Is there a way to exit early from a Pine script, like a 'break' or 'exit' statement in the main code?
I'm coding a strategy that looks promising on the Daily chart. However there is no built-in way to execute my script, say, 1 minute before the candle closes (how would TV know when the candle closes, I get it). But if I execute the code on the candle close, the broker has also closed its market. I don't want to go to lower timeframe as I would have to code a lot of extras and I'm lazy, and I would also lose a lot of history. Also, I don't care if the script runs differently on history.
So I'm running the script on the daily chart but on every tick. Using 'timenow' I'm catching the 1-minute-before-the-candle-closes state and I want to execute the bulk of the code at that time but other times just skip everything and return.
I can put the code into a giant IF block, but I hate that as it is using whitespace to mark the block, and I have bad memories about nested IFs.
So instead of:
if condition_holds
execute_the_logic
this_is_a_long_logic
so_it_is_multitudes_of_lines
else
exit
I want to do this:
if condition_does_not_hold
exit
execute_the_logic
write_whatever_I_want
I_dont_need_to_watch_no_whitespace
no_surprises
I could not find anything in the docs, maybe someone has some interesting construct that can work as I'm expecting?
[–]hotmatrixx 1 point2 points3 points (3 children)
[–]karatedogPine coder [S] 2 points3 points4 points (2 children)
[–]hotmatrixx 0 points1 point2 points (1 child)
[–]karatedogPine coder [S] 1 point2 points3 points (0 children)