Double SAR strategy - trend

I am trying to implement a double sar strategy but couldn't find any answers (maybe I got the answer somewhere but as I am not a coder, I may miss it)
My conditions to open a trade
1)check for PSAR1 if its in uptrend or downtrend
2)check for PSAR2 if it makes a crossover
as per the code, it looks for crossovers on both PSAR1 and PSAR2. I want that the strategy should check for PSAR1 if its in uptrend or downtrend (not if it makes a cross)
Many thanks for any answers.
//#version=4
strategy(title="Double Parabolic SAR", overlay=true)
start1 = input(title="Start1", type=input.float, defval=0.001, step=0.01)
inc1 = input(title="Inc1", type=input.float, defval=0.001, step=0.01)
max1 = input(title="Max1", type=input.float, defval=0.001, step=0.01)
start2 = input(title="Start2", type=input.float, defval=0.001, step=0.01)
inc2 = input(title="Inc2", type=input.float, defval=0.002, step=0.01)
max2 = input(title="Max2", type=input.float, defval=0.005, step=0.01)
PSAR1 = sar(start1, inc1, max1)
PColor1 = PSAR1 < low? color.red:color.red
plot(PSAR1, "ParabolicSAR2", style=plot.style_cross, color=PColor1)
plotshape(crossover(close,PSAR1), style=shape.labelup, location=location.belowbar, color=color.green, size=size.tiny, title="", text="", textcolor=color.white)
plotshape(crossunder(close,PSAR1), style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, title="", text="", textcolor=color.white)
PSAR2 = sar(start2, inc2, max2)
PColor2 = PSAR2 < low? color.blue:color.green
plot(PSAR2, "ParabolicSAR2", style=plot.style_cross, color=PColor2)
plotshape(crossover(close,PSAR2), style=shape.labelup, location=location.belowbar, color=color.green, size=size.tiny, title="", text="", textcolor=color.white)
plotshape(crossunder(close,PSAR2), style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, title="", text="", textcolor=color.white)
tp=input(defval=500.0,title="TARGET IN POINTS")
sl=input(defval=500.0,title="STOP LOSS IN POINTS")
Buy1 = crossunder(close,PSAR1)
Sell1 = crossover(close,PSAR1)
Buy2 = crossunder(close,PSAR2)
Sell2 = crossover(close,PSAR2)
if Buy1 and Sell2
strategy.entry("BUY", strategy.long)
alert("BUY", alert.freq_once_per_bar)
strategy.exit("Buy Exit", from_entry="BUY", profit = tp,loss = sl)
if (Sell1 and Buy2)
strategy.entry("SELL", strategy.short)
alert("SELL", alert.freq_once_per_bar)
strategy.exit("Sell Exit", from_entry="SELL", profit = tp,loss = sl)

Related

Plotshape and label

In below code, I am getting syntax error for plotshape and several for label. Even for max / min i am getting too many arguments. I used label to get the value from intraburst formula as text. Will need help to resolve these.
//#version=4
study("Intraburst", overlay=true)
truemove = abs(open[2] - close) dayTrueHigh = max(high[1], high,
close[2]) dayTrueLow = min(low[1], low, close[2]) dayTrueRange =
dayTrueHigh - dayTrueLow intraburstLevel = truemove / dayTrueRange *
100
if intraburstLevel > 30
plotshape(series=intraburstLevel, text="ON", style=shape.circle, location=location.abovebar, color=color.green, size=size.normal) else
plotshape(series=intraburstLevel, text="OFF", style=shape.circle, location=location.abovebar, color=color.red, size=size.normal)
label = label.new(bar_index=0, yloc=y_top, xloc=xloc.bar_index,
text=tostring(intraburstLevel, "0.00"), size=size.large,
color=color.black) label.location = location.top label.y = y_top
label.x = x_right label.text = tostring(intraburstLevel, "0.00")
In series, use a ternary
Something like that:
plotshape(
intraburstLevel > 30 ? intraburstLevel : na,
text = "ON",
style = shape.circle,
location = location.abovebar,
color = color.green,
size = size.normal)
plotshape(
intraburstLevel <= 30 ? intraburstLevel : na,
text = "OFF",
style = shape.circle,
location = location.abovebar,
color = color.red,
size = size.normal)
and the label
label.new(
bar_index,
close,
tostring (intraburstLevel, "##.00"),
color = color.black,
textcolor = color.white)

