Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Brevo, Today, 01:45 AM
      0 responses
      3 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      3 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      239 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      384 views
      1 like
      Last Post Gavini
      by Gavini
       
      Started by oviejo, Today, 12:28 AM
      0 responses
      6 views
      0 likes
      Last Post oviejo
      by oviejo
       
      Working...
      X