Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prevent multiple entries

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by MrTicks View Post
    Thanks for the prompt response Josh! Will edit that code.
    Hi Josh - I looked at that link and saw,

    Code:
    protected override void OnBarUpdate() 
    {    
        // Check if flat 
        if (GetAtmStrategyMarketPosition("id") == MarketPosition.Flat) 
            Print("ATM Strategy position is currently flat"); 
    }
    So I tried,
    Code:
    && GetAtmStrategyMarketPosition (atmStrategyIdS) == MarketPosition.Flat
    or for longs
    && GetAtmStrategyMarketPosition (atmStrategyIdL) == MarketPosition.Flat
    and got errors in my output window from trace orders of,
    GetAtmStrategyMarketPosition() method error: Missing atmStrategyId parameter

    So now I have,
    Code:
    && ( atmStrategyIdS.Length < 0 && GetAtmStrategyMarketPosition(atmStrategyIdS) == MarketPosition.Flat )
    && ( atmStrategyIdL.Length < 0 && GetAtmStrategyMarketPosition(atmStrategyIdL) == MarketPosition.Flat )
    ...but it doesn't seem to make any orders now. Instead of atmStrategyIdS.Length < 0 should I have something else as a qualifier to check for GetAtmStrategyMarketPosition ?

    I think the errors happen because I was calling GetAtmStrategyMarketPosition when there was no ATM order open?

    Perhaps atmStrategyIdL.Length ! = 0 && GetAtmStrategyMarketPosition(atmStrategyIdL) == MarketPosition.Flat would be better?
    Last edited by MrTicks; 10-07-2010, 04:38 AM.

    Comment


      #17
      Hello Mr Ticks,

      You should do all position checks when the ID length > 0.

      From the sample:
      Code:
       
      if (atmStrategyId.Length > 0)
      {
      // You can change the stop price
      if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
      AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
      // Print some information about the strategy to the output window
      Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
      Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
      Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
      Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
      }
      Ryan M.NinjaTrader Customer Service

      Comment


        #18
        Originally posted by NinjaTrader_RyanM View Post
        Hello Mr Ticks,

        You should do all position checks when the ID length > 0.

        From the sample:
        Code:
         
        if (atmStrategyId.Length > 0)
        {
        // You can change the stop price
        if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
        AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
        // Print some information about the strategy to the output window
        Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
        Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
        Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
        Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
        }
        Hi, that part of it works OK for me. It's the part just before the AtmStrategyCreate call that is causing issues.

        In the link http://www.ninjatrader-support.com/H...rategyPosition it shows,
        Code:
        protected override void OnBarUpdate() 
        {    
            // Check if flat 
            if (GetAtmStrategyMarketPosition("id") == MarketPosition.Flat) 
                Print("ATM Strategy position is currently flat"); 
        }
        but if you call up
        GetAtmStrategyMarketPosition("atmStrategyIdL ") == MarketPosition.Flat

        before the AtmStrategyCreate part then you get the missing order error which looks like,
        GetAtmStrategyMarketPosition() method error: Missing atmStrategyId parameter

        Here is how the code looks,
        Code:
        [FONT=&quot]                        if (orderIdS.Length == 0
                                    && atmStrategyIdS.Length == 0
                                    && orderIdL.Length == 0  
                                    && atmStrategyIdL.Length == 0
        [/FONT][FONT=&quot]                            && GetAtmStrategyMarketPosition(atmStrategyIdS) == Cbi.MarketPosition.Flat
        [/FONT][FONT=&quot]                            && Close [1] <= Open [1]
                                   [/FONT][FONT=&quot]&& Open[1] - PrevBarsMinusTicks*TickSize < GetCurrentBid() 
                                    && tradeShort == false
        [/FONT][FONT=&quot]                            )
        [/FONT]  {
                                        //entryBar = CurrentBar;
                                        atmStrategyIdS = GetAtmStrategyUniqueId();
                                        orderIdS = GetAtmStrategyUniqueId();
                                        orderBarS = CurrentBar;
                                        AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Stop, 0, Close[1], TimeInForce.Day, orderIdS, "FDAX_1_LB_short", atmStrategyIdS);    
                                        tradeShort = true;
                                }    
          [FONT=&quot]             [/FONT]
        [FONT=&quot][/FONT]
        The howto link stated that you can put the call in the start of protected override void OnBarUpdate() but if you do then you are calling an AtmStrategyId that may not be active/open?

        Also, should it be
        GetAtmStrategyMarketPosition(atmStrategyIdS) == Cbi.MarketPosition.Flat
        instead of
        GetAtmStrategyMarketPosition(atmStrategyIdS) == MarketPosition.Flat

        Comment


          #19
          Here's the sequence from the sample:

          1) Check if empty string. (Length = 0)
          Create ATM order

          2) Check if flat
          Reset to empty string

          If the length of string is zero, then there is not likely a position. If you want to check position for a given ID, then you can use the length check. If it's > 0, then there should be something there to check. You should do any position checks inbetween 1 & 2 there - after the postion has been created but before it's flat.
          Ryan M.NinjaTrader Customer Service

          Comment


            #20
            Originally posted by NinjaTrader_RyanM View Post
            Here's the sequence from the sample:

            1) Check if empty string. (Length = 0)
            Create ATM order

            2) Check if flat
            Reset to empty string

            If the length of string is zero, then there is not likely a position. If you want to check position for a given ID, then you can use the length check. If it's > 0, then there should be something there to check. You should do any position checks inbetween 1 & 2 there - after the postion has been created but before it's flat.
            Ah OK that's what I thought, I took Josh up wrong when he pointed me at http://www.ninjatrader-support.com/H...yPosition.html

            Will go back to bool flags so.

            Thanks.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X