Professional Documents
Culture Documents
// No repaint
res = timeframe.ismonthly ? str.tostring(timeframe.multiplier, '###M')
: timeframe.isweekly ? str.tostring(timeframe.multiplier, '###W')
: timeframe.isdaily ? str.tostring(timeframe.multiplier, '###D')
: timeframe.isintraday ? str.tostring(timeframe.multiplier, '####') : '60'
closey = request.security(syminfo.tickerid, res, close[barstate.isrealtime ? 1:0])
openy = request.security(syminfo.tickerid, res, open[barstate.isrealtime ? 1:0])
// Inputs
tradeType = input.string('BOTH', title='Trades ', options=['LONGS', 'SHORTS',
'BOTH', 'NONE'], inline='1')
TD = input.int(70, title='Trade infrequency', inline='1')
txt1 = "If no trend smoother ticked then default trend step is used with the Trade
infrequency number for the steps"
SmA = input.bool(false, title='Use Trend smoother with', inline='2',
tooltip=txt1)
smaAmount = input.int(100, title=' amount', step=5, inline='2')
tpPer = input.float(1.5, title='TP %', step=0.1, inline='3')
slPer = input.float(1, title='SL %', minval=0, step=0.1, inline='3')
// Decs
var float entryprice = 0.0
var float tradeStopPrice = 0.0
var float tp1 = 0.0, var float tp2 = 0.0, var float tp3 = 0.0, var float tp4 = 0.0,
var float tp5 = 0.0
float SL = close/100 * slPer
SLtick = math.round_to_mintick(slPer*close)
shortstopprice = math.round_to_mintick(low+SL)
longstopprice = math.round_to_mintick(high-SL)
// Colors
xbear = xcols == #cc0000 and (nz(Dn_x,xcols == #cc0000))
xbull = xcols == #33cc33 and (nz(Up_x,xcols == #33cc33))
barColor = xbull ? #33cc33 : xbear ? #cc0000 : na //green and red
barcolor(barColor, title='Bar Colours')
// long entry and stop price capture at point of entry (keeps the plot lines
straight and allows constant saved variable for strat exits below)
if validLong
entryprice := ta.valuewhen(longCondition,close,0)
tradeStopPrice := int(longstopprice)
tp1 := entryprice*(tpPer/100)/5*1/syminfo.mintick
tp2 := entryprice*(tpPer/100)/5*2/syminfo.mintick
tp3 := entryprice*(tpPer/100)/5*3/syminfo.mintick
tp4 := entryprice*(tpPer/100)/5*4/syminfo.mintick
tp5 := entryprice*(tpPer/100)/5*5/syminfo.mintick
// short entry and stop price capture at point of entry (keeps the plot lines
straight and allows constant saved variable for strat exits below)
if validShort
entryprice := ta.valuewhen(shortCondition,close,0)
tradeStopPrice := int(shortstopprice)
tp1 := entryprice*(tpPer/100)/5*1/syminfo.mintick
tp2 := entryprice*(tpPer/100)/5*2/syminfo.mintick
tp3 := entryprice*(tpPer/100)/5*3/syminfo.mintick
tp4 := entryprice*(tpPer/100)/5*4/syminfo.mintick
tp5 := entryprice*(tpPer/100)/5*5/syminfo.mintick
if myWindow
if (tradeType == 'LONGS' or tradeType == 'BOTH')
strategy.entry(id='L', direction=strategy.long, qty=5, when=validLong)
strategy.exit(id='L_tp1', from_entry='L', qty=1, profit=tp1, loss=SLtick,
when=strategy.position_size > 0)
strategy.exit(id='L_tp2', from_entry='L', qty=1, profit=tp2, loss=SLtick,
when=strategy.position_size > 0)
strategy.exit(id='L_tp3', from_entry='L', qty=1, profit=tp3, loss=SLtick,
when=strategy.position_size > 0)
strategy.exit(id='L_tp4', from_entry='L', qty=1, profit=tp4, loss=SLtick,
when=strategy.position_size > 0)
strategy.exit(id='L_tp5', from_entry='L', qty=1, profit=tp5, loss=SLtick,
when=strategy.position_size > 0)
strategy.close(id='L', qty_percent=100, when=ta.crossunder(close,
tradeStopPrice))// close if stop hit