mark.917
Member
My previous experience with charting programs was that code for a study gets evaluated on every new incoming tick. Does TOS operate this was as well?
I am trying to detect when a new bar has opened and the only idea I can come up with is to use the BarNumber() function, recording the bar number at the beginning of the script and updating it at the end, expecting it to reevaluate from the beginning again.
I don't think this code will work because I am guessing the variables get reset but it shows kind of what I am trying to do. My strategy requires a bar to close before a decision is made (plot red or green), otherwise it could be repainting red/green until the new bar opens.
Just looking for clues or any functions that I am not aware of that exist in ThinkScript.
I am trying to detect when a new bar has opened and the only idea I can come up with is to use the BarNumber() function, recording the bar number at the beginning of the script and updating it at the end, expecting it to reevaluate from the beginning again.
I don't think this code will work because I am guessing the variables get reset but it shows kind of what I am trying to do. My strategy requires a bar to close before a decision is made (plot red or green), otherwise it could be repainting red/green until the new bar opens.
Just looking for clues or any functions that I am not aware of that exist in ThinkScript.
Code:
def new_bar = BarNumber() + 1;
blah
blah
blah
plot xyz = if BarNumber()==new_bar then blah blah else new_bar = 0;
(then I guess the entire code gets reevaluated again???)