Hi,
Here is a simple plot I woul dlike to have on my chart
def __signalup = if close[2]<open[2] and close[1]>open[1] then high[1] else Double.NaN;
plot _signaltriggered = if high>signalup then high else Double.Nan;
The problem I have is the plot only appears if it's the next candle that triggered the _signalup while I would like to have the plot when the _signalup is triggered even if it's 3 candles after the _signalup appeared.
Any ideas?
Thanks for your help!
this draws a green line above the bars, when signalup and signaltriggered are true.
it can get confusing if multiple condition formulas are assigning price levels. then you can't easily reference those formulas, to see if the condition was true. there is nothing wrong with doing that, but sometimes if the price levels are assigned by other formulas, the program flow makes more sense.
changed the formulas, so when conditions are compared, the output is logical, 0 or 1 , not a price level.
def signal_up = if close[2] < open[2] and close[1] > open[1] then 1 else 0;
def signal_triggered = if signal_up and high > high[1] then 1 else 0;
these could be combined if signal_up isn't used elsewhere in the program. i left them separate.
add a plot that draws white wedges (small arrows) when signal_up occurs.
enter a number, default 3, for how many bars to look back at, to check if signal_triggered was true. it starts from the current bar. to skip the current bar , change signal_triggered[0] to signal_triggered[1]
use sum( ) to count how many times signal_triggered was true. if more than 0 then plot a line.
if sum( ) is greater 0, then plot a line at the bar high, times a factor.
there is a vertical factor number to adjust the level of the line. default is 0.8 , (high * (1 + 0.8/100))
Ruby:
# plot_0to3_barslater0a
#-----------------------------------------------
# original
# def signalup = if close[2] < open[2] and close[1] > open[1] then high[1] else Double.NaN;
# plot signaltriggered = if high > zsignalup then high else Double.Nan;
# -------------------------------------
# change the formulas, so when conditions are compared, the output is logical, 0 or 1 , not a price level.
# add a formula to assign a price level if the logical formulas are true ( signalup and signaltriggered )
def na = double.nan;
def signal_up = if close[2] < open[2] and close[1] > open[1] then 1 else 0;
def signal_triggered = if signal_up and high > high[1] then 1 else 0;
#def trig_level = if signal_triggered then high else na;
# draw a green wedge when signal_triggered is true
plot z1 = signal_triggered;
z1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
z1.SetDefaultColor(Color.white);
z1.setlineweight(2);
input trigger_prev_x_bars = 3;
def trigger_len = if trigger_prev_x_bars < 1 then 1 else trigger_prev_x_bars;
# count the triggers during the previous x bars , starting with the current bar
# to skip the current bar , change signal_triggered[0] to signal_triggered[1]
def sum_trig = sum(signal_triggered[0], trigger_len);
input line_ht_factor = 0.8;
plot trig_level = if sum_trig > 0 then (high * (1 + (line_ht_factor/100))) else na;
trig_level.SetDefaultColor(Color.green);
#
#
WFC 30D 1hr