Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

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

0 at
https://mozilla.org/MPL/2.0/
// © Cbgbm788

//@version=5
strategy('Break out Buy EXP BARS', shorttitle='BREAK OUT BUY EXP BARS',
pyramiding=0, overlay=true)
//input
HLPeriod = input(0.382, title='HighLow Period')
SK = input.float(2, title='SK') * 0.001
SLL = input.float(10, title='SL') * 0.001
TPP = input.float(20, title="TP")*0.001
res = input.timeframe(title='Timeframe', defval='D')
montha = input.int(title='Montha', defval=1, minval=0, maxval=12)
startY = input(title='Start Year', defval=2011)
startM = input.int(title='Start Month', defval=1, minval=1, maxval=12)
startD = input.int(title='Start Day', defval=1, minval=1, maxval=31)
finishY = input(title='Finish Year', defval=2050)
finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12)
finishD = input.int(title='Finish Day', defval=31, minval=1, maxval=31)

//finish = input(2019, 02, 28, 00, 00)


timestart = timestamp(startY, startM, startD, 00, 00)
timefinish = timestamp(finishY, finishM, finishD, 23, 59)
window = time >= timestart and time <= timefinish ? true : false // Lenghth
strategy
//Highest Lowest
//Pivot
H = request.security(syminfo.tickerid, res, high[1], barmerge.gaps_off,
barmerge.lookahead_on)
L = request.security(syminfo.tickerid, res, low[1], barmerge.gaps_off,
barmerge.lookahead_on)
C = request.security(syminfo.tickerid, res, close[1], barmerge.gaps_off,
barmerge.lookahead_on)

BarsSinceLastEntry() =>
strategy.opentrades > 0 ? bar_index -
strategy.opentrades.entry_bar_index(strategy.opentrades - 1) : na

// Fibonacci Pivots
pivot = (H + L + C) / 3
R = pivot + (H - L) * HLPeriod
S = pivot - (H - L) * HLPeriod

longCondition = low < R and close > R


LO = ta.valuewhen(longCondition, close, 0) - SK
SL = LO - SLL
TP = LO + TPP

//entry
if longCondition and month == montha and window and strategy.position_size == 0
strategy.entry('My Long Entry Id', strategy.long, limit=LO)
strategy.exit('close', stop=SL[bar_index -
strategy.opentrades.entry_bar_index(strategy.opentrades - 1)] ,comment='close')
if BarsSinceLastEntry() >= 1 and high >= TP[bar_index -
strategy.opentrades.entry_bar_index(strategy.opentrades - 1)]
strategy.close_all("closeTP",immediately = true)

//cancel
if ta.change(time(res))
strategy.cancel_all()
strategy.close_all("close position order",immediately = true)

//for debug
plot(strategy.position_size > 0 ? SL[bar_index -
strategy.opentrades.entry_bar_index(strategy.opentrades - 1)] : na,
style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='Long
Fixed SL')
plot(strategy.position_size > 0 ? TP[bar_index -
strategy.opentrades.entry_bar_index(strategy.opentrades - 1)] : na,
style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='Long
Fixed SL')
plot(R, style=plot.style_stepline)
plot(S, style=plot.style_stepline)

You might also like