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

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 Aviram Y, Today, 05:29 AM
              0 responses
              3 views
              0 likes
              Last Post Aviram Y  
              Started by quantismo, 04-17-2024, 05:13 PM
              3 responses
              27 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by ScottWalsh, 04-16-2024, 04:29 PM
              7 responses
              35 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cls71, Today, 04:45 AM
              0 responses
              6 views
              0 likes
              Last Post cls71
              by cls71
               
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              218 views
              1 like
              Last Post PaulMohn  
              Working...
              X