# +------------------------------------------------------------+
# | Example code to dynamically offset arrow plots |
# | Robert...
# +------------------------------------------------------------+
# | Example code to dynamically offset arrow plots |
# | Robert Payne |
# | https://funwiththinkscript.com |
# +------------------------------------------------------------+
def cond1 = high == Highest(high, 13) and high == GetValue(Highest(high, 13), -12);
def cond2 = high == Highest(high, 5) and high == GetValue(Highest(high, 5), -4);
def avgRng = Average(high - low, 21) / 3;
def offset = if cond1 and cond2 then avgRng * 2 else 0;
plot arrow1 = if cond1 then high else Double.NaN;
arrow1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrow1.SetDefaultColor(Color.LIME);
arrow1.SetLineWeight(5);
plot arrow2 = if cond2 then high + offset else Double.NaN;
arrow2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrow2.SetDefaultColor(Color.CYAN);
arrow2.SetLineWeight(5);
plot pUP = major == 1;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);
plot pDown = major == -1;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);
# Arrows below based on the following
#AddChartBubble(ConditionUp4 && ConditionUp5, Volume, concat("Buy @ $", Close), Color.Green, Yes);
#AddChartBubble(ConditionUp1 && ConditionUp2 && ConditionUp3, Volume, concat("Buy @ $", Close), Color.Green, Yes);
#AddChartBubble(ConditionDown1 && ConditionDown4 && ConditionDown5, Volume, concat("Sell @ $", Close), Color.Red, Yes);
#AddChartBubble(ConditionDown1 && ConditionDown2 && ConditionDown3, Volume, concat("Sell @ $", Close), Color.Red, Yes);
# buy and sell signals
def Buy45 = ConditionUp4 && ConditionUp5;
plot bullish45 = Buy45;
bullish45.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish45.SetDefaultColor(Color.CYAN);
bullish45.SetLineWeight(3);
def Buy123 = ConditionUp1 && ConditionUp2 && ConditionUp3;
plot bullish123 = Buy123;
bullish123.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish123.SetDefaultColor(Color.CYAN);
bullish123.SetLineWeight(3);
def Bearish145i = ConditionDown1 && ConditionDown4 && ConditionDown5;
plot bearish145 = Bearish145i;
bearish145.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish145.SetDefaultColor(Color.CYAN);
bearish145.SetLineWeight(3);
def Bearish123i = ConditionDown1 && ConditionDown2 && ConditionDown3;
plot bearish123 = Bearish123i;
bearish123.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish123.SetDefaultColor(Color.CYAN);
bearish123.SetLineWeight(3);
@zeek the arrow offset code in post#8 should work for you.
#...this script seems to provide better fractal signals than the other script
# added alarms for buy/sell fractal signals - RickK 2021/09/08
### define inputs
input price = close;
input audioalarm = yes;
input arrow_offset = .06; #might need to be modified for every instrument's charts
### define a Buy Fractal setup
def buy_fractal_setup_is_true = high[2] < high[1];
def buy_fractal_peak_is_true = high > high[1] && high > high[-1];
def buy_fractal_confirm_is_true = high[-1] > high[-2];
### define a Sell Fractal setup
def sell_fractal_setup_is_true = low[2] > low[1];
def sell_fractal_peak_is_true = low < low[1] && low < low[-1];
def sell_fractal_confirm_is_true = low[-1] < low[-2];
### plot details (for some reason the original coder set "buy" with a down arrow
# above the candle and the "sell" is a Up arrow below the candle. I just left
# that way)
plot buy_fractal = if buy_fractal_setup_is_true and buy_fractal_peak_is_true and buy_fractal_confirm_is_true then price + arrow_offset else double.NaN;
buy_fractal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
buy_fractal.SetDefaultColor(Color.magenta);
plot sell_fractal = if sell_fractal_setup_is_true and sell_fractal_peak_is_true and sell_fractal_confirm_is_true then close - arrow_offset else double.NaN;
sell_fractal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
sell_fractal.SetDefaultColor(Color.cyan);
### alarms
alert (audioalarm and buy_fractal, "!..BUY..!", alert.bar, sound.DING);
alert (audioalarm and sell_fractal, "!..SELL..!", alert.bar, sound.ding);
#end
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
K | Bullish Stack SMA's Scan | Questions | 15 | |
To plot arrows on Daily Chart with Weekly plot criteria | Questions | 2 | ||
N | Need help adding long / short arrows to the TMO indicator | Questions | 3 | |
D | Up/Dn arrows...how to paint on bar[1]? | Questions | 5 | |
arrows not painting | Questions | 8 |