Professional Documents
Culture Documents
Half Trend Other With VWAP MA Alerts
Half Trend Other With VWAP MA Alerts
Half Trend Other With VWAP MA Alerts
0 at
https://mozilla.org/MPL/2.0/
// © Sandesh
//@version=4
//***************GUIDE***********************************
//CPR - Applicable only for daily pivots
//CPR - All 3 lines display enabled by default
//CPR - Central Pivot line display cannot changed
//CPR - Central Pivot is a blue line by default and can be changed from settings
//CPR - Top Range & Bottom Ranage display can be changed from settings
//CPR - Top Range & Bottom Ranage are Yellow lines by default and can be chaned
from settings
//Daily pivots - Pivot line and CPR Central line are samea
//Daily pivots - level 1 & 2 (S1, R1, S2 R2) display enabled by default and can be
changed from settings
//Daily pivots - level 3 (S3 & R3) is availale and can be seleted from settings
//Daily pivots - Resistance(R) lines are Red lines and can be changed from settings
//Daily pivots - Support(S) lines are Green lines and can be changed from settings
//Weekly pivots - Pivot is a blue line by default and can be changed from settings
//Weekly pivots - 3 levels (S1, R1, S2, R2, S3 & R3) availale and can be seleted
from settings
//Weekly pivots - Resistance(R) lines are crossed (+) Red lines and can be changed
from settings
//Weekly pivots - Support(S) lines are crossed (+) Green lines and can be changed
from settings
//Monthly pivots - Pivot is a blue line by default and can be changed from settings
//Monthly pivots - 3 levels (S1, R1, S2, R2, S3 & R3) availale and can be seleted
from settings
//Monthly pivots - Resistance(R) lines are circled (o) Red lines and can be changed
from settings
//Monthly pivots - Support(S) lines are circled (o) Green lines and can be changed
from settings
//Checkbox inputs
CPRPlot = input(title = "Plot CPR?", type=input.bool, defval=true)
DayS1R1 = input(title = "Plot Daiy S1/R1?", type=input.bool, defval=true)
DayS2R2 = input(title = "Plot Daiy S2/R2?", type=input.bool, defval=true)
DayS3R3 = input(title = "Plot Daiy S3/R3?", type=input.bool, defval=true)
WeeklyPivotInclude = input(title = "Plot Weekly Pivot?", type=input.bool,
defval=true)
WeeklyS1R1 = input(title = "Plot weekly S1/R1?", type=input.bool, defval=true)
WeeklyS2R2 = input(title = "Plot weekly S2/R2?", type=input.bool, defval=true)
WeeklyS3R3 = input(title = "Plot weekly S3/R3?", type=input.bool, defval=false)
MonthlyPivotInclude = input(title = "Plot Montly Pivot?", type=input.bool,
defval=true)
MonthlyS1R1 = input(title = "Plot Monthly S1/R1?", type=input.bool, defval=true)
MonthlyS2R2 = input(title = "Plot Monthly S2/R2?", type=input.bool, defval=true)
//MonthlyS3R3 = input(title = "Plot Montly S3/R3?", type=input.bool, defval=false)
//******************WEEKLY PIVOTS**************************
//******************MONTHLY PIVOTS**************************
//*****************************INDICATORs**************************
//EMA 20
PlotSMA = input(title = "Plot EMA?", type=input.bool, defval=true)
SMALength = input(title="EMA Length", type=input.integer, defval=20)
SMASource = input(title="EMA Source", type=input.source, defval=close)
SMAvg = ema (SMASource, SMALength)
plot(PlotSMA ? SMAvg : na, color= color.blue, title="EMA 20")
//EMA 50
PlotEMA50 = input(title = "Plot EMA?", type=input.bool, defval=true)
EMALength50 = input(title="EMA Length", type=input.integer, defval=50)
EMASource50 = input(title="EMA Source", type=input.source, defval=close)
EMAvg50 = ema (EMASource50, EMALength50)
plot(PlotEMA50 ? EMAvg50 : na, color= color.red, title="EMA 50")
//EMA 200
PlotEMA200 = input(title = "Plot EMA?", type=input.bool, defval=true)
EMALength200 = input(title="EMA Length", type=input.integer, defval=200)
EMASource200 = input(title="EMA Source", type=input.source, defval=close)
EMAvg200 = ema (EMASource200, EMALength200)
plot(PlotEMA200 ? EMAvg200 : na, color= color.black, title="EMA 200")
//VWAP
PlotVWAP = input(title = "Plot VWAP?", type=input.bool, defval=true)
VWAPSource = input(title="VWAP Source", type=input.source, defval=close)
VWAPrice = vwap (VWAPSource)
plot(PlotVWAP ? VWAPrice : na, color= #fbc02d, title="VWAP", style =
plot.style_stepline, linewidth =2)
//PDH
PrevBars = input(title = "Show previous highs and lows?", type =input.bool,
defval=false)
condition = not(timeframe.isweekly or timeframe.ismonthly)
h = security(syminfo.tickerid,"D",high,barmerge.gaps_off,barmerge.lookahead_on)
l = security(syminfo.tickerid,"D",low,barmerge.gaps_off,barmerge.lookahead_on)
if (newSession)
PrevHigh := line.new(x1=bar_index, y1=h[1],
x2=bar_index, y2=h[1], color=#0E6720,width=1)
PrevLow := line.new(x1=bar_index,y1=l[1],
x2=bar_index,y2=l[1],color=#AF0D26,width = 1)
line.delete(id = PrevHigh[1])
line.delete(id = PrevLow[1])
if (not barstate.islast)
line.set_x2(id= PrevHigh, x=bar_index)
line.set_x2(id= PrevLow, x=bar_index)
else
line.set_xloc(id=PrevHigh, x1=time[count + 1],
x2=time_close + (1 * 86400000), xloc=xloc.bar_time)
line.set_xloc(id=PrevLow, x1=time[count + 1],
x2=time_close + (1 * 86400000), xloc=xloc.bar_time)
//previous week
prevWeekHigh = security(syminfo.tickerid, 'W', high[1], lookahead=true)
prevWeekLow = security(syminfo.tickerid, 'W', low[1], lookahead=true)
amplitude = 1
channelDeviation = 2
atr2 = atr(100) / 2
dev = channelDeviation * atr2
highPrice = high[abs(highestbars(1))]
lowPrice = low[abs(lowestbars(1))]
highma = sma(high, 1)
lowma = sma(low, 1)
if nextTrend == 1
maxLowPrice := max(lowPrice, maxLowPrice)
if trend == 0
if not na(trend[1]) and trend[1] != 0
up := na(down[1]) ? down : down[1]
arrowUp := up - atr2
else
up := na(up[1]) ? maxLowPrice : max(maxLowPrice, up[1])
atrHigh := up + dev
atrLow := up - dev
else
if not na(trend[1]) and trend[1] != 1
down := na(up[1]) ? up : up[1]
arrowDown := down + atr2
else
down := na(down[1]) ? minHighPrice : min(minHighPrice, down[1])
atrHigh := down + dev
atrLow := down - dev
ht = trend == 0 ? up : down
//halftrend2
highPriceHT2 = high[abs(highestbars(2))]
lowPriceHT2 = low[abs(lowestbars(2))]
highmaHT2 = sma(high, 2)
lowmaHT2 = sma(low, 2)
if nextTrendHT2 == 1
maxLowPriceHT2 := max(lowPriceHT2, maxLowPriceHT2)
if highmaHT2 < maxLowPriceHT2 and close < nz(low[1], low)
trendHT2 := 1
nextTrendHT2 := 0
minHighPriceHT2 := highPriceHT2
else
minHighPriceHT2 := min(highPriceHT2, minHighPriceHT2)
if trendHT2 == 0
if not na(trendHT2[1]) and trendHT2[1] != 0
upHT2 := na(downHT2[1]) ? downHT2 : downHT2[1]
arrowUpHT2 := upHT2 - atr2
else
upHT2 := na(upHT2[1]) ? maxLowPriceHT2 : max(maxLowPriceHT2, upHT2[1])
atrHighHT2 := upHT2 + dev
atrLowHT2 := upHT2 - dev
else
if not na(trendHT2[1]) and trendHT2[1] != 1
downHT2 := na(upHT2[1]) ? upHT2 : upHT2[1]
arrowDownHT2 := downHT2 + atr2
else
downHT2 := na(downHT2[1]) ? minHighPriceHT2 : min(minHighPriceHT2,
downHT2[1])
atrHighHT2 := downHT2 + dev
atrLowHT2 := downHT2 - dev
//halftrend3
highPriceHT3 = high[abs(highestbars(3))]
lowPriceHT3 = low[abs(lowestbars(3))]
highmaHT3 = sma(high, 3)
lowmaHT3 = sma(low, 3)
if nextTrendHT3 == 1
maxLowPriceHT3 := max(lowPriceHT3, maxLowPriceHT3)
if highmaHT3 < maxLowPriceHT3 and close < nz(low[1], low)
trendHT3 := 1
nextTrendHT3 := 0
minHighPriceHT3 := highPriceHT3
else
minHighPriceHT3 := min(highPriceHT3, minHighPriceHT3)
if trendHT3 == 0
if not na(trendHT3[1]) and trendHT3[1] != 0
upHT3 := na(downHT3[1]) ? downHT3 : downHT3[1]
arrowUpHT3 := upHT3 - atr2
else
upHT3 := na(upHT3[1]) ? maxLowPriceHT3 : max(maxLowPriceHT3, upHT3[1])
atrHighHT3 := upHT3 + dev
atrLowHT3 := upHT3 - dev
else
if not na(trendHT3[1]) and trendHT3[1] != 1
downHT3 := na(upHT3[1]) ? upHT3 : upHT3[1]
arrowDownHT3 := downHT3 + atr2
else
downHT3 := na(downHT3[1]) ? minHighPriceHT3 : min(minHighPriceHT3,
downHT3[1])
atrHighHT3 := downHT3 + dev
atrLowHT3 := downHT3 - dev
buySignal = not na(arrowUp) and (trend == 0 and trend[1] == 1 and trendHT2 == 0 and
trendHT2[1] == 1 and trendHT3 == 0 and trendHT3[1] == 1 )
sellSignal = not na(arrowDown) and (trend == 1 and trend[1] == 0 and trendHT2 == 1
and trendHT2[1] == 0 and trendHT3 == 1 and trendHT3[1] == 0)