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 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