Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AtmStrategyChangeStopTarget() - Question

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

    AtmStrategyChangeStopTarget() - Question

    The code below generates the following output to the output window:
    CL 09-10 (09:30:23) Set Target ATM_S_ID: 4b442f8ee62a4ef0ab98c5a789188724 Is the Order Filled: True
    **NT** AtmStrategyChangeStopTarget() method error: AtmStrategyId '4b442f8ee62a4ef0ab98c5a789188724' does not exist or is already in terminated state
    09:30:23 First Tick Of Bar * Reset Inactive Order Values

    I am trying to eliminate the AtmStrategyChangeStopTarget() method error

    This above output and error occur when the OnBarUpdate Event is called IMMEDIATELY after the orders STOP is filled. I seem to be confused her. How do I know this order has been stopped out so I do not call this method.

    Thanks!





    protected override void OnBarUpdate()
    {

    if (Historical)
    return;

    if (FirstTickOfBar)
    {
    ManageTradeOnFirstTick( 1, ref longTradeValues, ref configValues);
    ...

    }
    }



    public void ManageTradeOnFirstTick( int BarsBack, ref string[] tradeValues,ref string[] configValues)
    {

    if(!IsTheOrderFilled(ref tradeValues, ref configValues))
    return;
    Print(Instrument.FullName+" ("+Bars.GetTime(CurrentBar).TimeOfDay+") Set Target ATM_S_ID: " +tradeValues[ATM_S_ID] + " Is the Order Filled: " +IsTheOrderFilled(ref tradeValues, ref configValues));
    AtmStrategyChangeStopTarget((Math.Round(EMA(GetCon figValueInt(ref configValues, CHECKEMA))[1],2)),0 , "TARGET1",tradeValues[ATM_S_ID]);


    }



    public bool IsTheOrderFilled(ref string[] tradeValues ,ref string [] configValues)
    {

    if (tradeValues[ORD_ID].Length > 0)
    {
    string[] status = GetAtmStrategyEntryOrderStatus(tradeValues[ORD_ID]);
    if (status.GetLength(0) > 0)
    {
    if (status[2] != "Filled" && status[2] != "PartFilled" )
    return false;
    }
    }
    ///
    /// THIS NEXT LINE IS GENERATING THE ERROR. HOW DO I ELIMINATE THIS ERROR
    /// THIS CODE USED ACCORDING TO YOUR SAMPLE ATM STRATEGY
    ///
    else if (tradeValues[ATM_S_ID].Length > 0 && GetAtmStrategyMarketPosition(tradeValues[ATM_S_ID]) == Cbi.MarketPosition.Flat)
    {
    ResetOrderValues(ref tradeValues,ref configValues) ;
    return false;
    }

    return true;

    }



    public void ResetOrderValues(ref string[] TradeValues,ref string[] configValues)
    {
    TradeValues[ATM_S_ID] = string.Empty;
    TradeValues[ORD_ID] = string.Empty;
    Print( Bars.GetTime(CurrentBar).TimeOfDay +" First Tick Of Bar * Reset Inactive Order Values");
    }

    #2
    mjc4118, you can't rely on the MarketPosition update in this case to reset the atmStrategyId, as the position update is not guaranteed to be reflected until the next OnBarUpdate().

    Comment


      #3
      OnBarUpdate() is triggering on every tick.. So many OnBarUpdates() have triggered between when the object was disposed and I am trying to access it. I am only trying to access this object on the FirstTickOfBar for the next bar Does this imply that even yet another bar needs to close before this would be updated? If so that would be TWO bars after the object was disposed.
      That would seem odd. On the next bar... I can understand although on the next tick is better and On the next bar. is what I have done...First Tick Of Next Bar...

      Here is a video showing the trade/chart/logs/error..like usual the codec is from gotomeeting.com available here

      minute 3 second 22 in the video shows a slow replay of the chart w/ error

      Comment


        #4
        And if i cannot rely on MarketPosition update then what can I use to tell me that the order is flat and that I am free to take another trade if presented?

        Comment


          #5
          Thanks for the video, you can use GetAtmStrategyStopTargetOrderStatus to know when it's filled so you can stop trying to access it once it's in a terminated state - http://www.ninjatrader-support.com/H...derStatus.html

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          651 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          577 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X