Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

If I have a bool which is "true" at the close of the CurrentBar

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

    If I have a bool which is "true" at the close of the CurrentBar

    How can I make that bool false on the next bar? Ideally I need the bool to remain true for the whole bar. Currently, CalculateOnBarClose is true.

    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (priceflipup == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR]
    {
    buysetupmoveiscompleted = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}
    [/SIZE][/FONT][/SIZE][/FONT]

    #2
    Hi kaywai,

    Thank you for your post.

    You can check if your CurrentBar increased since the signal and turn it off. You will need an integer variable to hold the last CurrentBar #. Something like this in your variables section;

    int lastBuyMoveBar = -1;

    Then add a line to keep track of the bar the buy setup occured on:
    Code:
    if (priceflipup == true)
    {
        buysetupmoveiscompleted = true;
        lastBuyMoveBar = CurrentBar; 
    }
    Add this code where you want to reset the boolean. if we're on a new bar, reset buysetupmoveiscompleted:
    Code:
    if(lastBuyMoveBar < CurrentBar)
        buysetupmoveiscompleted = false;
    This code will work w/ CalculateOnBarClose true or false. If you are going to stick with true, you could just toggle buysetupmove back off if it was true at the start of a new bar since OnBarUpdate() is only called once per bar.
    Code:
    // in top of OnBarUpdate 
    if (buysetupmoveiscompleted)
        buysetupmoveiscompleted = false;
    Please let me know if I can assist you any further.
    DexterNinjaTrader Customer Service

    Comment


      #3
      Thanks very much Dexter! Aprreciate your help! Kay Wai

      Comment


        #4
        Problem with this solution when priceflipup is true each CurrentBar

        Hello:

        It appears you have not taken into account the situation where a boolean such as priceflipup is true all the time. For example:

        // ... Initialize()
        CalculateOnBarClose = false;

        // ... OnBarUpdate()
        if (buysetupmoveiscompleted) buysetupmoveiscompleted = false;

        {***code where variable PRICE is calculated, making priceflipup true all the time***}

        if (priceflipup == true)
        {
        buysetupmoveiscompleted = true;
        lastBuyMoveBar = CurrentBar;
        }

        if(lastBuyMoveBar < CurrentBar) buysetupmoveiscompleted = false;

        The key in this scenario is how to know when lastBuyMoveBar is less than the CurrentBar. Any ideas? Thanks.

        Tony

        Comment


          #5
          Hello Tony,

          If we assume priceflipup always ends up true after some calculation, the code will work the same, assigning the current bar to lastBuyMoveBar and resetting on new bar (just to re-set it to current bar again of course).

          I am not following 100% what you are asking to achieve. Do you want to only update the buysetupmoveiscomplete once per bar and only when priceflipup is true and it was previously enabled?

          Code:
          if (priceflipup == true)
          {
              if(lastBuyMoveBar < CurrentBar && buysetupmoveiscompleted)                  
          
                  buysetupmoveiscompleted = false;
              else if(!buysetupmoveiscompleted)
              {
                   buysetupmoveiscompleted = true;
                   lastBuyMoveBar = CurrentBar; 
              }
          }
          Please let me know if this is what you were looking for.
          DexterNinjaTrader Customer Service

          Comment


            #6
            priceflipup boolean ALWAYS true: CalculateOnBarClose = false;

            Hello Dexter:

            Yes, my desire is to know what the last calculation was on the CurrentBar before CurrentBar increments. If priceflipup is always true, the logic you have created will work, up to a point. I will use FirstTickOfBar in conjunction with this code to handle the situation.

            Thanks.

            Tony

            Comment


              #7
              Hi Tony,

              Understood, and you are welcome. Just let us know if we can assist any further.
              DexterNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              581 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              338 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X