binance-futures-strategy-candle-bar.txt
Copy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © binancash
//@version=5
strategy("Binancash - Candle Strategy Futures on Binance", overlay=true, default_qty_value=200, initial_capital=1)
// config profit stoploss start
stopPer = input.float(1, title='Stop Loss %') / 100
takePer = input.float(15, title='Take Profit %') / 100
longStop = strategy.position_avg_price * (1 - stopPer)
shortStop = strategy.position_avg_price * (1 + stopPer)
shortTake = strategy.position_avg_price * (1 - takePer)
longTake = strategy.position_avg_price * (1 + takePer)
// // config profit stoploss end
//vwap start
point_lb = 5
point_rb = 5
point_ph = ta.pivothigh(point_lb, point_rb)
point_pl = ta.pivotlow(point_lb, point_rb)
var float running_ph = na
var float running_pl = na
running_ph := running_ph
running_pl := running_pl
if point_ph
running_ph := point_ph
if point_pl
running_pl := point_pl
plot(running_ph, title = 'R', style = plot.style_circles, linewidth = 1,color=color.red, offset = -point_rb)
plot(running_ph, title = 'R', style = plot.style_circles, linewidth = 1,color=color.red, offset = 0)
plot(running_pl, title = 'S', style = plot.style_circles, linewidth = 1,color=color.blue,offset = -point_rb)
plot(running_pl, title = 'S', style = plot.style_circles, linewidth = 1,color=color.blue, offset = 0)
var bool is_strong_buy = false
var bool is_strong_sell = false
if running_ph and ta.crossover(close, running_ph) and barstate.isconfirmed
is_strong_buy := true
is_strong_sell := false
if running_pl and ta.crossunder(close, running_ph) and barstate.isconfirmed
is_strong_buy := false
if running_pl and ta.crossunder(close, running_pl) and barstate.isconfirmed
is_strong_sell := true
is_strong_buy := false
if running_pl and ta.crossover(close, running_pl) and barstate.isconfirmed
is_strong_sell := false
//vwap end
// logic buy sell improve start
src = close
di = (6 - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (0.4 * 0.4 + 0.4 * 0.4 * 0.4)
c4 = -3.0 * (2.0 * 0.4 * 0.4 + 0.4 + 0.4 * 0.4 * 0.4)
c5 = 3.0 * 0.4 + 1.0 + 0.4 * 0.4 * 0.4 + 3.0 * 0.4 * 0.4
var float i1 = na
var float i2 = na
var float i3 = na
var float i4 = na
var float i5 = na
var float i6 = na
i1 := c1 * src + c2 * nz(i1[1])
i2 := c1 * i1 + c2 * nz(i2[1])
i3 := c1 * i2 + c2 * nz(i3[1])
i4 := c1 * i3 + c2 * nz(i4[1])
i5 := c1 * i4 + c2 * nz(i5[1])
i6 := c1 * i5 + c2 * nz(i6[1])
Cto = -0.4 * 0.4 * 0.4 * i6 + c3 * i5 + c4 * i4 + c5 * i3
//bfrC = Cto > nz(Cto[1]) ? raise : Cto < nz(Cto[1]) ? fall : na
plot(Cto, title='Trend', linewidth=2, style=plot.style_line, color=color.gray, editable=false)
ema3 = ta.ema(close, 3)
var bool is_cross_up = false
var bool is_cross_down = false
if ta.crossover(ema3, Cto)
is_cross_up := true
is_cross_down := false
if ta.crossunder(ema3, Cto)
is_cross_down := true
is_cross_up := false
//condition Long & Short
long = (close > Cto and close[1] < Cto[1] and close > close[1] or close[1] > Cto[1] and close > close[1] and close [1] < close[2] and close > ema3) and barstate.isconfirmed? true : false
profit_long = close < close[1] and low < ema3 and close[1] > ema3[1] and close[2] > ema3[2] and barstate.isconfirmed
short = (close < Cto and close[1] > Cto[1] and close < close[1] or close[1] < Cto[1] and close < close[1] and close [1] > close[2] and close < ema3) and barstate.isconfirmed? true : false
profit_short = close > close[1] and high > ema3 and close[1] < ema3[1] and close[2] < ema3[2] and barstate.isconfirmed
var int trend = 0
if long
trend := 1
if short
trend := -1
if profit_long
trend := 2
if profit_short
trend := -2
// logic buy sell improvate end
rsi = ta.rsi(close, 3)
ema48 = ta.wma(close, 48)
ema11 = ta.wma(close, 11)
ema200 = ta.wma(close, 200)
close10 = request.security(symbol=syminfo.tickerid, timeframe="12", expression=close, lookahead=barmerge.lookahead_on)
wma10_11 = ta.wma(close, 4)
wma_10_11 = request.security(symbol=syminfo.tickerid, timeframe="12", expression=wma10_11, lookahead=barmerge.lookahead_on)
wma10_48 = ta.wma(close, 9)
wma_10_48 = request.security(symbol=syminfo.tickerid, timeframe="12", expression=wma10_48, lookahead=barmerge.lookahead_on)
var bool cross_up_wma_10 = false
var bool cross_down_wma_10 = false
if ta.crossover(wma_10_11, wma_10_48) and barstate.isconfirmed
cross_up_wma_10 := true
cross_down_wma_10 := false
if ta.crossunder(wma_10_11, wma_10_48) and barstate.isconfirmed
cross_up_wma_10 := false
cross_down_wma_10 := true
up10m = false
if close10 > wma_10_11
up10m := true
close10_2 = request.security(symbol=syminfo.tickerid, timeframe="10", expression=close, lookahead=barmerge.lookahead_on)
low1d = request.security(symbol=syminfo.tickerid, timeframe="D", expression=low, lookahead=barmerge.lookahead_on)
wma10_11_2 = ta.wma(close, 11)
wma_10_11_2 = request.security(symbol=syminfo.tickerid, timeframe="10", expression=wma10_11, lookahead=barmerge.lookahead_on)
//plot(wma_10_11, title="WMA10_11", color=color.blue)
wma10_48_2 = ta.wma(close, 48)
wma_10_48_2 = request.security(symbol=syminfo.tickerid, timeframe="10", expression=wma10_48, lookahead=barmerge.lookahead_on)
//plot(wma_10_48, title="WMA10_48", color=color.purple)
up10m_2 = false
down10m_2 = false
if close10_2 > wma_10_11_2
up10m_2 := true
if close10_2 < wma_10_11_2
down10m_2 := true
////logic volume start
x = input.float(3.1, title="Factor For Breakout Candle")
red = #ff848a //#ff848a // #FA8072 // #323433 // #ff848a
green = #8cffe5 // #8cffe5 // #6DC066 // #80aebd // #8cffe5
// Basic Volume Calcs //
bull = close>open?volume:0
bear = open>close?volume:0
// BEAR Moving Average Calculation
bullma = ta.sma(bull, 14)
// BEAR Moving Average Calculation //
bearma = ta.sma(bear, 14)
// ma dif //
vf_dif = bullma-bearma
vf_absolute = vf_dif > 0 ? vf_dif : vf_dif * (-1)
// Volume Spikes //
var bool gsig = false
var bool rsig = false
if ta.crossover(bull, bullma*x) and barstate.isconfirmed
gsig := true
rsig := false
if ta.crossover(bear, bearma*x) and barstate.isconfirmed
rsig := true
gsig := false
// Color Calcs //
vdClr = vf_dif > 0 ? true : false
vClr = close>open ? true:false
color clr_bar = na
var color_trend = ''
var string colors = na
clr_10m_up = up10m_2 ? color.orange : color.green
clr_10m_down = down10m_2 ? color.gray : color.red
is_trong_call = false
is_trong_put = false
if trend == 1
if vf_dif > 0
clr_bar := color.rgb(41, 126, 45, 5) //rgb(0, 100, 0) // Strong Call
clr_bar := color.rgb(67, 221, 87) // Light Call
if rsi >= 50.00
color_trend := 'Up Trend'
if rsi >= 70.00
color_trend := 'Strong Up Trend'
colors := 'G'
else
if trend == 2
if vf_dif > 0
clr_bar := color.rgb(252, 139, 74) // Mid PUT
clr_10m_down := color.white
is_trong_put := true
else
clr_bar := color.red // Strong PUT
if rsi <= 50.00
color_trend := 'Down Trend'
if rsi <= 35.00
color_trend := 'Strong Down Trend'
colors := 'R'
else
if trend == -1
if vf_dif > 0
clr_bar := color.rgb(252, 139, 74) // Mid PUT
else
clr_bar := color.rgb(228, 201, 170) // Light PUT
if rsi <= 50.00
color_trend := 'Down Trend'
if rsi <= 35.00
color_trend := 'Strong Down Trend'
//is_trong_put := true
colors := 'O'
else
if trend == -2
if vf_dif > 0
clr_bar := color.yellow // Begin Call
clr_10m_up := color.blue
is_trong_call := true
else
clr_bar := color.rgb(0, 0, 255) // Mid Call
if rsi >= 50.00
color_trend := 'Up Trend'
if rsi >= 70.00
color_trend := 'Strong Up Trend'
//is_trong_call := true
colors := 'B'
barcolor(clr_bar)
plotshape(up10m_2 ? low1d : na, title="close > wma 11", style=shape.circle, location=location.absolute, color=clr_10m_up, size=size.tiny)
plotshape(down10m_2 ? low1d : na, title="close < wma 11", style=shape.circle, location=location.absolute, color=clr_10m_down, size=size.tiny)
exit_short = down10m_2[5] and down10m_2[4] and down10m_2[3] and down10m_2[2] and down10m_2[1] and is_trong_call
////logic volume end
// super trend start
cci_period = 28
cci = ta.cci(close, cci_period)
ML = 0
Factor=3
Pd=3
f_supertrend(Factor, Pd) =>
Up=hl2-(Factor*ta.atr(Pd))
Dn=hl2+(Factor*ta.atr(Pd))
TrendUp = 0.0
TrendUp := cci[1] > ML ? math.max(Up,TrendUp[1]) : Up
TrendDown = 0.0
TrendDown := cci[1]< ML ? math.min(Dn,TrendDown[1]) : Dn
Trend = 0.0
Trend := cci > ML ? 1: cci < ML ? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown
Tsl
st_tsl = f_supertrend(Factor, Pd)
buy= close >= st_tsl
sell= close < st_tsl
buy1= ta.barssince(buy)
sell1 = ta.barssince(sell)
buy_trend = buy1[1] > sell1[1] ? true : false
buy2= ta.barssince(sell)
sell2 = ta.barssince(buy)
sell_trend = buy2[1] > sell2[1] ? true : false
var bool is_buy = false
var bool is_sell = false
if sell_trend
is_sell := true
is_buy := false
if buy_trend
is_sell := false
is_buy := true
// super trend end
// ema cross start
oc = math.abs(open[1]-close[1])
hl = math.abs(high[1]-low[1])
ochl = (oc-hl)/hl
ll = (low[1]-low[2])/low[2]
crossUpWMA11 = ta.crossover(ema11, ema48) and barstate.isconfirmed
crossDownWMA11 = ta.crossunder(ema11, ema48) and barstate.isconfirmed
var bool crossup11_48 = false
var bool crossdown11_48 = false
var int cnt_out_up = 0
if crossUpWMA11
crossup11_48 := true
crossdown11_48 := false
cnt_out_up := 0
if crossDownWMA11
crossup11_48 := false
crossdown11_48 := true
cnt_out_up := 0
is_br = open[2] < close[2] and open[1] < close[1] and close < open and close[2] < close[1] and close[1] > close and ochl < 0.3 and (low[3] < low[2] and low[2] < low[1])
if is_br
cnt_out_up := cnt_out_up + 1
is_out_up = false
if cnt_out_up>2
is_out_up := true
cnt_out_up := 0
// ema cross end
// trend strong start
wma13 = ta.wma(close, 13)
plot(wma13, title="WMA13", color=color.blue)
wma48 = ta.wma(close, 48)
plot(wma48, title="WMA48", color=color.yellow)
// sideway start
avg = (close[10] + close[9] + close[8] + close[7] + close[6] +close[5] + close[4] + close[3] + close[2] + close[1])/10
sideway_short = wma13 < wma48 and wma13 < avg and avg < wma48
sideway_long = wma13 > wma48 and wma13 > avg and avg > wma48
sideway = math.abs(close[1]-avg)/avg < 0.001
plotshape(sideway_short or sideway_long or sideway ? low1d*0.995 : na, title="Short", style=shape.diamond, location=location.absolute, color=sideway? color.white : (sideway_long? color.yellow: color.blue), size=size.tiny, textcolor = color.white)
//plotshape(sideway_long ? *0.99 : na, title="Long", style=shape.xcross, location=location.absolute, color=color.yellow, size=size.small, textcolor = color.white)
//plotshape(sideway ? (wma13 + wma48)/2 : na, title="Short", style=shape.diamond, location=location.absolute, color=color.blue, size=size.small, textcolor = color.white)
// sideway end
wma200 = ta.wma(close, 200)
plot(wma200, title="WMA200", color=color.white)
crossUpWMA13 = ta.crossover(close, wma13) and barstate.isconfirmed
crossDownWMA13 = ta.crossunder(close, wma13) and barstate.isconfirmed
crossUpWMA48 = ta.crossover(close, wma48) and barstate.isconfirmed
crossDownWMA48 = ta.crossunder(close, wma48) and barstate.isconfirmed
crossUpWMA200 = ta.crossover(close, wma200) and barstate.isconfirmed
crossDownWMA200 = ta.crossunder(close, wma200) and barstate.isconfirmed
crossUpWMA13_48 = ta.crossover(wma13, wma48) and barstate.isconfirmed
crossDownWMA13_48 = ta.crossunder(wma13, wma48) and barstate.isconfirmed
crossUpWMA48_200 = ta.crossover(wma48, wma200) and barstate.isconfirmed
crossDownWMA48_200 = ta.crossunder(wma48, wma200) and barstate.isconfirmed
var price_wmacrossup_arr = array.new_float()
var price_wmacrossdown_arr = array.new_float()
if crossUpWMA48_200
price_wmacrossdown_arr := array.new_float()
array.push(price_wmacrossup_arr, close)
else if crossDownWMA48_200
price_wmacrossup_arr := array.new_float()
array.push(price_wmacrossdown_arr, close)
var bool isUpTrend = false
var bool isDownTrend = false
if crossUpWMA13 and isUpTrend == false
isUpTrend := true
isDownTrend := false
else if crossUpWMA48 and isUpTrend == false
isUpTrend := true
isDownTrend := false
else if crossUpWMA200 and isUpTrend == false
isUpTrend := true
isDownTrend := false
if crossDownWMA13 and isDownTrend == false
isUpTrend := false
isDownTrend := true
else if crossDownWMA48 and isDownTrend == false
isUpTrend := false
isDownTrend := true
else if crossDownWMA200 and isDownTrend == false
isUpTrend := false
isDownTrend := true
var int trendUp = 0
var int trendDown = 0
if isUpTrend
if crossUpWMA13_48
trendUp := 1
trendDown := 0
if crossUpWMA48_200
trendUp := 2
trendDown := 0
if isDownTrend
if crossDownWMA13_48
trendUp := 0
trendDown := 1
if crossDownWMA48_200
trendUp := 0
trendDown := 2
// trend strong end
bottomsupport = running_pl and close > running_pl and close > close[1] and rsi > rsi[1] + 8
bigdrop = rsi + 8 < rsi[1] and close > ema48 and running_ph and close < running_ph
if sideway
is_trong_call := false
strong_call = is_trong_call[2] and is_trong_call[1] and is_trong_call
longCondition = up10m_2 and not sideway and up10m and buy_trend and ( close*1.05 > wma13 and rsi > rsi[1] + 6 or rsi > rsi[1] + 8 and long or is_cross_up and bottomsupport and is_strong_buy or bottomsupport) and barstate.isconfirmed//and (close > ema48 or close>ema200) // and is_strong_buy and (close > Cto ) and bottomsupport and (close > ema48 or close>ema200)
plotshape(longCondition ? low*0.997 : na, title="BIG", style=shape.triangleup, location=location.absolute, color=clr_10m_up, size=size.small)
//plotshape(strong_call ? low*0.997 : na, title="N", style=shape.xcross, location=location.absolute, color=clr_10m_up, size=size.small)
shortCondition = not sideway and not up10m and sell_trend and (close*0.94 < wma13 and rsi + 8 < rsi[1] or rsi + 8 < rsi[1] and short or is_br or bigdrop and is_strong_sell) and barstate.isconfirmed //is_strong_sell and (close < Cto ) and rsi - rsi[1] < -6 and (close < ema48 or close<ema200)
plotshape(shortCondition ? high*1.003 : na, title="BIG", style=shape.triangledown, location=location.absolute, color=clr_10m_down, size=size.small)
if sideway or Cto < wma13 and wma48 > wma13 and wma48 < wma48[1]
//label.new(bar_index, low, text="SW", textcolor=color.yellow, style=label.style_triangleup, size=size.tiny)
longCondition := false
shortCondition := false
if (longCondition)
strategy.entry("long", strategy.long)
if (shortCondition)
strategy.entry("short", strategy.short)
// exit long when has a short signal and otherwise
//closelong = shortCondition or ((rsi > 70 ) and high[2] < high[1] and high[1] > high or not up10m and (trendDown > 1 or profit_long or sell_trend or bigdrop and not is_cross_up or is_out_up ))//ta.crossunder(rsi,80) or ta.crossunder(rsi,60))
//closeshort= longCondition or up10m and (trendUp > 1 or profit_short or buy_trend or bottomsupport and not is_cross_down) //or ta.crossover(rsi,40) or ta.crossover(rsi,60)
closelong = shortCondition or sideway and close < Cto and close < wma13 or down10m_2 or not up10m and (trendDown > 1 or profit_long or sell_trend or bigdrop and not is_cross_up or is_out_up ) and barstate.isconfirmed
closeshort = longCondition or exit_short or up10m and (trendUp > 1 or profit_short or buy_trend or bottomsupport and not is_cross_down) and barstate.isconfirmed
if(strategy.position_size > 0)
strategy.close(id="long", when=closelong)
if(strategy.position_size < 0)
strategy.close(id="short", when = closeshort)
if(strategy.position_size > 0)
strategy.exit(id='long', limit=longTake,stop = longStop)
if(strategy.position_size < 0)
strategy.exit(id='short', limit=shortTake,stop = shortStop)
Show all 476 lines