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

Help to simplify some code

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

    Help to simplify some code

    Hello,
    I am trying to include a condition into a code whereby Close[0] would be greater than the first Close going backwards that is greater than Close[3] and occurs before Close[3]. I don’t think I can use Most Recent Occurrence (MRO) to do this, as that works back from Close[0] as far as I understand, and so may pick up Close[1] or Close[2]. Currently the code would look something like this:

    Code:
    if ((Close[4] > Close[3] && Close[0] > Close[4]) ||  (Close[5] > Close[3] && Close[0] > Close[5]))
    In order to catch the first Close > Close[3] I would need to keep repeating this condition, Close[6] next, until I was satisfied I had included enough bars prior to Close[3] to catch one where the Close > Close[3].

    Is there an easier way of doing this? Any help would be much appreciated.

    Thank you.

    #2
    GeorgeW
    Is CalculateOnBarClose = True ?

    Comment


      #3
      Hello GeorgeW,

      Are you trying to compare an arbitrary number of bars based on a variable?

      You could use a for loop and compare the current index with the previous index (starting with 1 in the loop).

      Iterate over numbers with for. Increment or decrement an index int from a start to an end value.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks for your responses JerryWar and ChelseaB.

        CalculateOnBarClose = true yes.

        I am trying to compare the close of an arbitrary number of bars before bar[3] to Close[3], and then the first one that I pick up that is greater than Close[3] is then compared to Close[0]. I will try the for loop.

        Comment


          #5
          George ,
          I think there is a flaw in your statement. ergo. If you were to code it exactly as you wrote that
          statement , I don't think you would get what your looking for.
          You said " then the first one that I pick up that is greater than Close[3] " . Since you are using Calculate on BarClose= true. That bar will be Close[0] . You then went on to say " is then compared to Close[0]" but that bar already is Close[0] so it will be ==

          Hope this helps
          Jerry.

          Comment


            #6
            Hello JerryWar,

            I am working back from 3 reversal bars and the last climax bar. So counting back from the 3rd reversal bar, which is Close[0], the climax bar becomes Close[3], I then want to compare Close[0], the third reversal bar, to the first close before Close[3] that exceeds Close[3]. As I have written the code, the signals are appear on the 3rd reversal bar, as intended, and sometimes the 4th (because this meets the condition for a 3rd reversal bar).

            Comment


              #7
              Are you trying to compare an arbitrary number of bars based on a variable?

              Comment


                #8
                Originally posted by lhthe View Post
                Are you trying to compare an arbitrary number of bars based on a variable?
                Hello lhthe,
                I am not sure I understand the question correctly. But if any of a number of bars prior to bar[3] could be the first to exceed it, then I suppose I am comparing the close of an arbitrary number of bars to Close[3], and then once I find the first bar whose close exceeds it, I am then comparing that close to Close[0].

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by adeelshahzad, Today, 03:54 AM
                5 responses
                32 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by stafe, 04-15-2024, 08:34 PM
                7 responses
                32 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by merzo, 06-25-2023, 02:19 AM
                10 responses
                823 views
                1 like
                Last Post NinjaTrader_ChristopherJ  
                Started by frankthearm, Today, 09:08 AM
                5 responses
                21 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                43 views
                0 likes
                Last Post jeronymite  
                Working...
                X