// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//max_bars_back=4,
//@version=5
strategy("MultiStrategy-LazyBear", overlay=true,max_bars_back=4,shorttitle="multiStrategy",calc_on_every_tick=false,initial_capital=1000,currency=currency.USD,pyramiding=1,commission_type=strategy.commission.percent,commission_value=0.1,default_qty_type=strategy.percent_of_equity ,default_qty_value=100)
trendIsLong = input.bool(false,title="UpTrend",group = "Trend Type",inline="Trend",confirm=true)
trendIsShort = input.bool(false,title="DownTrend",group = "Trend Type",inline="Trend",confirm=true)
Scalpe = input.bool(false,title="Scalpe Trading",group = "Strategy",inline="Strategy",confirm=true)
Swing = input.bool(false,title="Swing Trading",group = "Strategy",inline="Strategy",confirm=true)
slLongScalpe = input.float(1 ,title="Long Stop Scalpe(%) " ,minval=0.0, step=0.5 ,group = "Scalpe",inline="Scalpe",confirm=true) * 0.01
slShortScalpe = input.float(1 ,title="Short Stop Scalpe (%) " ,minval=0.0, step=0.5 ,group = "Scalpe",inline="Scalpe",confirm=true) * 0.01
tpLongSclape = input.float(2 ,title="Long Take Profit Scalpe (%)" ,minval=0.0, step=0.5 ,group = "Scalpe",inline="Scalpe",confirm=true) * 0.01
tpShortScalpe = input.float(2 ,title="Short Take Profit Scalpe(%)" ,minval=0.0, step=0.5 ,group = "Scalpe",inline="Scalpe",confirm=true) * 0.01
stepOneExitVolScalp = input.float(90,title="Step One Exit in Scalpe (%)",minval=0.0, step=10.0,group = "Scalpe",inline="Scalpe",confirm=true)
slLong = input.float(2 ,title="Long Stop Loss Swing (%) ",minval=0.0, step=0.5 ,group = "Swing",inline="Swing",confirm=true) * 0.01
slShort = input.float(2 ,title="Short Stop Loss Swing (%) ",minval=0.0, step=0.5 ,group = "Swing",inline="Swing",confirm=true) * 0.01
tpLong = input.float(2 ,title="Long Take Profit Swing (%) ",minval=0.0, step=0.5 ,group = "Swing",inline="Swing",confirm=true) * 0.01
tpShort = input.float(2 ,title="Short Take Profit Swing (%)",minval=0.0, step=0.5 ,group = "Swing",inline="Swing",confirm=true) * 0.01
tpLong2 = input.float(5 ,title="Long Take Profit Swing (%) ",minval=0.0, step=0.5 ,group = "Swing",inline="Swing",confirm=true) * 0.01
tpShort2 = input.float(5 ,title="Short Take Profit Swing (%)",minval=0.0, step=0.5 ,group = "Swing",inline="Swing",confirm=true) * 0.01
stepOneExitVolSwing = input.float(50,title="Step One Exit in Swing(%) ",minval=0.0, step=10.0,group = "Swing",inline="Swing",confirm=true)
isTF_Filter = input.bool(true,title="Filter-TF ADX",group = "Bigger TimeFrame",inline="BTF",confirm=true)
biggerTF = input.timeframe('60', "Bigger-Resolution", options=['15','30', '60','120','180','240','360'],group = "Bigger TimeFrame",inline="BTF",confirm=true)
//trade time zone
StartTime = input.time(defval=timestamp('14 May 2022 00:00 +0000'), title='Start Time',group = "Strategy Time Range",confirm=true)
EndTime = input.time(defval=timestamp('30 Jun 2022 23:59 +0000'), title='End Time',group = "Strategy Time Range",confirm=true)
InDateRange = time>=StartTime and time<=EndTime
//bgcolor(color=InDateRange?color.new(color.blue,95):na)
//{util
f_secureSecurity_realtime(_symbol, _res, _src) => request.security(_symbol, _res, _src, lookahead = barmerge.lookahead_on)//,gaps= barmerge.gaps_on)
f_secureSecurity(sym, tf, src) =>
request.security(sym, tf, src[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]
truncate(number, decimals) =>
factor = math.pow(10, decimals)
int(number * factor) / factor
//}Util End
//{half trend start
amplitude = input.int(4,title="Amplitude")
channelDeviation = input.int(2,title="Channel Deviation")
showArrows = input.bool(true,title="Show Arrows")
showChannels = input.bool(false,title="Show Channels")
var int trend = 0
var int nextTrend = 0
var float maxLowPrice = nz(low[1], low)
var float minHighPrice = nz(high[1], high)
var float up = 0.0
var float down = 0.0
float atrHigh = 0.0
float atrLow = 0.0
float arrowUp = na
float arrowDown = na
atr2 = ta.atr(100) / 2
dev = channelDeviation * atr2
highPrice = high[math.abs(ta.highestbars(amplitude))]
lowPrice = low[math.abs(ta.lowestbars(amplitude))]
highma = ta.sma(high, amplitude)
lowma = ta.sma(low, amplitude)
if nextTrend == 1
maxLowPrice := math.max(lowPrice, maxLowPrice)
if highma < maxLowPrice and close < nz(low[1], low)
trend := 1
nextTrend := 0
minHighPrice := highPrice
else
minHighPrice := math.min(highPrice, minHighPrice)
if lowma > minHighPrice and close > nz(high[1], high)
trend := 0
nextTrend := 1
maxLowPrice := lowPrice
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 : math.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 : math.min(minHighPrice, down[1])
atrHigh := down + dev
atrLow := down - dev
ht = trend == 0 ? up : down
var color buyColor = color.blue
var color sellColor = color.red
htColor = trend == 0 ? buyColor : sellColor
htPlot = plot(ht, title="HalfTrend", linewidth=2, color=htColor)
atrHighPlot = plot(showChannels ? atrHigh : na, title="ATR High", style=plot.style_circles, color=sellColor)
atrLowPlot = plot(showChannels ? atrLow : na, title="ATR Low", style=plot.style_circles, color=buyColor)
fill(htPlot, atrHighPlot, title="ATR High Ribbon", color=sellColor)
fill(htPlot, atrLowPlot, title="ATR Low Ribbon", color=buyColor)
halfTrendBuySignal = not na(arrowUp) and (trend == 0 and trend[1] == 1)
halftTrendSellSignal = not na(arrowDown) and (trend == 1 and trend[1] == 0)
plotshape(showArrows and halfTrendBuySignal ? atrLow : na, title="Arrow Up", style=shape.triangleup, location=location.absolute, size=size.tiny, color=buyColor)
plotshape(showArrows and halftTrendSellSignal ? atrHigh : na, title="Arrow Down", style=shape.triangledown, location=location.absolute, size=size.tiny, color=sellColor)
//}half trend end
//ADX{
ADX_Length = input.int(14, title="ADX Length", minval=1,confirm=true,group = "ADX")
ADX_TH = input.int(20, title="ADX TH", minval=1,confirm=true,group = "ADX")
get_DIPlus() =>
TrueRange = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? math.max(high-nz(high[1]), 0): 0
SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/ADX_Length) + TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/ADX_Length) + DirectionalMovementPlus
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
get_DIMinus() =>
TrueRange = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? math.max(nz(low[1])-low, 0): 0
SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/ADX_Length) + TrueRange
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/ADX_Length) + DirectionalMovementMinus
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
get_ADX() =>
// TrueRange = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))
// DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? math.max(high-nz(high[1]), 0): 0
// SmoothedTrueRange = 0.0
// SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/ADX_Length) + TrueRange
// SmoothedDirectionalMovementPlus = 0.0
// SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/ADX_Length) + DirectionalMovementPlus
DIPlus = get_DIPlus()
DIMinus = get_DIMinus()
DX = math.abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = ta.sma(DX, ADX_Length)
biggerTF_ADX = f_secureSecurity(syminfo.tickerid,biggerTF,get_ADX())
biggerTF_DIPlus = f_secureSecurity(syminfo.tickerid,biggerTF,get_DIPlus())
biggerTF_DIMinus = f_secureSecurity(syminfo.tickerid,biggerTF,get_DIMinus())
currentTF_ADX = get_ADX()
currentTF_DIPlus = get_DIPlus()
currentTF_DIMinux = get_DIMinus()
// biggerTF_ADX_Realtime = f_secureSecurity_realtime(syminfo.tickerid,biggerTF,get_ADX())
// biggerTF_DIPlus_Realtime = f_secureSecurity_realtime(syminfo.tickerid,biggerTF,get_DIPlus())
// biggerTF_DIMinus_Realtime = f_secureSecurity_realtime(syminfo.tickerid,biggerTF,get_DIMinus())
//}ADX End
//stoch bigger time frame
periodK = input.int(14, title="%K Length", minval=1,confirm=true,group = "Options")
smoothK = input.int(3, title="%K Smoothing", minval=1,confirm=true,group = "Options")
periodD = input.int(3, title="%D Smoothing", minval=1,confirm=true,group = "Options")
upperBand1 = input.int(80,title="Upper-Band1",confirm=true,group = "Options")
lowerBand1 = input.int(20,title="Lower-Band1",confirm=true,group = "Options")
upperBand2 = input.int(180,title="Upper-Band2",confirm=true,group = "Options")
lowerBand2 = input.int(120,title="Lower-Band2",confirm=true,group = "Options")
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
biggerTFk = f_secureSecurity(syminfo.tickerid,biggerTF,k)
biggerTFd = f_secureSecurity(syminfo.tickerid,biggerTF,d)
// plot(biggerTFk, title="%K1", color=#2962FF)
// plot(biggerTFd, title="%D1", color=#FF6D00)
// h0 = hline(80, "Upper Band", color=#787B86)
// h1 = hline(20, "Lower Band", color=#787B86)
// plot(k+100, title="%K2", color=color.green)
// // plot(d+100, title="%D2", color=color.red)
// h01 = hline(80+100, "Upper Band", color=#787B86)
// h11 = hline(20+100, "Lower Band", color=#787B86)
CrossBars = input.int(1,minval=0,title="Number of Bars to Confirm Cross")
CrossOverConfirm(x,y) =>
ta.barssince(ta.crossover(x,y)) == CrossBars and x>=y
CrossUnderConfirm(x,y) =>
ta.barssince(ta.crossunder(x,y)) == CrossBars and x<=y
//filter Time Frame
if isTF_Filter
trendIsLong := false
trendIsShort := false
if biggerTF_ADX>20 and biggerTF_DIPlus>biggerTF_DIMinus //and biggerTF_ADX_Realtime>20 and biggerTF_DIPlus_Realtime>biggerTF_DIMinus_Realtime
trendIsLong := true
if biggerTF_ADX>20 and biggerTF_DIPlus<biggerTF_DIMinus //and biggerTF_ADX_Realtime>20 and biggerTF_DIPlus_Realtime<biggerTF_DIMinus_Realtime
trendIsShort := true
//bullish cross in higher time frame
if (ta.crossover(biggerTFk,biggerTFd) and biggerTFk<upperBand1 and biggerTFk>lowerBand1) or (biggerTFk>biggerTFd and biggerTFk[1]<lowerBand1 and biggerTFd[1]<lowerBand1 and biggerTFk>lowerBand1)//biggerTFk[30]<biggerTFd[30] and biggerTFk>biggerTFd// and biggerTFk< upperBand1 and biggerTFk> lowerBand1
line.new(bar_index, close, bar_index, open, extend = extend.both,color=color.green,style=line.style_dotted)
//bearesh cross in higher time frame
if (ta.crossunder(biggerTFk,biggerTFd) and biggerTFk<upperBand1 and biggerTFk>lowerBand1) or (biggerTFk<biggerTFd and biggerTFk[1]>upperBand1 and biggerTFd[1]>upperBand1 and biggerTFk<upperBand1)//biggerTFk[30]>biggerTFd[30] and biggerTFk<biggerTFd//ta.crossunder(k,d) //and biggerTFk> lowerBand1// and biggerTFk< upperBand1
line.new(bar_index, close, bar_index, open, extend = extend.both,color=color.red,style=line.style_dotted)
momentumConditionandLong = false
momentumConditionandShort = false
//bullish cross in current time frame
if biggerTFk>biggerTFd and biggerTFk<upperBand1 and biggerTFk>lowerBand1 and biggerTFd<upperBand1 and biggerTFd>lowerBand1 and ((k[1]<d[1] and k>d) or (k>d and ((k[1]<lowerBand1 and d[1]<lowerBand1) or(k[2]<lowerBand1 and d[2]<lowerBand1)) )) and k < upperBand1 and k > lowerBand1 and d>lowerBand1 and d<upperBand1
//biggerBarIndex = f_secureSecurity(syminfo.tickerid,biggerTF,bar_index)
line.new(bar_index, close-500, bar_index, open+500,color=color.green,style=line.style_dashed)
momentumConditionandLong := true
//bearesh cross in current time frame
if biggerTFk<biggerTFd and biggerTFk>lowerBand1 and biggerTFk<upperBand1 and biggerTFd<upperBand1 and biggerTFd>lowerBand1 and ((k[1]>d[1] and k < d) or (k<d and ((k[1]>upperBand1 and d[1]>upperBand1) or (k[2]>upperBand1 and d[2]>upperBand1)) )) and k > lowerBand1 and k < upperBand1 and d>lowerBand1 and d<upperBand1
line.new(bar_index, close-500, bar_index, open+500,color=color.red,style=line.style_dashed)
momentumConditionandShort := true
bgcolor(color=InDateRange and biggerTFk>biggerTFd and biggerTFk>lowerBand1 and biggerTFk<upperBand1?color.new(color.green,95):InDateRange and biggerTFk<biggerTFd and biggerTFk<upperBand1 and biggerTFk>lowerBand1?color.new(color.red,95):color.new(color.blue,90))
//ema
//ema 100 and ema 200
lenEmaNear = input.int(100, minval=1, title="Near Length",confirm=true,group = "Options",inline="ema")
lenFarNear = input.int(200, minval=1, title="Far Length",confirm=true,group = "Options",inline="ema")
src = input.source(close, title="Source",group = "Options")
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500,confirm=true,group = "Options")
outNearEma = ta.ema(src, lenEmaNear)
outFarEma = ta.ema(src, lenFarNear)
plot(outNearEma, title="EMA-Fast", color=color.white, offset=offset)
plot(outFarEma, title="EMA-Slow", color=color.blue, offset=offset)
scalpeStrategy = false
swingStrategy = false
if strategy.position_size != 0
scalpeStrategy := scalpeStrategy[1]
swingStrategy := swingStrategy[1]
PK_X_PD = 0
if biggerTF_ADX<20
if strategy.position_size == 0
scalpeStrategy := true
PK_X_PD :=
//long (30 M Trend is positive) (ema 100 slope positive)
//(momentumConditionandLong or (momentumConditionandLong[1] and biggerTFk[1]>biggerTFd[1] and biggerTFk>biggerTFd) or (momentumConditionandLong[2] and biggerTFk[2]>biggerTFd[2] and biggerTFk>biggerTFd) or (momentumConditionandLong[3] and biggerTFk[3]>biggerTFd[3] and biggerTFk>biggerTFd)) and (high>close[1] and high>close[2]) and (open==low)?1
(halfTrendBuySignal or halfTrendBuySignal[1] or halfTrendBuySignal[2]) and currentTF_ADX>20 and currentTF_ADX>currentTF_ADX[1] and currentTF_DIPlus>currentTF_DIMinux?1
//short (30 M Trend is negetive) (ema 100 slope positive)
//:(momentumConditionandShort or (momentumConditionandShort[1] and biggerTFk[1]<biggerTFd[1] and biggerTFk<biggerTFd) or (momentumConditionandShort[2] and biggerTFk[2]<biggerTFd[2] and biggerTFk<biggerTFd) or (momentumConditionandShort[3] and biggerTFk[3]<biggerTFd[3] and biggerTFk<biggerTFd)) and (low<close[1] and low<close[2]) and (open==high) ?-1
:(halftTrendSellSignal or halftTrendSellSignal[1] or halftTrendSellSignal[2]) and currentTF_ADX>20 and currentTF_ADX>currentTF_ADX[1] and currentTF_DIPlus<currentTF_DIMinux?-1
:0
else if biggerTF_ADX>=20
if strategy.position_size == 0
swingStrategy := true
PK_X_PD :=
//long (30 M Trend is positive) (ema 100 slope positive)
(momentumConditionandLong or (momentumConditionandLong[1] and biggerTFk[1]>biggerTFd[1] and biggerTFk>biggerTFd) or (momentumConditionandLong[2] and biggerTFk[2]>biggerTFd[2] and biggerTFk>biggerTFd) or (momentumConditionandLong[3] and biggerTFk[3]>biggerTFd[3] and biggerTFk>biggerTFd)) and (high>close[1] and high>close[2]) and (open==low)?1
//short (30 M Trend is negetive) (ema 100 slope positive)
:(momentumConditionandShort or (momentumConditionandShort[1] and biggerTFk[1]<biggerTFd[1] and biggerTFk<biggerTFd) or (momentumConditionandShort[2] and biggerTFk[2]<biggerTFd[2] and biggerTFk<biggerTFd) or (momentumConditionandShort[3] and biggerTFk[3]<biggerTFd[3] and biggerTFk<biggerTFd)) and (low<close[1] and low<close[2]) and (open==high)?-1
:0
PK_X_PD_Long = PK_X_PD>0
PK_X_PD_Short = PK_X_PD<0
if(InDateRange)
//strategy long
if swingStrategy and strategy.position_size == 0 and Swing
strategy.entry('buy',strategy.long,when=PK_X_PD_Long and strategy.position_size ==0 and trendIsLong)
//strategy short
strategy.entry('short',strategy.short,when=PK_X_PD_Short and strategy.position_size ==0 and trendIsShort)
else if scalpeStrategy and strategy.position_size == 0 and Scalpe
strategy.entry('buy',strategy.long,when=PK_X_PD_Long and strategy.position_size ==0 )
//strategy short
strategy.entry('short',strategy.short,when=PK_X_PD_Short and strategy.position_size ==0 )
inTrade = strategy.position_size //if <0 trade position is short and if >0 trade postion is long and if = 0 no postion
stopPrice = 0.0
profitPrice = 0.0
longProfitPrice = 0.0
shortProfitPrice = 0.0
changeStopPrice = false
if strategy.position_size < 0 and scalpeStrategy
shortProfitPrice := strategy.position_avg_price * (1-tpShortScalpe)
stopPrice := if (strategy.position_size < 0)
stopValue = strategy.position_avg_price * (1 + slShortScalpe)
if stopPrice[1] !=0 and low < stopPrice[1] * (1-(slShortScalpe* 2))
changeStopPrice := true
stopPrice[1] * (1-slShortScalpe)
else if stopPrice[1] > 0
math.min(stopValue,stopPrice[1])
else
stopValue
else
0
else if strategy.position_size > 0 and scalpeStrategy
longProfitPrice := strategy.position_avg_price * (1+tpLongSclape)
stopPrice := if (strategy.position_size > 0)
stopValue = strategy.position_avg_price * (1 - slLongScalpe)
if stopPrice[1] !=0 and high > stopPrice[1] * (1+(slLongScalpe* 2))
changeStopPrice := true
stopPrice[1] * (1+slLongScalpe)
else if stopPrice[1] > 0
math.max(stopValue,stopPrice[1])
else
stopValue
else
0
//alert for change stoploss{
if changeStopPrice
alertsyntax_change_stop = '{' + '\"method\":\"changeStop\",\"changeStopPrice\":\"' + str.tostring(stopPrice) +'\",\"market\":\"' + syminfo.ticker + '\"}'
alert(message=alertsyntax_change_stop, freq=alert.freq_once_per_bar_close)
//}
//alert for close position if change phase in bigger timeframe{
if biggerTF_ADX>20 and biggerTF_DIPlus<biggerTF_DIMinus and inTrade>0 //change bigger timeframe phase for long position
alertsyntax_exit_long_position = '{' + '\"method\":\"changePhase\",\"changeStopPrice\":\"' + str.tostring(close) +'\",\"market\":\"' + syminfo.ticker + '\"}'
alert(message=alertsyntax_exit_long_position, freq=alert.freq_once_per_bar_close)
if biggerTF_ADX>20 and biggerTF_DIPlus>biggerTF_DIMinus and inTrade<0 //change bigger timeframe phase for short position
alertsyntax_exit_short_position = '{' + '\"method\":\"changePhase\",\"changeStopPrice\":\"' + str.tostring(close) +'\",\"market\":\"' + syminfo.ticker + '\"}'
alert(message=alertsyntax_exit_short_position, freq=alert.freq_once_per_bar_close)
//}
if swingStrategy
strategy.exit("TP1Short",from_entry="short", qty_percent=stepOneExitVolSwing, limit = strategy.position_avg_price * (1 - tpShort), stop =stopPrice != 0? stopPrice:strategy.position_avg_price * (1 + slShort))
//strategy.exit("TP3Short",from_entry="short", qty_percent=25, limit = strategy.position_avg_price * (1 - tpShort2), stop =stopPrice != 0? stopPrice:strategy.position_avg_price * (1 + slShort))
strategy.exit("TP2Short",from_entry="short",stop=stopPrice != 0? stopPrice:strategy.position_avg_price * (1 + slShort))
strategy.exit("TP1Buy",from_entry="buy", qty_percent=stepOneExitVolSwing, limit = strategy.position_avg_price * (1 + tpLong), stop = stopPrice!=0?stopPrice:strategy.position_avg_price * (1 - slLong))
//strategy.exit("TP3Buy",from_entry="buy", qty_percent=25, limit = strategy.position_avg_price * (1 + tpLong2), stop = stopPrice!=0?stopPrice:strategy.position_avg_price * (1 - slLong))
strategy.exit("TP2Buy",from_entry="buy",stop=stopPrice!=0?stopPrice:strategy.position_avg_price * (1 - slLong))
strategy.close("buy",when=biggerTF_ADX>20 and biggerTF_DIPlus<biggerTF_DIMinus)
strategy.close("short",when=biggerTF_ADX>20 and biggerTF_DIPlus>biggerTF_DIMinus)
else if scalpeStrategy
strategy.exit("TP1Short",from_entry="short", qty_percent=stepOneExitVolScalp, limit = strategy.position_avg_price * (1 - tpShortScalpe), stop =stopPrice != 0? stopPrice:strategy.position_avg_price * (1 + slShortScalpe))
strategy.exit("TP2Short",from_entry="short",stop=stopPrice != 0? stopPrice:strategy.position_avg_price * (1 + slShortScalpe))
strategy.exit("TP1Buy",from_entry="buy", qty_percent=stepOneExitVolScalp, limit = strategy.position_avg_price * (1 + tpLongSclape), stop = stopPrice!=0?stopPrice:strategy.position_avg_price * (1 - slLongScalpe))
strategy.exit("TP2Buy",from_entry="buy",stop=stopPrice!=0?stopPrice:strategy.position_avg_price * (1 - slLongScalpe))
// strategy.close("buy",when=biggerTFk<biggerTFd and biggerTFk<upperBand1)
// strategy.close("short",when=biggerTFk>biggerTFd and biggerTFk>lowerBand1)
//plot rectongle on chart when position condition is true
plotshape(PK_X_PD_Long and inTrade==0,title="Signal Long",style=shape.triangleup,color=color.green,location=location.bottom,size=size.small)
plotshape(PK_X_PD_Short and inTrade==0,title="Signal Short",style=shape.triangledown,color=color.red,location=location.top,size=size.small)
//alert for call robot webhook
if PK_X_PD_Long and trendIsLong and strategy.position_size==0
enteryPriceCalculated = (close + open)/2
//alertsyntax_golong = '{' + '\"price\":\"' + str.tostring(strategy.position_avg_price) + '\",\"stoploss\":\"' + str.tostring(strategy.position_avg_price * slLong) + '\",\"takeprofit\":\"' + str.tostring(strategy.position_avg_price * tpLong) + '\",\"side\":2' + ',\"market\":\"' + syminfo.ticker + '\"}'
alertsyntax_golong = '{' + '\"price\":\"' + str.tostring(enteryPriceCalculated) + '\",\"stoploss\":\"' + str.tostring(enteryPriceCalculated * (1-slLong)) + '\",\"takeprofit\":\"' + str.tostring(enteryPriceCalculated * (1+tpLong2)) + '\",\"riskfree\":\"' + str.tostring(enteryPriceCalculated * (1+slLong)) + '\",\"takeprofit1\":\"' + str.tostring(enteryPriceCalculated * (1+tpLong)) + '\",\"takeprofit1\":\"' + str.tostring(enteryPriceCalculated * (1+tpLong)) + '\",\"side\":2' + ',\"market\":\"' + syminfo.ticker + '\"}'
//alertsyntax_golong = '{' + '\"price\":\"' + str.tostring(strategy.position_avg_price) + '\",\"stoploss\":\"' + str.tostring(strategy.position_avg_price * (1-slLong)) + '\",\"takeprofit\":\"' + str.tostring(strategy.position_avg_price * (1+tpLong2)) + '\",\"riskfree\":\"' + str.tostring(strategy.position_avg_price * (1+slLong)) + '\",\"takeprofit1\":\"' + str.tostring(strategy.position_avg_price * (1+tpLong)) + '\",\"takeprofit1\":\"' + str.tostring(strategy.position_avg_price * (1+tpLong)) + '\",\"side\":2' + ',\"market\":\"' + syminfo.ticker + '\"}'
alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)
if PK_X_PD_Short and trendIsShort and strategy.position_size==0
enteryPriceCalculated = (close + open)/2
//alertsyntax_goshort = '{' + '\"price\":\"' + str.tostring(strategy.position_avg_price) + '\",\"stoploss\":\"' + str.tostring(strategy.position_avg_price * slShort) + '\",\"takeprofit\":\"' + str.tostring(strategy.position_avg_price * tpShort) + '\",\"side\":1' + ',\"market\":\"' + syminfo.ticker + '\"}'
alertsyntax_goshort = '{' + '\"price\":\"' + str.tostring(enteryPriceCalculated) + '\",\"stoploss\":\"' + str.tostring(enteryPriceCalculated * (1+slShort)) + '\",\"takeprofit\":\"' + str.tostring(enteryPriceCalculated * (1-tpShort2)) + '\",\"riskfree\":\"' + str.tostring(enteryPriceCalculated * (1-slShort)) + '\",\"takeprofit1\":\"' + str.tostring(enteryPriceCalculated * (1-tpShort)) + '\",\"side\":1' + ',\"market\":\"' + syminfo.ticker + '\"}'
//alertsyntax_goshort = '{' + '\"price\":\"' + str.tostring(strategy.position_avg_price) + '\",\"stoploss\":\"' + str.tostring(strategy.position_avg_price * (1+slShort)) + '\",\"takeprofit\":\"' + str.tostring(strategy.position_avg_price * (1-tpShort2)) + '\",\"riskfree\":\"' + str.tostring(strategy.position_avg_price * (1-slShort)) + '\",\"takeprofit1\":\"' + str.tostring(strategy.position_avg_price * (1-tpShort)) + '\",\"side\":1' + ',\"market\":\"' + syminfo.ticker + '\"}'
alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)
//for sell and buy show risk/reward swing and scalpe strategy
entry = plot(inTrade!=0? strategy.position_avg_price :na,color=color.purple,style=plot.style_circles,title="entry",trackprice=false)
//profit1 = plot(inTrade<0 ? strategy.position_avg_price * (1-tpShort):strategy.position_avg_price * (1+tpLong),color=color.green,style=plot.style_circles,title="TP1",trackprice=false)
profit = plot(inTrade !=0 and swingStrategy?inTrade<0? close<strategy.position_avg_price * (1-tpShort2)?close:strategy.position_avg_price * (1-tpShort2):inTrade>0?close>strategy.position_avg_price * (1+tpLong2)?close:strategy.position_avg_price * (1+tpLong2):na:inTrade<0 and scalpeStrategy?strategy.position_avg_price * (1-tpShortScalpe):inTrade>0 and scalpeStrategy?strategy.position_avg_price * (1+tpLongSclape):na,color=color.green,style=plot.style_circles,title="TP",trackprice=false)
//riskFree = plot(inTrade<0 ? strategy.position_avg_price * (1-slShort):strategy.position_avg_price * (1+slLong),color=color.green,style=plot.style_circles,title="Risk Free",trackprice=false)
stop = plot(inTrade!=0 and swingStrategy? inTrade<0?strategy.position_avg_price * (1+slShort):inTrade>0?strategy.position_avg_price * (1-slLong):na:inTrade<0 and scalpeStrategy?strategy.position_avg_price * (1+slShortScalpe):inTrade>0 and scalpeStrategy?strategy.position_avg_price * (1-slLongScalpe):0,color=color.red,style=plot.style_circles,title="SL",trackprice=false)
stop2Scalpe = plot(inTrade<0?stopPrice:inTrade>0?stopPrice:na,color=color.yellow,style=plot.style_circles,title="SL2Scalpe",trackprice=false)
fill(entry,profit,title="Reward",color= color.new(color.green,65))
fill(entry,stop,title="Risk",color= color.new(color.red,65))
tableColumn = 2
tableRow = 16
var table panel = table.new(position.top_right, tableColumn, tableRow)
table.cell(panel, 0, 0, "Hello Sassiz", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 0, "Lazy Bear", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 0, 1, "Net Profit", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 1,str.tostring(truncate(strategy.netprofit,2)), bgcolor=color.new(color.black,65), text_color=strategy.netprofit>0?color.green:color.red)
table.cell(panel, 0, 2, "Winning Trade", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 2,str.tostring(strategy.wintrades), bgcolor=color.new(color.black,65), text_color=color.green)
table.cell(panel, 0, 3, "Loss Trade", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 3,str.tostring(strategy.losstrades), bgcolor=color.new(color.black,65), text_color=color.red)
table.cell(panel, 0, 4, "Max Down", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 4,str.tostring(truncate(strategy.max_drawdown,2)), bgcolor=color.new(color.black,65), text_color=color.red)
table.cell(panel, 0, 5, "R&R", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 5,str.tostring(tpLong2/slLong), bgcolor=color.new(color.black,65), text_color=color.red)
table.cell(panel, 0, 6, "BT-K", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 6,str.tostring(truncate(biggerTFk,2)), bgcolor=color.new(color.black,65), text_color=color.blue)
table.cell(panel, 0, 7, "BT-D", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 7,str.tostring(truncate(biggerTFd,2)), bgcolor=color.new(color.black,65), text_color=color.orange)
table.cell(panel, 0, 8, "BT-ADX", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 8,str.tostring(truncate(biggerTF_ADX,2)), bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 0, 9, "BT-DI+", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 9,str.tostring(truncate(biggerTF_DIPlus,2)), bgcolor=color.new(color.black,65), text_color=color.green)
table.cell(panel, 0, 10, "BT-DI-", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 10,str.tostring(truncate(biggerTF_DIMinus,2)), bgcolor=color.new(color.black,65), text_color=color.red)
table.cell(panel, 0, 11, "Up Trend", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 11,trendIsLong?"Enable":"Disable" , bgcolor=color.new(color.black,65), text_color=trendIsLong?color.green:color.red)
table.cell(panel, 0, 12, "Down Trend", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 12,trendIsShort?"Enable":"Disable" , bgcolor=color.new(color.black,65), text_color=trendIsShort?color.green:color.red)
table.cell(panel, 0, 13, "Day", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 13,str.tostring(dayofweek), bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 0, 14, "Scalpe", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 14,scalpeStrategy?"Enable":"Disable", bgcolor=color.new(color.black,65),text_color=scalpeStrategy?color.green:color.red)
table.cell(panel, 0, 15, "Swing", bgcolor=color.new(color.black,65), text_color=color.white)
table.cell(panel, 1, 15,swingStrategy?"Enable":"Disable", bgcolor=color.new(color.black,65),text_color=swingStrategy?color.green:color.red)
Overview
MultiStrategy-LazyBear filters trades with a higher-timeframe ADX reading, stochastic bands, and a price channel defined by amplitude and deviation. Long or short direction is selected by trend toggles, and orders are limited to a chosen date range. Percentage stop-loss and take-profit levels differ for scalp and swing, with a partial first exit before the remaining position. Arrows and channels can be shown on the price chart. Higher-timeframe data is requested with lookahead, so historical signals can use future bars.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
UpTrend
bool
false
trendIsLong
DownTrend
bool
false
trendIsShort
Scalpe Trading
bool
false
Scalpe
Swing Trading
bool
false
Swing
Long Stop Scalpe(%)
float
1
slLongScalpe
Short Stop Scalpe (%)
float
1
slShortScalpe
Long Take Profit Scalpe (%)
float
2
tpLongSclape
Short Take Profit Scalpe(%)
float
2
tpShortScalpe
Step One Exit in Scalpe (%)
float
90
stepOneExitVolScalp
Long Stop Loss Swing (%)
float
2
slLong
Short Stop Loss Swing (%)
float
2
slShort
Long Take Profit Swing (%)
float
2
tpLong
Show all 38 settings
Setting
Type
Default
Variable
Short Take Profit Swing (%)
float
2
tpShort
Long Take Profit Swing (%)
float
5
tpLong2
Short Take Profit Swing (%)
float
5
tpShort2
Step One Exit in Swing(%)
float
50
stepOneExitVolSwing
Filter-TF ADX
bool
true
isTF_Filter
Bigger-Resolution
timeframe
60
biggerTF
Start Time
time
timestamp('14 May 2022 00:00 +0000')
StartTime
End Time
time
timestamp('30 Jun 2022 23:59 +0000')
EndTime
Amplitude
int
4
amplitude
Channel Deviation
int
2
channelDeviation
Show Arrows
bool
true
showArrows
Show Channels
bool
false
showChannels
ADX Length
int
14
ADX_Length
ADX TH
int
20
ADX_TH
%K Length
int
14
periodK
%K Smoothing
int
3
smoothK
%D Smoothing
int
3
periodD
Upper-Band1
int
80
upperBand1
Lower-Band1
int
20
lowerBand1
Upper-Band2
int
180
upperBand2
Lower-Band2
int
120
lowerBand2
Number of Bars to Confirm Cross
int
1
CrossBars
Near Length
int
100
lenEmaNear
Far Length
int
200
lenFarNear
Source
source
close
src
Offset
int
0
offset
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This strategy generates trading signals on the 5-minute price chart using Williams Fractals for trend reversals, combined with EMA fast and slow trend filters and optional RSI confirmation. Long entries trigger on bullish fractals aligned with rising EMA and R
This strategy trades EUR/USD on the price chart using a fast and slow exponential moving average crossover filtered by RSI. It enters long when the fast EMA crosses above the slow EMA while RSI is above 50 and below the overbought level, and enters short on th
LuxAlgo Hybrid Gold Scalper is a price-chart strategy aimed at gold. It stacks a fast, slow, trend and 200-period bias EMA to mark trend direction, then filters strength with RSI, ADX and an intraday VWAP. Swing highs and lows are marked from pivot length. Set
This trend-following scalping strategy combines a moving average trend filter with the Absolute Strength Histogram indicator. It opens long positions when price is above a selectable baseline moving average and the histogram signals bullish momentum, and short
This long-only strategy calculates three exponential moving averages with lengths of 50, 100, and 150 periods, plotting them directly on the price chart. It also calculates a 14-period RSI and MACD. The strategy opens long positions when the moving averages al
This strategy draws on the price chart and combines a momentum zigzag, a custom QQE built from RSI, ADX directional strength, an SSL filter, and a coefficient-of-variation weighted average. Box period, deviation, and threshold inputs set the box filter, while