0% found this document useful (0 votes)
8 views

CPR Script

The document contains a Pine Script code for a trading strategy that includes Exponential Moving Averages (EMAs) and pivot point calculations for weekly and daily timeframes. It also implements buy and sell signals based on breakout conditions and RSI values. The code is structured to allow customization of parameters such as pivot resolution and session timings.

Uploaded by

Krishna Aero
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

CPR Script

The document contains a Pine Script code for a trading strategy that includes Exponential Moving Averages (EMAs) and pivot point calculations for weekly and daily timeframes. It also implements buy and sell signals based on breakout conditions and RSI values. The code is structured to allow customization of parameters such as pivot resolution and session timings.

Uploaded by

Krishna Aero
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

// This source code is subject to the terms of the Mozilla Public License

2.0 at https://mozilla.org/MPL/2.0/
// © allanster

//@version=4
study(title = "CPR Weekly", shorttitle = "CPR", overlay = true, precision =
2, max_bars_back = 200)
//study(title="EMA 20/50/100/200", overlay=true)
ema15 = ema(close, 15)
ema35 = ema(close, 35)
ema100 = ema(close, 100)
ema200 = ema(close, 200)
plot(ema15 , title = "ema15", color = color.rgb(245, 197, 125), linewidth =
2)
plot(ema35 , title = "ema35", color = color.green, linewidth = 2,display=0)
plot(ema100 , title = "ema100", color = color.rgb(12, 12, 12), linewidth =
3,display=0)
plot(ema200 , title = "ema200", color =color.rgb(241, 9, 9, 1), linewidth =
4,display=0)

//@version=4

pivottimeframe = input(title="Pivot Resolution", defval="W", options=["D",


"W", "M"])
dp = input(true, title="Show Floor Pivots")
tp = input(false, title="Show Tomorrow Pivots")

//dp in the prefix implies daily pivot calculation


dpopen = security(syminfo.tickerid, pivottimeframe, open[1],
barmerge.gaps_off, barmerge.lookahead_on)
dphigh = security(syminfo.tickerid, pivottimeframe, high[1],
barmerge.gaps_off, barmerge.lookahead_on)
dplow = security(syminfo.tickerid, pivottimeframe, low[1],
barmerge.gaps_off, barmerge.lookahead_on)
dpclose = security(syminfo.tickerid, pivottimeframe, close[1],
barmerge.gaps_off, barmerge.lookahead_on)
dprange = dphigh - dplow

//Expanded Floor Pivots Formula


pivot = (dphigh + dplow + dpclose) / 3.0
bc = (dphigh + dplow) / 2.0
tc = pivot - bc + pivot
r1 = pivot * 2 - dplow
s1 = pivot * 2 - dphigh

//Tomorrow's Pivot Calculation

tpopen = security(syminfo.tickerid, pivottimeframe, open,


barmerge.gaps_off, barmerge.lookahead_on)
tphigh = security(syminfo.tickerid, pivottimeframe, high,
barmerge.gaps_off, barmerge.lookahead_on)
tplow = security(syminfo.tickerid, pivottimeframe, low, barmerge.gaps_off,
barmerge.lookahead_on)
tpclose = security(syminfo.tickerid, pivottimeframe, close,
barmerge.gaps_off, barmerge.lookahead_on)
tprange = tphigh - tplow

tppivot = (tphigh + tplow + tpclose) / 3.0


tpbc = (tphigh + tplow) / 2.0
tptc = tppivot - tpbc + tppivot
tpr1 = tppivot * 2 - tplow
tps1 = tppivot * 2 - tphigh
tph3 = tpclose + tprange * (1.1 / 4)
tpl3 = tpclose - tprange * (1.1 / 4)

//m,w,d in the prefix implies monthly, weekly and daily


mhigh = security(syminfo.tickerid, "M", high[1],
lookahead=barmerge.lookahead_on)
mlow = security(syminfo.tickerid, "M", low[1],
lookahead=barmerge.lookahead_on)
whigh = security(syminfo.tickerid, "W", high[1],
lookahead=barmerge.lookahead_on)
wlow = security(syminfo.tickerid, "W", low[1],
lookahead=barmerge.lookahead_on)
dhigh = security(syminfo.tickerid, "D", high[1],
lookahead=barmerge.lookahead_on)
dlow = security(syminfo.tickerid, "D", low[1],
lookahead=barmerge.lookahead_on)
//dclose = security(tickerid, "D", close[1],
lookahead=barmerge.lookahead_on)

