Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to save Current Bar based on bool variable ?

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

    How to save Current Bar based on bool variable ?

    Hello,
    I am working on an indicator to draw lines based on user input bool variable, bool can remain true for n number of bars so how can I store current bar to int saveBar only when bool was changed to true from false. Any help is appreciated!

    #2
    Hello s.kinra,

    Thanks for your post.

    A typical user input would be a read-only type of input so it would only be changed by the user.

    The user would change this input when the script is applied and would not change states after that.

    To answer your question though, you would need another bool variable (internal variable) that matches the current state of the bool of interest and when the two bools are different is when the change occurs and when you could save the current bar.

    if (userBool != myinternalbool)
    {
    savedBar = CurrentBar;
    myinternalbool = userBool;
    }




    Comment


      #3
      Hello Paul,
      Thanks for your reply, unfortunately I couldn't get it working. Anything I might be missing ?

      Comment


        #4
        Hello s.kinra,

        Thanks for your reply.

        Can you confirm that the bool is a user input bool that is set when the user sets it when applying the script?

        If the user bool is indeed set by the user I would not expect it to change state for the life of the script instance.

        Comment


          #5
          Hello Paul,
          Let me share a test script for better clarity, what exactly I need is the Bar Index when the user bool is set to true so that I can fix the start anchor of Ray.
          Attached Files

          Comment


            #6
            Hello s.kinra,

            Thanks for your reply and test script.

            That will not work because as I mentioned it is a user input which means that it is set before the script runs (state.configure) and then does not change.

            Comment


              #7
              Hello Paul,
              Thanks for confirming!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by charlesugo_1, 05-26-2026, 05:03 PM
              0 responses
              70 views
              0 likes
              Last Post charlesugo_1  
              Started by DannyP96, 05-18-2026, 02:38 PM
              1 response
              152 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by CarlTrading, 05-11-2026, 05:56 AM
              0 responses
              162 views
              0 likes
              Last Post CarlTrading  
              Started by CarlTrading, 05-10-2026, 08:12 PM
              0 responses
              100 views
              0 likes
              Last Post CarlTrading  
              Started by Hwop38, 05-04-2026, 07:02 PM
              0 responses
              288 views
              0 likes
              Last Post Hwop38
              by Hwop38
               
              Working...
              X