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

How to code bars since condition

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

    How to code bars since condition

    Hi NT8,

    How do I code bars since a condition other than entry. similar to the bars since entry/exit condition, I'd like to reference the number of bars since another condition.

    Such as

    If
    (MACD cross 0)

    Then
    (variable = bars since that event)

    Thank you!

    #2
    I'd like to clarify that I can't use the look back period, what I am trying to do is replicate the Bars since entry for a different condition, so that I can do this:

    Condition (Bars Since last Condition > 10)

    ^ I don't believe the look back period can do this because it checks if a condition happened within the look back period and I'd like to set if a condition happened to bars greater than a lookback period.

    Comment


      #3
      Hello Austiner87, thanks for writing in.

      We have the MRO (Most Recent Occurrence) method that will return the bar index where a condition happened:
      https://ninjatrader.com/support/help...urence_mro.htm

      There is an example on that page on how to use it.

      If you have any further questions please let me know.
      Chris L.NinjaTrader Customer Service

      Comment


        #4

        Hi NT8, I need some more help on this:

        // Prints the high price of the most recent up bar over the last 10 bars (current bar + look back period's 9 bars before that)
        int barsAgo = MRO(() => Close[0] > Open[0], 1, 9);
        if (barsAgo > -1)
        Print("The bar high was " + High[barsAgo]);

        ^using the example, how would I check for if a variable increased by 1 (+=1) greater than 12 bars ago. my assumption is below, can you please let me know if this is correct?

        int barsAgo = MRO((variable += 1) => Close[0] > Open[0], 1,12);
        if (barsAgo >= 12)


        Comment


          #5
          Hello Austiner87, thanks for your reply.

          The (variable) => is a way to pass in parameters into the lambda function. To check if a variable increased by one you would need to store the variable in a custom Series<T> object:

          https://ninjatrader.com/support/help.../?iseriest.htm

          Then you can compare MySeries[0] against MySeries[11 to 1] to see if MySeries[0] == MySeries[x]+1

          Make sure to test thoroughly with Print statements to check the output.

          Please let me know if I can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ghoul, Today, 06:02 PM
          2 responses
          12 views
          0 likes
          Last Post ghoul
          by ghoul
           
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          44 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          180 views
          0 likes
          Last Post jeronymite  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Working...
          X