Hi All,
I'm trying to create a simple timer that will count a specific number of seconds from a triggered event. In the case below, the triggered event is when a position is closed, I want to display a label that will stay on the chart for 60 seconds. This code will run on 30 or 60 minute chart so the thing Im not sure I can do is create a timer that can actively count down 60 seconds. I've tried a few different ways so far but before I go too far down this rabbit hole, I figured I would ask you all if what I'm trying to do is even possible. Thanks!
I'm trying to create a simple timer that will count a specific number of seconds from a triggered event. In the case below, the triggered event is when a position is closed, I want to display a label that will stay on the chart for 60 seconds. This code will run on 30 or 60 minute chart so the thing Im not sure I can do is create a timer that can actively count down 60 seconds. I've tried a few different ways so far but before I go too far down this rabbit hole, I figured I would ask you all if what I'm trying to do is even possible. Thanks!
Code:
declare lower;
def time = gettime();
def qty = getquantity();
def bn = barnumber();
def trigger1LongIN = bn >= bn and qty > 0;
def triggerBN = if trigger1LongIN then bn else triggerbn[1];
def triggerlongOUT = bn >= triggerBN and qty crosses below 1;;
def Hold = bn >= triggerBN and if trigger1LongIN and triggerlongOUT and time < time+aggregationperiod.min then 1 else 0;
#def min = if roundtriplong then ((time + 180000) - time)/1000 else 0;
#def threemintimer = if roundtriplong then time + 180000 else double.nan;
addlabel(yes,"Holding for " + Hold + " seconds " ,color.magenta);
addlabel(yes,Hold ,color.magenta);
# Show debugging signals offsetting each one so they're not on top of each other
plot p_trigger1LongIN = trigger1LongIN;
plot p_triggerlongOUT = triggerlongOUT+ 4;
plot p_roundtriplong = Hold + 6;