Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Recall indicator value from entry bar for exit condition?

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

    Recall indicator value from entry bar for exit condition?

    Hello,
    I am new to NT and coding but have made significant strides thanks to the forums. This will be the first post I have made on any forum so I will be as clear as possible.

    I am unable to find a solution to this set-up:

    For a long only strategy, one condition requires all entries to occur above 200 SMA.

    One exit condition writes,
    if(CountIf (delegate {return SMA(200)[0] < Close [0];}, 100) < 99)
    ExitLongStop(SMA(90)[0], "", "");

    An open trade can be closed when price crosses below 90 SMA. My problem now is that it is possible for another trade to open on the next bar with the countif condition met and the 90 SMA still above price. My trades are being closed next day because the price was above the 200 SMA for 100 days but is entered below the 90 SMA.

    I need to create an additional ExitLongStop condition and as a newbie I came up:

    if(CountIf (delegate {return SMA(200)[0] < Close [0];}, 100) < 99
    && (BarsSinceEntry() > 0)
    && (Position.AvgPrice < SMA(90)[BarsSinceEntry]))

    BarsSinceEntry is not accepted here; it is unfortunately the only idea I had to update how many days to go back and find the SMA value from the entry bar.

    How can I recall the value of the 90 SMA on the entry bar for this condition? Thanks.

    #2
    Hi Scotty,

    Welcome to the NinjaTrader Support Forums.

    For your exit condition instead of using this CountIf() condition I suggest you use CrossBelow() instead.


    Code:
    if (Position.MarketPosition == MarketPosition.Long && CrossBelow(Close, SMA(90), 1))
         // Do something;
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Wow you guys are fast! Thanks for your help. Much more logical solution than CountIf.

      Thanks again.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      43 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      25 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      162 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      98 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      158 views
      2 likes
      Last Post CaptainJack  
      Working...
      X