Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to address the previous candle

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

    How to address the previous candle

    Hello

    I'm using a few criteria in my strategy that must all be set to true before a trading signal is generated and an arrow is drawn on the chart.

    if (Criteria1 == true && Criteria2 == true....)
    Draw UpArrow etc.

    In order to avoid having two subsequent arrows in a row drawn on the chart, I'd like to address the previous candle by checking if its criteria were already set to true or not. If this is the case (If all criteria of the previous candle were set to true) do not draw another arrow on the chart.

    How can I address the previous candle in its entirety (not just the Close or Open of it but the candle as a whole?

    I usually use Close [1] or Open [1] to address the previous candle but this obviously won't work here.

    Thanks

    #2
    Hello,

    Thanks for the forum post.

    There are many ways to do this in programming.

    What I might suggest is what you set a variable when the condition is true.

    lastBarConditionWasTrue = CurrentBar;

    Set this to the current bar value.

    Then when checking for if you need to draw the triangle again. You can do a check to make sure the CurrentBar > lastConditionWasTrue + 2. This would prevent the condition from being true for the next 2 bars for example.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      You may want to look at this thread:

      Support for the development of custom automated trading strategies using NinjaScript.

      Comment


        #4
        Thanks Koganam for referring me to...my own thread ;-)
        The reason I posted this request again in a different form is that your suggested solution doesn't produce the desired result on my end. (I'm not questioning your suggestion, I'm just saying that for some reason I didn't manage to make it work.)

        Thanks

        Comment


          #5
          I think Brett's answer already provides you with the solution. Have you tried that.

          the coding will be like this

          in variable
          int lastBar = -2;


          in OnBarUpdate
          if (condition1 == true && condition2 == true && CurrentBar > lastBar +2)
          {
          DrawArrow..(....);
          lastBar = CurrentBar; //make sure you assign the value
          }

          Comment


            #6
            Thanks for your reply and your help Bukkan, much appreciated. I'm currently implementing Brett's solution and it looks very good so far (Thanks Brett!)
            Last edited by laocoon; 04-11-2011, 03:20 AM.

            Comment


              #7
              Originally posted by laocoon View Post
              Thanks for your reply and your help Bukkan, much appreciated. I'm currently implementing Brett's solution and it looks very good so far (Thanks Brett!)
              Not to quibble, but how is Brett's answer any different from the answer that I gave you using "Deadbars"?

              I mean this one: http://www.ninjatrader.com/support/f...37&postcount=3

              Comment


                #8
                My bad, Koganam. I made a mistake while implementing your solution.
                Just gave it another shot and it worked like a charm this time...sorry for the confusion.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                639 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                366 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                572 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X