5min Eth
5min Eth
5min Eth
0 at
https://mozilla.org/MPL/2.0/
//@version=5
//This Strategy Combined the following indicators and conditioning by me
//ATR , RSI , EMA , SMA and Linear regression curve.
strategy("5mineth", overlay=true )
// INPUT BACKTEST RANGE
var string BTR1 = '════════ INPUT BACKTEST TIME RANGE ════════'
i_startTime = input.time(defval = timestamp("01 Jan 1945 00:00 +0000"),
title = "Start", inline="timestart", group=BTR1)
i_endTime = input.time(defval = timestamp("01 Jan 2074 23:59 +0000"),
title = "End", inline="timeend", group=BTR1)
timeCond = (time > i_startTime) and (time < i_endTime)
// Strategy Setting
riskPer = input.int(15, "Lost per trade(in fiat$)", minval = 1,
group='═ Strategy Setting ═', tooltip = 'เจ๊งได้เท่าไหร่?(ต่อ 1 ไม้นะ)')
cond0 = 'Break Cloud + Pivot' , cond1 = 'Break Cloud + Pivot +
Subhag Filter' , cond2 = 'Cloud-MA(New)'
conditype = input.string(cond2, "Order Condition",
options=[cond0,cond1, cond2] ,group='═ Strategy Setting ═')
uselong = input.bool(title="Open Buy?", defval = true , group='═
Strategy Setting ═')
useshort = input.bool(title="Open Sell?", defval = true , group='═
Strategy Setting ═')
usetpsma = input.bool(title="Use SMA Take Profit?", defval = true ,
group='═ Strategy Setting ═')
usetp = input.bool(title="Use RRR Take Profit?", defval = true ,
inline='Set', group='═ Strategy Setting ═')
usetpcl = input.color(defval=color.new(color.orange,0),
title='Color', inline='Set', group='═ Strategy Setting ═')
rrPer = input.float(4.00, "Risk:Reward", minval = 1, step=0.1,
group='═ Strategy Setting ═')
TPper = input.float(25, "Equity % Take Profit", minval = 0.1,
step=5, group='═ Strategy Setting ═', tooltip='Take a snack and let profit run.')
/////////////////////////
ATR //////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
Periods = input.int(title="ATR Period", defval=16 ,group='═ ATR
Setting ═')
Multiplier = input.float(title="ATR Multiplier", step=0.1,
defval=1.6,group='═ ATR Setting ═')
ATR = ta.sma(ta.tr,Periods)
downT = high + ATR * Multiplier
upT = low - ATR * Multiplier
[supertrend, direction] = ta.supertrend(Multiplier, Periods)
/////////////////////////
RSI //////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
LengthRSI = input.int(36,'RSI', minval=1, group='═ RSI Setting ═')
LengthRSIMA = input.int(14,'RSI-MA', minval=1, group='═ RSI Setting ═',
tooltip = 'RSI MA corss 50 Trigger Order')
rsibb = ta.rsi(close,LengthRSI)
rsiMA = ta.sma(rsibb,LengthRSIMA)
/////////////////////////
MA ///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
LengthMA = input.int(29,'EMA Trend line', minval=1, group='═ MA
Setting ═', tooltip = 'Act as Trend line')
sma2cl = input.color(defval=color.new(color.purple,0), title='SMA
TP line', group='═ MA Setting ═' ,inline = 'sma200')
LengthMA2 = input.int(200,'Period', minval=1, group='═ MA Setting
═' , tooltip = 'Act as TP line',inline = 'sma200')
float MA_1 = ta.ema(close, LengthMA)
MA_2 = ta.sma(close, LengthMA2)
///////////////////////// Pivot
Setting //////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
plotPVT = input.bool(defval=true, title='Plot Pivots', group='═
Pivots ═')
pivotLookup = input.int(defval=5, minval=1, maxval=8,title='Pivot
Lookup', group='═ Pivots ═', tooltip='Minimum = 1, Maximum = 8')
pivotsizing = input.int(defval=50, minval=1, maxval=100,title='Pivot
bars back for sizing', group='═ Pivots ═', tooltip='Minimum = 1, Maximum = 100')
plotInThePast = input(false, "Plot When Pivot is Detected" ,group='═
Pivots ═')
pvtTopColor = input.color(defval=color.new(color.lime,10), title='Pivot
Top Color', group='═ Pivots ═', inline='PVT Top Color')
pvtBottomColor = input.color(defval=color.new(color.red,10), title='Pivot
Bottom Color', group='═ Pivots ═', inline='PVT Top Color')
////////////////////////// Linear regression
curve ////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
length = input.int(35, minval=1, group='═ Linear regression curve
═')
smoothing = input.int(30, minval=1, group='═ Linear regression curve
═')
linreg = ta.ema(ta.wma(2*ta.wma(close, length/2)-ta.wma(close,
length), math.round(math.sqrt(length))),smoothing)
//COLOR of Regression Line
hullColor = linreg > linreg[3] ? color.green :linreg < linreg[3] ?
color.red : color.yellow
//////////////////////////////////// High Volume Bars
Setting ///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////
plotHVB = input.bool(defval=true, title='Plot HVB', group='═ High
Volume Bar ═', tooltip='A candle where the average volume is higher than last few
bars.')
hvbBullColor = input.color(defval=color.new(color.green,0),
title='Bullish HVB Color', inline='Set Custom Color', group='═ High Volume Bar ═')
hvbBearColor = input.color(defval=color.new(color.orange,0),
title='Bearish HVB Color', inline='Set Custom Color', group='═ High Volume Bar ═')
hvbEMAPeriod = input.int(defval=6, minval=1, title='Volume EMA Period',
group='═ High Volume Bar ═')
hvbMultiplier = input.float(defval=1.2, title='Volume Multiplier',
minval=1, maxval=100, group='═ High Volume Bar ═')
//////////////////////////////////// Cloud
Setting ///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////
showcloud = input.bool(title="Show Cloud?", defval = true , group='═
Cloud Setting ═')
clhicl = input.color(defval=color.new(color.green,100),
title='Cloud High Color', group='═ Cloud Setting ═' )
cllocl = input.color(defval=color.new(color.red,100), title='Cloud
Low Color', group='═ Cloud Setting ═')
clbgclbull = input.color(defval=color.green, title='Bull Cloud
Color', group='═ Cloud Setting ═')
clbgclbear = input.color(defval=color.red, title='Bear Cloud Color',
group='═ Cloud Setting ═')
clbgclsway = input.color(defval=color.yellow, title='Sideway Cloud
Color', group='═ Cloud Setting ═')
/////////////////////////////// define
trend ////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//cloud
AlphaTrend = 0.0
AlphaTrend := conditype == cond2 ? (rsibb >= 50 ? upT <
nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : upT : downT > nz(AlphaTrend[1]) ?
nz(AlphaTrend[1]) : downT) : supertrend
fastl = ta.ema(close,2)
clohi = math.max(MA_1,linreg,AlphaTrend[2])
clolo = math.min(MA_1,linreg,AlphaTrend[2])
greenzone = close > clohi
redzone = close < clolo
greenzoneB = (close > clohi) and (hullColor == color.green)
redzoneB = (close < clolo) and (hullColor == color.red)
//CloudMA
CloudMA = 0.0
CloudMA := rsibb >= 50 ? clolo < nz(CloudMA[1]) ? nz(CloudMA[1]) :
clolo : clohi > nz(CloudMA[1]) ? nz(CloudMA[1]) : clohi
ATisup = ta.rising(CloudMA,2)
ATisdn = ta.falling(CloudMA,2)
cloudtrend = 0
cloudtrend := ATisup ? 1 : ATisdn ? -1 : cloudtrend[1]
ATcl = color.new(color.yellow,0)
ATcl := ATisup ? clbgclbull : ATisdn ? clbgclbear : CloudMA[1]
== CloudMA ? clbgclsway : ATcl[1]
//plot cloud
kline = plot(CloudMA, color=color.new(ATcl,0), linewidth=2)
zonecl = color.white
zonecl := greenzoneB and (conditype == cond1) ?
color.new(clbgclbull,80) : redzoneB and (conditype == cond1) ?
color.new(clbgclbear,80) : greenzone and (conditype == cond0) ?
color.new(clbgclbull,80) : redzone and (conditype == cond0) ?
color.new(clbgclbear,80) : (conditype == cond2) ? color.new(ATcl,80) : zonecl[1]
main1 = plot(clohi , title="Cloud High" , color=clhicl ,
linewidth=1)
main2 = plot(clolo , title="Cloud low" , color=cllocl ,
linewidth=1)
fill(main1,main2,showcloud ? zonecl : na)
main3 = plot(MA_2 , title="SMA" , color=sma2cl , linewidth=2)
//////////////////// Pivots ////////////////////
hih = ta.pivothigh(high, pivotLookup, pivotLookup)
lol = ta.pivotlow(low , pivotLookup, pivotLookup)
top = ta.valuewhen(hih, high[pivotLookup], 0)
bottom = ta.valuewhen(lol, low [pivotLookup], 0)
pvtop = plot(top, offset=plotInThePast ? 0 : -pivotLookup , linewidth=1, color=(top
!= top[1] ? na : (plotPVT ? pvtTopColor : na)), title="Pivot Top")
pvdow = plot(bottom, offset=plotInThePast ? 0 : -pivotLookup, linewidth=1,
color=(bottom != bottom[1] ? na : (plotPVT ? pvtBottomColor : na)), title="Pivot
Bottom")
////////////////// High Volume Bars //////////////////
volEma = ta.sma(volume, hvbEMAPeriod)
isHighVolume = volume > (hvbMultiplier * volEma)
//Functions
isUp(index) =>
close[index] > open[index]
isDown(index) =>
close[index] < open[index]
barcolor(plotHVB and isUp(0) and isHighVolume ? hvbBullColor : na, title="Bullish
HVB")
barcolor(plotHVB and isDown(0) and isHighVolume ? hvbBearColor : na, title="Bearish
HVB")
////////////////////////////////// Strategy
condition ///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
position_size = strategy.position_size
openoncel = strategy.opentrades == 0 or (position_size <= 0)
openonces = strategy.opentrades == 0 or (position_size >= 0)
exitshort = (conditype == cond2) ? ATisup : (close > clohi) and
(close > top)
exitlong = (conditype == cond2) ? ATisdn : (close < clolo) and
(close < bottom)
//exitshort = (close > clohi) and (close > top)
//exitlong = (close < clolo) and (close < bottom)
//sizing
//pull bottom and top up to 50 bars
highest = ta.highest(top,pivotsizing)
lowest = ta.lowest(bottom,pivotsizing)
lotsbull = math.abs((riskPer ) / (close - lowest))
lotsbear = math.abs((riskPer ) / (highest - close))
// exit order
strategy.close('long2', when=exitlong , comment='StopBuy',
alert_message='Tailing Stop Long!!!')
strategy.close('Short2', when=exitshort , comment='StopSell',
alert_message='Tailing Stop Short!!!')
////condition
LongCondition = openoncel and (close > top) and greenzone and timeCond
LongConditionB = openoncel and (close > top) and greenzoneB and
timeCond
ShortCondition = openonces and (close < bottom) and redzone and timeCond
ShortConditionB = openonces and (close < bottom) and redzoneB and
timeCond
LongConditionC = (cloudtrend > 0) and openoncel and greenzone and
timeCond
ShortConditionC = (cloudtrend < 0) and openonces and redzone and
timeCond
// long
if (uselong == true) and (conditype == cond0)
strategy.entry('long2', strategy.long, when = LongCondition ,qty =lotsbull ,
comment='Buy', alert_message='Long Entry!')
else if (uselong == true) and (conditype == cond1)
strategy.entry('long2', strategy.long, when = LongConditionB ,qty =lotsbull ,
comment='Buy', alert_message='Long Entry!')
else if (uselong == true) and (conditype == cond2)
strategy.entry('long2', strategy.long, when = LongConditionC ,qty =lotsbull ,
comment='Buy', alert_message='Long Entry!')
// Short
if (useshort == true) and (conditype == cond0)
strategy.entry('Short2', strategy.short, when= ShortCondition ,qty =lotsbear,
comment='Sell', alert_message='Short Entry!')
else if (useshort == true) and (conditype == cond1)
strategy.entry('Short2', strategy.short, when= ShortConditionB ,qty =lotsbear,
comment='Sell', alert_message='Short Entry!')
else if (useshort == true) and (conditype == cond2)
strategy.entry('Short2', strategy.short, when= ShortConditionC ,qty =lotsbear,
comment='Sell', alert_message='Short Entry!')
//TP
actionbull = (conditype == cond1) ? (LongConditionB) : (conditype ==
cond0) ? ( LongCondition) : (conditype == cond2) ? (LongConditionC) : false
actionbear = (conditype == cond1) ? (ShortConditionB): (conditype ==
cond0) ? (ShortCondition) : (conditype == cond2) ? (ShortConditionC) : false
changetbull = ta.change(actionbull)
changetbear = ta.change(actionbear)
pullpricebull = ta.barssince(actionbull)
pullpricebear = ta.barssince(actionbear)
buyprice = 0.0
sellprice = 0.0
buyprice := position_size >= 0 ? changetbull ?
close[pullpricebull] : buyprice[1] : 0.0
sellprice := position_size <= 0 ? changetbear ?
close[pullpricebear] : sellprice[1] : 0.0
var float sl_percent_bull = 0.0
var float sl_percent_bear = 0.0
//TP SMA
if usetpsma == true and (buyprice < MA_2[pullpricebull]) and (top <
MA_2[pullpricebull])
strategy.exit('TPl-MA', 'long2', limit=MA_2 , alert_message='TP
Long!',qty_percent=TPper)
if usetpsma == true and (sellprice > MA_2[pullpricebear]) and (bottom >
MA_2[pullpricebull])
strategy.exit('TPs-MA', 'Short2', limit=MA_2 , alert_message='TP
Short!',qty_percent=TPper)
//TP RR
if barstate.isconfirmed
sl_percent_bull := changetbull ? (buyprice - lowest)/buyprice :
(position_size > 0) ? sl_percent_bull[1] :(position_size < 0) ? 0.0 : 0.0
sl_percent_bull
takeProfitBull = buyprice * (1 + (sl_percent_bull*rrPer))
if barstate.isconfirmed
sl_percent_bear := changetbear ? (highest - sellprice) / sellprice :
(position_size < 0) ? sl_percent_bear[1] :(position_size > 0) ? 0.0 : 0.0
sl_percent_bull
takeProfitBear = sellprice * (1 - (sl_percent_bear*rrPer))