//Plotting
plot(dp and pivot ? pivot : na, title="Pivot", color=color.rgb(240, 24,
139), style=plot.style_circles, linewidth=3)
plot(dp and bc ? bc : na, title="BC", color=color.navy,
style=plot.style_circles, linewidth=3)
plot(dp and tc ? tc : na, title="TC", color=color.navy,
style=plot.style_circles, linewidth=3)
plot(dp and r1 ? r1 : na, title="R1", color=color.red,
style=plot.style_circles, linewidth=3)
plot(dp and s1 ? s1 : na, title="S1", color=color.green,
style=plot.style_circles, linewidth=3)
plot(tp and tppivot ? tppivot : na, title="Pivot",color=color.fuchsia,
style=plot.style_circles , linewidth=3)
plot(tp and tpbc ? tpbc : na, title="BC",color= color.navy,
style=plot.style_circles, linewidth=3)
plot(tp and tptc ? tptc : na, title="TC",color= color.navy,
style=plot.style_circles, linewidth=3)
plot(tp and tpr1 ? tpr1 : na, title="R1",color= color.red,
style=plot.style_circles, linewidth=3)
plot(tp and tps1 ? tps1 : na, title="S1",color= color.green,
style=plot.style_circles, linewidth=3)
//
lookback = input(title="Lookback:", type=input.integer, defval=7)
rsiLen = input(title="RSI Length:", type=input.integer, defval=14)
rsiSrc = input(title="RSI Source:", type=input.source, defval=close)

// Get RSI value


rsi = rsi(rsiSrc, rsiLen)
//len = input(14, minval=1, title="Length")
//src = input(close, "Source", type = input.source)
//up = rma(max(change(src), 0), len)
//down = rma(-min(change(src), 0), len)
//mid = rma(-min(change(src), 0), len)
//rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

//breakdown=(crossunder(close,shortest) and rsi < 50 and condition11 and


condition12 and condition13 and condition1 and condition2 and condition3)
//breakout=(crossover(close,shortest)and rsi >50 and condition14 and
condition15 and condition16 and condition4 and condition5 and condition6)
//
plotshape(breakdown,style=shape.labeldown,text="SELL",location=location.abo
vebar, color=color.red,textcolor=color.white)
//
plotshape(breakout,style=shape.labelup,text="BUY",location=location.belowba
r, color=color.green,textcolor=color.white)
//plot(breakout,style=plot.style_line, color=color.red)
//plot(breakdown ? low : na, color=color.red,style =
plot.style_line,linewidth = 2 )
//down = valuewhen(breakdown,low,0)
//up = valuewhen(breakout,high,0)
//plot(down, title
="Breakdown",color=color.red,style=plot.style_stepline,linewidth=2)
//plot(up,title
="Breakout",color=color.green,style=plot.style_stepline,linewidth=2)
//
plotshape(crossunder(close,down),style=shape.labeldown,text="entry",locatio
n=location.abovebar, color=color.red,textcolor=color.white)
//
plotshape(crossover(close,up),style=shape.labelup,text="entry",location=loc
ation.belowbar, color=color.green,textcolor=color.white)
// This source code is subject to the terms of the Mozilla Public License
2.0 at https://mozilla.org/MPL/2.0/
// © marketcalls_in
// Founder - Marketcalls (www.marketcalls.in)
// Co-Founder - Algomojo (www.algomojo.com)

//@version=4
//study("Open Range Breakout",overlay=true)

tf = input(title="Resolution",type = input.resolution,defval = "5")


//which timeframe you want to move
session = input(title="Breakout Timings",defval="0915-0920",
type=input.session)
linew = input(title="Line Width",type = input.integer,
defval=1,minval=1,maxval=5)

//is the market trading in between the session timings? If yes then it
returns true
Barsinsession(session) => time(tf,session) != 0 //single line function
Insession = Barsinsession(session) ? 1 : 0
endofsession = Insession == 0 and Insession[1] == 1 //end of the session
if it is happening -> returns ture
//high value and low value from 60min timeframe charts
hi = security(syminfo.tickerid,tf,high)
lo = security(syminfo.tickerid,tf,low)

orbh = valuewhen(endofsession,hi,0) //first time computation


orbl = valuewhen(endofsession,lo,0)

orbh := Barsinsession(session) ? na : orbh //rewriting the value storing


a different value
orbl := Barsinsession(session) ? na : orbl //rewriting the value storing
a different value

Buy = crossover(high,orbh)
Short = crossunder(low,orbl)

//flip
Buycontinue = barssince(Buy) < barssince(Short)
Shortcontinue = barssince(Short) < barssince(Buy)

newday = dayofmonth != dayofmonth[1]

var isLong = false


var isShort = false

//exrem
Buy := not isLong and Buy
Short := not isShort and Short

if Buy
isLong := true
isShort := false

if Short
isLong := false
isShort := true

if newday[1]
isLong := false
isShort := false

//indicates the buy or sell signal


//plotshape(Buy,style=shape.labelup,location =
location.belowbar,color=color.green,title =
"B",text="B",textcolor=color.white)
//plotshape(Short,style=shape.labeldown,location =
location.abovebar,color=color.red,title =
"S",text="S",textcolor=color.white)

alertcondition(Buy, title='Buy Alert', message='Buy Signal!')


alertcondition(Short, title='Short Alert', message='Short Signal!')

//plot(orbh,color=color.red,style=plot.style_circles,linewidth=linew)
//plot(orbl,color=color.lime,style=plot.style_circles,linewidth=linew)

You might also like