Change RSI Plot Range - Possible or not?

We know that RSI plotting range is between 0 to 100.
Is it possible to change a plotted indicator line so that it will fluctuate in an extended range, say -50 to 100 ?
In simple way I want it to be (stretched) so I can easily draw trend line on the RSI line.
Attached photo is sample of what I mean on is perfect , one that I have is not like it.
I want the the RSI to cross the green and red area without affecting the movement of the indicator. I just want it to be stretching.
enter image description here
enter image description here
//#version=5
indicator(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(50, title="MA Length", group="MA Settings")
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
rsicolor = rsi > 70 ? color.new(#ff0057, 0) : rsi < 30 ? color.new(#ff0057, 0) : #1056ee
plot(rsi, "RSI", color=rsicolor, linewidth=2, style=plot.style_stepline)
plot(rsiMA, "RSI-based MA", color=color.rgb(120, 206, 255))
OverBought1 = input.int(80, minval=1)
OverBought2 = input.int(90, minval=1)
OverSold1 = input.int(20, minval=1)
OverSold2 = input.int(10, minval=1)
OB1 = hline(OverBought1 , color=color.red, linestyle=hline.style_dashed)
OB2 = hline(OverBought2 , color=color.red, linestyle=hline.style_dashed)
OS1 = hline(OverSold1 , color=color.green, linestyle=hline.style_dashed)
OS2 = hline(OverSold2 , color=color.green, linestyle=hline.style_dashed)
fill(OB1 , OB2, color=color.rgb(255, 82, 82, 80), title="Red Zoon Fill")
fill(OS1 , OS2 , color=color.rgb(76, 175, 79, 80), title="Green Zoon Fill")
Any ideas, please?
Thank you!
Colin
Is it possible to change a plotted indicator line so that it will fluctuate in an extended range, say -50 to 100 ?
In simple way I want it to be (stretched) so I can easily draw trend line on the RSI line.
Attached photo is sample of what I mean on is perfect , one that I have is not like it.
I want the the RSI to cross the green and red area without affecting the movement of the indicator. I just want it to be stretching.
You can use normalize() function:
//#version=5
indicator("My script")
normalize(_src, _min, _max) =>
// Normalizes series with unknown min/max using historical min/max.
// _src : series to rescale.
// _min, _min: min/max values of rescaled series.
var _historicMin = 10e10
var _historicMax = -10e10
_historicMin := math.min(nz(_src, _historicMin), _historicMin)
_historicMax := math.max(nz(_src, _historicMax), _historicMax)
_min + (_max - _min) * (_src - _historicMin) / math.max(_historicMax - _historicMin, 10e-10)
rsi = ta.rsi(close, 20)
rsiNormalized = normalize(rsi, -50, 100)
plot(rsiNormalized)
hline(-50)
hline(100)
EDIT
In your case, since we know the scale will always be between 0 to 100, we can use math to solve the issue much more accurately:
//#version=5
indicator("My script")
rsi = ta.rsi(close, 20) // this will give a value between 0 to 100
// find the value compared to a scale of 100
rsiPerc = rsi / 100
// multiply by the new range to get the position of rsi on the new range
rsiOnNewScale = rsiPerc * 150
// place the newRsi on a scale of -50 to 100
newRsi = rsiOnNewScale - 50
plot(newRsi)
hline(-50)
hline(100)
Or in short:
//#version=5
indicator("My script")
rsi = ta.rsi(close, 20) // this will give a value between 0 to 100
newRsi = (rsi / 100 * 150) - 50
plot(newRsi)
hline(-50)
hline(100)

Strategy ATR TP/SL target doesn't stay 'locked' to my entry readings

I want a strategy to Take Profit/Stop Loss to be based on the ATR (plus multiplier). However, I want it to be whatever the readings were at the point of entry, not simply the last candle (which is what it seems to be doing). Weird thing is that I have other strategies that use this approach, and they seem fine, so I'm really stumped by what I'm doing wrong.
Any help would be much appreciated!
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dave-browning
//#version=5
strategy("Dead-Cat Bounce", overlay = true, initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, currency = currency.GBP, commission_value = 0.05, use_bar_magnifier = true)
trendEMAlength = input.int(130, "Trend EMA Length")
fastSMALength = input.int(14, "Fast SMA Length")
tpATRmultiplyer = input.float(6.2, "Short TP ATR Multiplier")
slATRmultiplier = input.float(4, "Short SL ATR Multiplier")
//Trade Conditions
shortCondition = close > ta.sma(close, fastSMALength) and close < ta.ema(close, length=trendEMAlength)
notInTrade = strategy.position_size <= 0
atr = ta.atr(14)
ema=ta.ema(close, trendEMAlength)
plot(ta.sma(close,length=fastSMALength), color=color.blue, linewidth = 2)
plot(ta.ema(close, length=trendEMAlength), color=color.yellow, linewidth = 4)
plot(low - (atr * tpATRmultiplyer), color=color.green)
plot(high + (atr * slATRmultiplier), color=color.red)
if shortCondition and notInTrade
stopLoss = (high + (atr * slATRmultiplier))
takeProfit = (low - (atr * tpATRmultiplyer))
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", limit=takeProfit, stop=stopLoss)

Setting A Multiple Ticker Alert On Barstate.islast in Pine Script

Good Day! I am trying to emulate a script I created that provides alerts on multiple tickers for the various conditions I have set up. This works as it should and have been happy with it. Although it is not pretty, it is the first section of code posted below. The end of the code is where I input the action_alerts for the multiple tickers.
The new code I am trying to create deals with a label that shows if the relative strength reach a new high over a 28 day span. I am looking to create an alert of that new high on the same tickers as the first code to tell me once that new high is reached. That is the second code below. I also added a picture showing that label.new is a tiny green circle every time the new high is reached.
Any help with this will be greatly appreciated!
First Code (working)
indicator('Daily Screener #1', overlay=true)
//Backtest start date with inputs
startDate = input.int(title='Start Date', defval=1, minval=1, maxval=31)
startMonth = input.int(title='Start Month', defval=5, minval=1, maxval=12)
startYear = input.int(title='Start Year', defval=2021, minval=2000, maxval=2100)
//See if the bar's time happened on/after start date
afterStartDate = time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)
//Inputs
ts_bars = input.int(10, minval=1, title='Tenkan-Sen Bars')
ks_bars = input.int(20, minval=1, title='Kijun-Sen Bars')
ssb_bars = input.int(50, minval=1, title='Senkou-Span B Bars')
sma_bars = input.int(50, minval=1, title='SMA Bars')
sec_sma_bars = input.int(5, minval=1, title='Second SMA Bars')
cs_offset = input.int(20, minval=1, title='Chikou-Span Offset')
ss_offset = input.int(20, minval=1, title='Senkou-Span Offset')
long_entry = input(true, title='Long Entry')
short_entry = input(true, title='Short Entry')
wait_for_cloud = input(true, title='Wait for Cloud Confirmation')
//values
avgvalue = input(defval=20, title='Avg Vol Period')
avgvolfac = input(defval=2, title='Rvol Factor')
maxvol = input(defval=5, title='Max Vol')
minvol = input(defval=10000, title='Required Min Vol')
color bo = color.white
color suy = color.black
avgvola = ta.sma(volume, avgvalue)
volcheck = volume > avgvola * avgvolfac and volume > minvol and volume > volume[1] * .75
maxvolcheck = volume > avgvola * maxvol and volume > minvol and volume > volume[1] * .75
// RSI Inputs
use_rsi_tp = input(false, title='Use RSI for Take Profit')
use_rsi_entry = input(false, title='Use RSI for Entry')
seq_rsi = input(defval=1, title='Alert TP after X Sequential bars past RSI')
rsi_period = input(defval=7, title='RSI Period')
overbought_rsi = input(defval=80, title='RSI Overbought Level')
oversold_rsi = input(defval=20, title='RSI Oversold Level')
middle(len) =>
ta.sma(close, len)
//Stoch RSI Inputs
smoothK = input.int(3, 'K', minval=1)
smoothD = input.int(3, 'D', minval=1)
lengthRSI = input.int(14, 'RSI Length', minval=1)
lengthStoch = input.int(14, 'Stochastic Length', minval=1)
src = input(close, title='RSI Source')
//Stoch RSI Components
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
//MACD Inputs
fast_length = input(title='Fast Length', defval=12)
slow_length = input(title='Slow Length', defval=26)
src2 = input(title='Source', defval=close)
signal_length = input.int(title='Signal Smoothing', minval=1, maxval=50, defval=9)
sma_source = input(title='Simple MA (Oscillator)', defval=false)
sma_signal = input(title='Simple MA (Signal Line)', defval=false)
//MACD Components
fast_ma = sma_source ? ta.sma(src2, fast_length) : ta.ema(src2, fast_length)
slow_ma = sma_source ? ta.sma(src2, slow_length) : ta.ema(src2, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
// Ichimoku Components
tenkan = middle(ts_bars)
kijun = middle(ks_bars)
mid_sma = middle(sma_bars)
sec_sma = middle(sec_sma_bars)
senkouA = math.avg(tenkan, kijun)
senkouB = middle(ssb_bars)
// Plot Ichimoku Kinko Hyo
plot(tenkan, color=color.new(#0496ff, 0), title='Tenkan-Sen')
plot(kijun, color=color.new(#991515, 0), title='Kijun-Sen')
plot(mid_sma, color=color.new(color.white, 0), title='50 SMA')
plot(sec_sma, color=color.new(color.orange, 0), title='5 SMA')
plot(close, offset=-cs_offset + 1, color=color.new(color.gray, 0), title='Chikou-Span')
sa = plot(senkouA, offset=ss_offset - 1, color=color.new(color.green, 0), title='Senkou-Span A')
sb = plot(senkouB, offset=ss_offset - 1, color=color.new(color.red, 0), title='Senkou-Span B')
fill(sa, sb, color=senkouA > senkouB ? color.green : color.red, title='Cloud color', transp=90)
ss_high = math.max(senkouA[ss_offset - 1], senkouB[ss_offset - 1])
ss_low = math.min(senkouA[ss_offset - 1], senkouB[ss_offset - 1])
// Entry/Exit Signals
tk_cross_bull = tenkan > kijun
tk_cross_bear = tenkan < kijun
cs_cross_bull = ta.mom(close, cs_offset - 1) > 0
cs_cross_bear = ta.mom(close, cs_offset - 1) < 0
price_above_kumo = close > ss_high
price_below_kumo = close < ss_low
price_between_kumo = close < ss_high and close > ss_low
senkou_green = senkouA > senkouB ? true : false
rsi_value = ta.rsi(close, rsi_period)
trend_midentry_T = close < tenkan or open < tenkan
trend_midentry_K = close > kijun or open > kijun
pp_t = close > tenkan or open > tenkan
pp_k = close < kijun or open < kijun
open_trend_reentry_T = open < tenkan
open_trend_reentry_K = open > kijun
close_trend_reentry_T = close < tenkan
close_trend_reentry_K = close > kijun
kumo_open_trend_reentry_T = open > tenkan
kumo_open_trend_reentry_K = open < kijun
kumo_close_trend_reentry_T = close > tenkan
kumo_close_trend_reentry_K = close < kijun
rsi_positive = k > d
rsi_negative = d > k
rsi_cross = ta.crossover(k, d)
macd_positive = macd > signal and macd > 0
macd_exit = ta.crossover(signal, macd)
macd_entry = ta.crossover(macd, signal)
hist_positive = hist >= 0
higherOrSameClose = close >= close[1]
two_day_higherOrSameClose = close >= close[1] and close[1] >= close[2]
five_day_lowerOrSameClose = close < close[7]
macd_greater_zero = fast_ma > 0
first_exit = ta.crossover(tenkan, close)
avgVol = ta.ema(volume, 50)
support = ta.lowest(close, 25)
five_ten_cross = ta.crossunder(sec_sma, tenkan)
bullish = tk_cross_bull and cs_cross_bull and price_above_kumo
bearish = tk_cross_bear and cs_cross_bear and price_below_kumo
if wait_for_cloud
bullish := bullish and senkou_green
bearish := bearish and not senkou_green
bearish
if use_rsi_entry
bullish := bullish and rsi_value < overbought_rsi
bearish := bearish and rsi_value > oversold_rsi
bearish
in_long = false
in_long := in_long[1]
open_long = bullish and long_entry and not in_long
open_short = bearish and short_entry and in_long
ish_long_entry = tk_cross_bull and cs_cross_bull and price_below_kumo
ish_2nd_long_entry = price_above_kumo and trend_midentry_T and trend_midentry_K
ish_sell_in_trend = price_above_kumo and ta.crossunder(tenkan, kijun)
ish_buy_in_trend = price_above_kumo and ta.crossover(tenkan, kijun) and higherOrSameClose
early_exit_bear = price_below_kumo and ta.crossunder(tenkan, kijun) or first_exit and price_below_kumo
best_entry = rsi_positive and macd_positive and ish_long_entry or ish_buy_in_trend and rsi_positive and macd_positive
best_exit = macd_exit and rsi_negative and ish_2nd_long_entry or first_exit and price_above_kumo
trend_reentry = price_above_kumo and (open_trend_reentry_T or close_trend_reentry_T) and (open_trend_reentry_K or close_trend_reentry_K) and rsi_positive and higherOrSameClose and macd_entry
in_kumo_trend_reentry = price_between_kumo and (kumo_open_trend_reentry_T or kumo_close_trend_reentry_T) and (kumo_open_trend_reentry_K or kumo_close_trend_reentry_K) and rsi_positive and higherOrSameClose and macd_entry
better_entry = price_above_kumo and rsi_cross and macd_greater_zero and higherOrSameClose
in_kumo_trend_reentry1 = price_between_kumo and kumo_open_trend_reentry_T and kumo_open_trend_reentry_K and rsi_positive and higherOrSameClose and macd_entry
in_kumo_trend_reentry2 = price_between_kumo and kumo_close_trend_reentry_T and kumo_close_trend_reentry_K and rsi_positive and higherOrSameClose and macd_entry
better_entry_pos = price_above_kumo and rsi_cross and macd_positive and higherOrSameClose
pre_party = price_below_kumo and (trend_midentry_T and trend_midentry_K or pp_t and pp_k) and two_day_higherOrSameClose and not five_day_lowerOrSameClose and cs_cross_bull
test = cs_cross_bull and price_below_kumo and two_day_higherOrSameClose
trend_breakout_close = not price_below_kumo and ta.crossover(close, tenkan) and rsi_positive and close > open[3]
quick_test = not price_above_kumo and close > tenkan and rsi_positive and higherOrSameClose and close[1] > close[2] and close > close[1] * 1.05
//reversal = price_below_kumo and close > close[1] and close[1] > close[2] and close > support and macd_entry
sell_off = open_short or ish_sell_in_trend
buy_up = open_long or (trend_breakout_close and ish_buy_in_trend) or (better_entry_pos and trend_breakout_close) or (trend_reentry and trend_breakout_close) or (trend_reentry and better_entry_pos) or (in_kumo_trend_reentry and trend_breakout_close) or (pre_party and test) or (quick_test and test)
sell_all = sell_off and volcheck
buy_all = buy_up and volcheck
voliskey = higherOrSameClose and maxvolcheck
all_volcheck = higherOrSameClose and volcheck and open>mid_sma
fifty_bo = trend_breakout_close and volcheck and ta.crossover(close,mid_sma)
show_me = ((ta.crossover(close,tenkan) and ta.crossover(close,kijun)) or (ta.crossover(close,sec_sma) and ta.crossover(close,tenkan))) and close<mid_sma and sec_sma>=tenkan*.99 and (volume > avgvola*.5)
bull_trend = price_above_kumo and close > sec_sma and tenkan>sec_sma and sec_sma>kijun and close>close[1] and close[1] >close[2]
chikcross = ta.crossover(close,mid_sma[20]) and open>mid_sma
ten_chikcross = ta.crossover(close,tenkan[20]) and volume > (avgvola * .75)
upside = low<low[1] and close>close[1] and ((close-low)/(high-low))>.55 and volume>avgvola*1.33 and sec_sma>tenkan
grab_it = voliskey
dump_it = sell_all
ybbo = (trend_breakout_close and better_entry_pos)
olretrace = (open_long and ish_buy_in_trend)
hvretrace = (volcheck and ish_buy_in_trend)
earbuy = quick_test
below_earbuy = (quick_test and test)
sbreak= fifty_bo
ebreak = (trend_breakout_close and quick_test)
olyb = better_entry_pos
if open_long
in_long := true
in_long
if open_short
in_long := false
in_long
rsi_count = 0
arm_tp = false
if use_rsi_tp
rsi_count := rsi_count[1]
if in_long and rsi_value > overbought_rsi or not in_long and rsi_value < oversold_rsi
rsi_count += 1
rsi_count
else
rsi_count := 0
rsi_count
if rsi_count >= seq_rsi
arm_tp := true
arm_tp
//Function Definition
action_alert(_ticker) =>
agrab_it = voliskey
adump_it = sell_all
aybbo = better_entry_pos
aearbuy = quick_test
asbreak= fifty_bo
awatch = show_me
[_grab_it, _ybbo, _earbuy, _sbreak, good_vol, _watch, _bull_trend,_ten_chikcross, _upside] = request.security(_ticker, timeframe.period, [ agrab_it, aybbo, aearbuy, asbreak, all_volcheck, awatch, bull_trend,ten_chikcross, upside])
_msg = _ticker + ',' + timeframe.period + ': '
if _grab_it
_msg += 'Big Volume Buy'
alert(_msg, alert.freq_once_per_bar)
if _ybbo
_msg += 'Yellow Buy'
alert(_msg, alert.freq_once_per_bar_close)
if _earbuy
_msg += 'Early Buy'
alert(_msg, alert.freq_once_per_bar_close)
if _sbreak
_msg += 'Super Breakout'
alert(_msg, alert.freq_once_per_bar_close)
if _bull_trend
_msg += 'Trend'
alert(_msg, alert.freq_once_per_bar_close)
if good_vol
_msg += 'Good Vol'
alert(_msg, alert.freq_once_per_bar_close)
if chikcross
_msg += 'Chikou Cross'
alert(_msg, alert.freq_once_per_bar_close)
if _ten_chikcross
_msg += '10 Chikou Cross'
alert(_msg, alert.freq_once_per_bar_close)
if _upside
_msg += 'Upside Reversal'
alert(_msg, alert.freq_once_per_bar_close)
barcolor(sell_all ? bo : na, editable=false)
barcolor(buy_all ? suy : na, editable=false)
barcolor(voliskey ? color.yellow : na, editable=false)
barcolor(all_volcheck ? suy : na, editable=false)
//Alert Plots
plotshape(open_short, text='Open Short', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.red, 0))
plotshape(better_entry_pos, text='Buy', style=shape.arrowup, location=location.belowbar, color=color.new(#FFC803, 0), textcolor=color.new(#FFC803, 0))
plotshape(bull_trend, text='Trend', style=shape.arrowup, location=location.belowbar, color=color.new(#00BFFF, 0), textcolor=color.new(#00BFFF, 0))
plotshape(quick_test, text='Early Buy', style=shape.arrowup, location=location.belowbar, color=color.new(color.orange, 0), textcolor=color.new(color.orange, 0))
plotshape(chikcross, text='Chikou Cross', style=shape.arrowup, location=location.belowbar, color=color.new(#00FFFF, 0), textcolor=color.new(#00FFFF, 0))
plotshape(voliskey, text= "Big Vol", style=shape.arrowup, location=location.belowbar, color=color.new(color.yellow, 0), textcolor=color.new(color.yellow, 0))
plotshape(fifty_bo, text= "Super Breakot", style=shape.arrowup, location=location.belowbar, color=color.new(color.white, 0), textcolor=color.new(color.white, 0))
plotshape(ybbo, text='Good Buy Breakout', style=shape.arrowup, location=location.belowbar, color=color.new(#66FF00, 0), textcolor=color.new(#66FF00, 0))
plotshape(all_volcheck, text='Good Volume', style=shape.arrowup, location=location.belowbar, color=color.new(color.lime, 0), textcolor=color.new(color.lime, 0))
plotshape(hvretrace, text="Retrace", style=shape.arrowup, location=location.belowbar, color=color.new(color.aqua, 0), textcolor=color.new(color.aqua, 0))
plotshape(ten_chikcross, text='10 Chikou Cross', style=shape.arrowup, location=location.belowbar, color=color.new(#00BFFF, 0), textcolor=color.new(#00BFFF, 0))
plotshape(upside, text='Upside Reversal', style=shape.arrowup, location=location.belowbar, color=color.new(#C3CDE6, 0), textcolor=color.new(#C3CDE6, 0))
//Position Alert
action_alert("AMEX:DRIP")
action_alert("AMEX:DUG")
action_alert("AMEX:EQX")
action_alert("AMEX:ERY")
action_alert("AMEX:NGD")
action_alert("AMEX:TZA")
Second Code (not working)
//#version=5
indicator("Ish's Relative Strength")
length = 20
five_sma=ta.sma(close,5)
var prevRatio = 0.0
//Save each ratio so we can look for RS line new high
var array=array.new_float(0)
// RS - IBD
ThreeMonthRS = 0.4 * (close / close[13])
SixMonthRS = 0.2 * (close / (close[26] * 2))
NineMonthRS = 0.2 * (close / (close[39] * 3))
TwelveMonthRS = 0.2 * (close / (close[52] * 4))
RatingRS = (ThreeMonthRS + SixMonthRS + NineMonthRS + TwelveMonthRS) * 100
rsText = "RS Rating \n" + str.tostring(RatingRS, "0.00")
//Gather Compared Index/Stock
comparedSymbol = input.symbol(title="Benchmark RS Line", defval="QQQ", group="Relative Strength")
comparedClose = request.security(comparedSymbol, timeframe.period, close)
cThreeMonthRS = 0.4 * (comparedClose / comparedClose[13])
cSixMonthRS = 0.2 * (comparedClose / (comparedClose[26] * 2))
cNineMonthRS = 0.2 * (comparedClose / (comparedClose[39] * 3))
cTwelveMonthRS = 0.2 * (comparedClose / (comparedClose[52] * 4))
cRatingRS = (cThreeMonthRS + cSixMonthRS + cNineMonthRS + cTwelveMonthRS) * 100
crsText = "Comp RS \n" + str.tostring(cRatingRS, "0.00")
compratio = "RS Ratio \n" + str.tostring(RatingRS/cRatingRS, "0.00")
compratioNUM = RatingRS/cRatingRS
posslope= (compratioNUM-compratioNUM[2])/2
posfive=five_sma-five_sma[1]
slope=ta.sma(compratioNUM,5)
getin=ta.crossover(compratioNUM,slope) and posslope>0 and posfive>0
//Color of line to show up or down
ColorUp = color.new(color.green,0)
ColorDown = color.new(color.red,0)
linecolor = (posslope>.02 and posfive>.02)? ColorUp: ColorDown
//plot(RatingRS, color=color.new(color.white, 0), title='50 SMA')
//plot(cRatingRS, color=color.new(color.white, 0), title='Test')
plot(compratioNUM, color=linecolor, linewidth=2, title="Got It")
//plot(slope, color=color.new(color.lime,0),title="Please Work")
//plotshape(getin, title="Get In", style=shape.arrowup, location=location.belowbar, color=color.new(#C3CDE6,0), textcolor=color.new(#C3CDE6,0))
//Show high dot based on time
if (barstate.islast)
newHigh=true
for i=0 to 27
if(array.get(array, i)>compratioNUM)
newHigh:=false
break
if (newHigh)
label.new(bar_index, compratioNUM, color=color.new(color.green,40), style=label.style_circle, size=size.tiny)
if (barstate.islast)
newLow=true
for i=0 to 27
if(array.get(array, i)<compratioNUM)
newLow:=false
break
if (newLow)
label.new(bar_index, compratioNUM, color=color.new(color.red, 40), style=label.style_circle, size=size.tiny)
prevRatio:=compratioNUM
array.unshift(array, compratioNUM)
action_alert(_ticker) =>
test= newHigh
[_test] = request.security(_ticker, timeframe.period, [newHigh])
_msg = _ticker + ',' + timeframe.period + ': '
if _test
_msg += 'New High'
alert(_msg, alert.freq_once_per_bar)
//Position Alert
action_alert("AMEX:DRIP")
action_alert("AMEX:DUG")
action_alert("AMEX:EQX")
action_alert("AMEX:ERY")
action_alert("AMEX:NGD")
action_alert("AMEX:TZA")
Green dot showing new high value of relative strength reached over the last 28 days

Need to remove the previous day plots in tradingview - pinescript

This is my code. Can you please update your answer in this bcz i tried and the indicator is not compiled properly.
//#version=3
study(title="TEST", overlay=true)
fib1 = security(tickerid,"D",high[1], lookahead=barmerge.lookahead_on)
fib0 = security(tickerid,"D",low[1], lookahead=barmerge.lookahead_on)
plotS1 = input(title="Plot S1", type=bool, defval=true)
plotR1 = input(title="Plot R1", type=bool, defval=true)
R1 = (fib0-fib1)*0.215+fib1
S1 = (fib0-fib1)*0.79+fib1
plot(series=plotR1 ? R1 : na, title="R1", style=cross, linewidth=1, color=#EEC900) plot(series=plotS1 ? S1 : na, title="S1", style=cross, linewidth=1, color=#EEC900)
//#version=4
study("Fib", "FiB", true)
[fib1,fib0] = security(syminfo.tickerid, "D", [high[2], low[2]], lookahead=barmerge.lookahead_on)
is_today = year == year(timenow) and month == month(timenow) and dayofmonth == dayofmonth(timenow)
plot(fib0, "fib0", is_today ? color.green : na)
plot(fib1, "fib1", is_today ? color.blue : na)