Futures Trading
Futures Trading
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
i_startTime = input.time(defval=timestamp('01 Jan 2020 00:00 +0000'), title='Start
Time', group='🟰🟰🟰🟰🟰🟰 Trade Settings 🟰🟰🟰🟰🟰🟰')
i_endTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'),
title='End Time', group='🟰🟰🟰🟰🟰🟰 Trade Settings 🟰🟰🟰🟰🟰🟰')
inDateRange = time >= i_startTime and time <= i_endTime
long_ = input.bool(true, title='Longs',
group='🟰🟰🟰🟰🟰🟰 Trade Settings 🟰🟰🟰🟰🟰🟰')
short_ = input.bool(true,
title='Shorts', group='🟰🟰🟰🟰🟰🟰 Trade Settings 🟰🟰🟰🟰🟰🟰')
DoNotClose = input(false, "Do
not close previous position on new signal", tooltip = "This will allow position to
stay open until it hit SL or TP", group='🟰🟰🟰🟰🟰🟰 Trade Settings 🟰🟰🟰🟰🟰🟰')
OpenOpposite =
input(false, "Force opposite position if SL hit", inline = "oop", group='🟰🟰🟰🟰🟰🟰
Trade Settings 🟰🟰🟰🟰🟰🟰', tooltip = "If actual postion is stopped by Stop Loss then
strategy will open opposite one on the first next candle if possible. This is
experimental option, you are using this on your own.")
showLines =
input(false, "Show TP/SL lines", group='🟰🟰🟰🟰🟰🟰 Trade Settings 🟰🟰🟰🟰🟰🟰')
//-----------
----------------------------------------
SETTINGS----------------------------------------------------------\\
// Get user
input
sensitivity =
input.int(defval=6, title="Sensitivity", minval=1, maxval=20)
keltner_length = 10
atrPeriod = 10
factor = 3.5
// Signal Generation
atr = ta.atr(atrLen)
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand :
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction :
= 1
else
if prevSuperTrend == prevUpperBand
direction :
else
[superTrend, direction]
// SMA
sma55 = ta.sma(close, 9)
// High Lows
// Braid Filter
//-- Inputs
Period1 = 3
Period2 = 7
Period3 = 20
float result = 0
result
if type == 'EMA' // Exponential
result :
= ta.ema(src, len)
result
e = ta.ema(src, len)
result :
= 2 * e - ta.ema(e, len)
result
e = ta.ema(src, len)
result :
result
result :
= ta.wma(src, len)
result
result :
= ta.vwma(src, len)
result
w = ta.wma(src, len)
result :
result
if type == 'RMA'
result :
result
result :
= ta.linreg(src, len, 0)
result
result :
= kijun
result
if type == 'McGinley'
mg = 0.0
mg :
= na(mg[1])
result := mg
result
result
//-- Plots
BraidColor = ma01 > ma02 and dif > filter ? color.green : ma02 > ma01 and dif >
filter ? color.red : color.gray
//bgcolor(BraidColor, transp=90)
//buy = bull and ma01 > ma02 and dif > filter ? label.new(bar_index, y1, "▲",
xloc.bar_index, yloc.price, #04994b, label.style_label_up, color.white,
size.normal) : na
//sell = bear and ma02 > ma01 and dif > filter ? label.new(bar_index, y2, "▼",
xloc.bar_index, yloc.price, #b4060d, label.style_label_down, color.white,
size.normal) : na
barcolor(trendColor)
// Colored candles
// Take Profit Script
colorsr = 'DARK'
TE1 = true
TE2 = true
TE3 = true
rsiLengthInput = 22
rsiSourceInput = close
rsiMA = maTypeInput
// SHORT
// LONG
plotshape(long1 and showrevsig == true and close < supertrend and TE1, "GO LONG 1",
style=shape.circle, location=location.belowbar,size=size.tiny, color =
color.new(bullcolorr, 60), text="▲", textcolor = bullcolorr, editable = false)
plotshape(short1 and showrevsig == true and close > supertrend and TE1, "GO SHORT
1", style=shape.circle, location=location.abovebar,size=size.tiny, color =
color.new(bearcolorr, 60), text="▼", textcolor = bearcolorr, editable = false)
// TP Points Script
maj_qual = 13
maj_len = 40
min_qual = 5
min_len = 5
minn = false
selll = 0.0
buyy = 0.0
bindex = 0.0
sindex = 0.0
bindex := nz(bindex[1], 0)
sindex := nz(sindex[1], 0)
ret = 0
bindex += 1
bindex
sindex += 1
sindex
if bindex > qual and close < open and high >=
ta.highest(high, len)
bindex :
= 0
ret :
= -1
ret
if sindex > qual and close > open and low <= ta.lowest(low, len)
sindex :
= 0
ret :
= 1
ret
return_1 = ret
return_1
selll :
= 1
selll
selll :
= 2
selll
selll :
= 3
selll
= 1
buyy
buyy :
= 2
buyy
buyy :
= 3
buyy
plotshape(selll == 2, style=shape.xcross,location=location.abovebar,
color=color.new(#354996, 0), textcolor=color.new(color.white, 0), offset=0)
//-----------------------------------------------------------------------------}
//---Jurik MA
phase = 0
power = 1
phaseRatio = _phase < -100 ? 0.5 : _phase > 100 ? 2.5 : _phase / 100 + 1.5
e0 = 0.0
e1 = 0.0
jma = 0.0
e2 = 0.0
jma := e2 + nz(jma[1])
jma
frama(source, c) =>
out = 0.0
len1 = c / 2
e = 2.7182818284590452353602874713527
H1 = ta.highest(high, len1)
L1 = ta.lowest(low, len1)
H2 = ta.highest(high, len1)[len1]
L2 = ta.lowest(low, len1)[len1]
H3 = ta.highest(high, c)
L3 = ta.lowest(low, c)
N3 = (H3 - L3) / c
alpha_ = 2 / (N + 1)
out
//------FRAMA modificato---------
frama_mod(source, c) =>
float result = 0
int len1 = c / 2
frama_SC = 200
frama_FC = 1
e = 2.7182818284590452353602874713527
H1 = ta.highest(high, len1)
L1 = ta.lowest(low, len1)
H2 = H2_[len1]
L2 = L2_[len1]
H3 = ta.highest(high, c)
L3 = ta.lowest(low, c)
N3 = (H3 - L3) / c
alpha_ = 2 / (N + 1)
//frama = 0.0
result
//------------------------------------
calc_dema(source, c) =>
dema1 = ta.ema(source, c)
dema2 = ta.ema(dema1, c)
dExpoMA
calc_tema(source, c) =>
tExpo1 = ta.ema(source, c)
tExpo2 = ta.ema(tExpo1, c)
tExpo3 = ta.ema(tExpo2, c)
tExpoMA
calc_zlema(source, c) =>
zLagExpo1 = (c - 1) / 2
zLagExpoMA = ta.ema(zLagExpo2, c)
zLagExpoMA
calc_smma(source, c) =>
smmaMA = 0.0
smmaMA
calc_kama(source, c) =>
kaMA1 = math.abs(ta.change(source, c))
kaufmanVol = math.sum(math.abs(ta.change(source)), c)
kaufmanFast2 = 2 / (kaufmanFast + 1)
kaufmanSlow2 = 2 / (kaufmanSlow + 1)
kaMA = 0.0
kaMA
calc_tma(source, c) =>
triMA
calc_gmma(source, c) =>
lmean = math.log(source)
smean = math.sum(lmean, c)
geoMA = math.exp(smean / c)
geoMA
calc_vida(source, c) =>
mom = ta.change(source)
F = 2 / (c + 1)
vida = 0.0
vida := source * F * cmo + nz(vida[1]) * (1 - F * cmo)
vida
calc_cma(source, c) =>
sma = ta.sma(source, c)
cma = sma
v1 = ta.variance(source, c)
v3 = v1 == 0 or v2 == 0 ? 1 : v2 / (v1 + v2)
float err = 1
// Gain Factor
float kPrev = 1
float k = 1
for i = 0 to 5000 by 1
k := v3 * kPrev * (2 - kPrev)
err :
= kPrev - k
kPrev :
= k
kPrev
cma :
cma
alpha = 2 / (1 + c)
weight :
num = 0.0
den = 0.0
ma = num / den
ma
// Ribbion
getMa1(c) =>
switch ma
'ema'
=> ta.ema(source,c)
getMa(c) =>
switch ma2
'ema'
=> ta.ema(source,c)
c01 = Theme == 'Theme 1' ? colour1 : Theme == 'Theme 2' ? colour3 : Theme == 'Theme
3' ? colour5 : Theme == 'No fill' ? #FFFFFF00 : na
c02 = Theme == 'Theme 1' ? colour2 : Theme == 'Theme 2' ? colour4 : Theme == 'Theme
3' ? colour6 : Theme == 'N0 fill' ? #FFFFFF00 : na
rib1 = getMa1(rl1)
rib2 = getMa1(rl2)
rib3 = getMa1(rl3)
rib4 = getMa1(rl4)
rib5 = getMa1(rl5)
rib6 = getMa1(rl6)
rib7 = getMa1(rl7)
rib8 = getMa1(rl8)
sma8 = getMa(cl8)
sma7 = getMa(cl7)
sma6 = getMa(cl6)
sma5 = getMa(cl5)
sma4 = getMa(cl4)
sma3 = getMa(cl3)
sma2 = getMa(cl2)
sma1 = getMa(cl1)
// --> fill
// ALERTS {
// } ALERTS
// Bar Coloring
// Input
// Data reference
// 4 level of green
greenHigh = #05df09
greenMidHigh = #05df09
greenMidLow = #388E3C
greenLow = #5f3a97
// Yellow
yellowLow = #5f3a97
// 4 level of red
redHigh = #ea0402
redMidHigh = #ea0402
redMidLow = #cc0402
redLow = #5f3a97
// Default color
candleBody = yellowLow
// Ranging trend
if hist > 0
candleBody :
= greenLow
if hist < 0
candleBody := redLow
// Bullish trend
candleBody := greenMidLow
if hist >
candleBody :
= greenMidHigh
= greenHigh
// Bearish trend
candleBody :
= redMidLow
candleBody :
= redMidHigh
candleBody :
= redHigh
// TP Signals
src5 = close
offset = 0
sumX = 0.0
sumY = 0.0
sumXSqr = 0.0
sumXY = 0.0
for i = 1 to len5 by 1
val = src5[len5 - i]
per = i + 1.0
sumX += per
sumY += val
sumXY
//
z1 = vwap1 + dev
x1 = vwap1 - dev
//plotshape(tpmode == "Version 2" and close < supertrend ? low1 : na, title='low',
text='TP', color=color.new(color.red, 0), style=shape.labelup,
location=location.belowbar, size=size.small, textcolor=color.new(color.white,
0)) //plot for buy icon
//plotshape(tpmode == "Version 2" and close > supertrend ? high1 : na,
title='high', text='TP', color=color.new(color.green, 0), style=shape.labeldown,
location=location.abovebar, size=size.small, textcolor=color.new(color.white,
0)) //plot for sell icon
// PullBack Signals
mycolor = up and EmaClD ? color.rgb(0, 255, 234, 71) : down and EmaClD ?
color.rgb(255, 12, 32, 72) : na
//func
kama = 0.0
kama
//inputs
//logic
rg = kama(ta.tr, llength)
//ploting
// Dashboard
// Functions
f_chartTfInMinutes() =>
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
// Get components
bool bulle = na
if array.size(bull_array)
bulle :
= array.pop(bull_array)
array.clear(bull_array)
bulle
dashboard_cell(0, 3, "Volume")
dashboard_cell(0, 4, "Timeframe")
dashboard_cell(1, 0, "Premium")
dashboard_cell(1, 2, str.tostring(math.round_to_mintick(volume)))
dashboard_cell(1, 3, "Trends")
//
// Ha Market Bias //
ha_len = 100
ha_len2 = 100
// Calculations {
o = ta.ema(open, ha_len)
c = ta.ema(close, ha_len)
h = ta.ema(high, ha_len)
l = ta.ema(low, ha_len)
haclose = tf(ha_htf, (o + h + l + c) / 4, 0)
xhaopen = tf(ha_htf, (o + c) / 2, 0)
// }
// Oscillator {
osc_len = 7
sigcolor =
na
// }
// Plots {
// }
// Range Filter DW
//---------------------Range
Filter-----------------------------------------------------------------------------
-----------------------------------------
if cond
array.push(val, x)
if array.size(val)
> 1
array.remove(val, 0)
if na(array.get(ema_val, 0))
EMA = array.get(ema_val, 0)
EMA
if cond
array.push(vals, x)
if array.size(vals)
> n
array.remove(vals, 0)
SMA = array.avg(vals)
SMA
Stdev(x, n) =>
ATR = Cond_EMA(ta.tr(true), 1, n)
AC = Cond_EMA(math.abs(x - x[1]), 1, n)
SD = Stdev(x, n)
rng_size
if h - r > array.get(rfilt, 1)
array.set(rfilt, 0, h - r)
if l + r < array.get(rfilt, 1)
array.set(rfilt, 0, l + r)
if h >= array.get(rfilt, 1)
+ r
if l <= array.get(rfilt, 1)
- r
rng_filt1 = array.get(rfilt, 0)
hi_band1 = rng_filt1 + r
lo_band1 = rng_filt1 - r
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Filter Type
//Movement Source
mov_src = 'Close'
rng_qty = 2.618
//Range Period
rng_per = 14
smooth_range = true
smooth_per = 27
av_vals = false
av_samples = 2
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Definitions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Direction Conditions
upward = fdir == 1 ? 1 : 0
downward = fdir == -1 ? 1 : 0
//Colors
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Outputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Filter Plot
//Bar Color
// Superlchi + TBO
tenkan_len = 6
tenkan_mult = 2
kijun_len = 5
kijun_mult = 3.
spanB_len = 26
spanB_mult = 4.
offsett = 0
//------------------------------------------------------------------------------
avg(srcc,length,mult)=>
atr = ta.atr(length)*mult
up = hl2 + atr
dn = hl2 - atr
upper = 0.,lower = 0.
os = 0,max = 0.,min = 0.
math.avg(max,min)
//------------------------------------------------------------------------------
tenkan = avg(close,tenkan_len,tenkan_mult)
kijun = avg(close,kijun_len,kijun_mult)
senkouA = math.avg(kijun,tenkan)
senkouB = avg(close,spanB_len,spanB_mult)
//------------------------------------------------------------------------------
tenkan_css = #2157f3
kijun_css = #ff5d00
cloud_a = color.new(color.teal,80)
cloud_b = color.new(color.red,80)
chikou_css = #7b1fa2
plot(close,'Chikou',chikou_css,offset=-offsett+1,display=display.none)
//CONDITION//
//minplus
useATR = input(false, "Use ATR for SL/TP", group = "ATR system", tooltip = "If this
is activated main TP/SL % will not be in use. All the rest from trail TP/SL will be
possible to use acording to ATR's TP/SL.")
safeATR = input(false, "Safe from ATR on wicks (ATR SL > main SL)", group = "ATR
system", tooltip = "If there was a wicks on the chart and your positions should be
opened around that wicks then ATR SL could be to high, so this rule will check if
ATR SL is higher then main SL, if so main TP/SL will be used in that cases.")
//---------------------ATR------------------------------------------------------
if atrsmoothing == "RMA"
ta.rma(source, atrlength)
else
if atrsmoothing == "SMA"
ta.sma(source, atrlength)
else
if atrsmoothing == "EMA"
ta.ema(source, atrlength)
else
ta.wma(source, atrlength)
atrp1 = plot(showATR ? atrx : na, title = "ATR Short Stop Loss", color =
color.new(atrcolshort, 20), trackprice = atrpline ? true : false)
atrp2 = plot(showATR ? atrx2 : na, title = "ATR Long Stop Loss", color =
color.new(atrcollong, 20), trackprice = atrpline ? true : false)
//------------------------------------------------------------------------------
useClosePrice = input(false, "Use candle close price for trail TP/SL", group='Trail
system', tooltip = "This option will wait for candle close and according to the
close price will close the part of your position and set trail SL. This means that
there will be no exact trail levels for executing the limit order, trail levels
will be used as a gate while close price will be used for executions.")
// BACKTEST ====================
longCond :
= can_long
shortCond :
= can_short
var float tplLevel = na
var TrailTPstep = 0
var TrailSLlevel = 0
var PositionID = 0
var TrailGate1 = 0.
var TrailGate2 = 0.
var TrailGate3 = 0.
var TrailExecution = 0
var LTakeProfit = 0.
var STakeProfit = 0.
//var TakeProfit = 0.
var SStopLoss = 0.
var LStopLoss = 0.
shortCond :
= true
longCond :
= true
// Backtest Long ===================
GoWithPos = true
GoWithPos :
= false
LastPosSignal :
= "Long"
if strategy.position_size < 0
strategy.cancel_all()
PositionID :
= PositionID + 1
TrailTPstep :
= 0
TrailSLlevel :
= 0
TrailSignal :
= false
TrailGate1 :
= 0
TrailExecution :
= 0
= L_TakeProfit
LStopLoss :
= L_StopLoss
else
LTakeProfit :
LStopLoss :
else
LTakeProfit :
= L_TakeProfit
LStopLoss :
= L_StopLoss
if TrailSteps == 2
if TrailSteps == 3
if TrailSteps == 4
if TrailSignal == false
tplLevel :
= close * (1 + (LTakeProfit/100))
if TrailExecution == 0
sllLevel :
if strategy.position_size > 0
if TrailSteps == 2
if TrailSteps == 3
if TrailSteps == 4
if TrailSignal == false
tplLevel :
= strategy.position_avg_price * (1 + (LTakeProfit/100))
if TrailExecution == 0
sllLevel :
LastPosSignal :
= "Short"
if strategy.position_size > 0
strategy.cancel_all()
PositionID :
= PositionID + 1
TrailTPstep :
= 0
TrailSLlevel :
= 0
TrailSignal :
= false
TrailGate1 :
= 0
TrailExecution :
= 0
STakeProfit :
= S_TakeProfit
SStopLoss :
= S_StopLoss
else
STakeProfit :
SStopLoss :
else
STakeProfit :
= S_TakeProfit
SStopLoss :
= S_StopLoss
if TrailSteps == 2
if TrailSteps == 4
if TrailSignal == false
tpsLevel :
= close * (1 - (STakeProfit/100))
if TrailExecution == 0
slsLevel :
if strategy.position_size < 0
if TrailSteps == 2
if TrailSteps == 4
if TrailSignal == false
tpsLevel :
= strategy.position_avg_price * (1 - (STakeProfit/100))
if TrailExecution == 0
slsLevel :
//plot signals
if strategy.closedtrades > 0
TrailTPstep :
= 1
TrailTPstep :
= 2
TrailTPstep :
= 3
// Trail SL =========================
//Long
if strategy.position_size > 0
strategy.cancel_all()
if TrailTPstep == 1
tplLevel :
= strategy.position_avg_price * (1 + (LTakeProfit/100))
sllLevel :
= strategy.position_avg_price
if TrailTPstep == 2
if TrailSteps == 2
tplLevel :
= strategy.position_avg_price * (1 + (LTakeProfit/100))
sllLevel :
= strategy.position_avg_price * (1 + ((LTakeProfit/100)*0.50))
if TrailSteps == 3
tplLevel :
= strategy.position_avg_price * (1 + (LTakeProfit/100))
sllLevel :
= strategy.position_avg_price * (1 + ((LTakeProfit/100)*0.33))
if TrailSteps == 4
tplLevel :
= strategy.position_avg_price * (1 + (LTakeProfit/100))
sllLevel :
= strategy.position_avg_price * (1 + ((LTakeProfit/100)*0.25))
if TrailTPstep == 3
tplLevel :
= strategy.position_avg_price * (1 + (LTakeProfit/100))
sllLevel :
= strategy.position_avg_price * (1 + ((LTakeProfit/100)*0.50))
if useTrailTP
if TrailSteps == 3
if TrailSteps == 4
//Short
if strategy.position_size < 0
strategy.cancel_all()
if TrailTPstep == 1
tpsLevel :
= strategy.position_avg_price * (1 - (STakeProfit/100))
slsLevel :
= strategy.position_avg_price
if TrailTPstep == 2
if TrailSteps == 2
tpsLevel :
= strategy.position_avg_price * (1 - (STakeProfit/100))
slsLevel :
= strategy.position_avg_price * (1 - ((STakeProfit/100)*0.50))
if TrailSteps == 3
tpsLevel :
= strategy.position_avg_price * (1 - (STakeProfit/100))
slsLevel :
= strategy.position_avg_price * (1 - ((STakeProfit/100)*0.33))
if TrailSteps == 4
tpsLevel :
= strategy.position_avg_price * (1 - (STakeProfit/100))
slsLevel :
= strategy.position_avg_price * (1 - ((STakeProfit/100)*0.25))
if TrailTPstep == 3
tpsLevel :
= strategy.position_avg_price * (1 - (STakeProfit/100))
slsLevel :
= strategy.position_avg_price * (1 - ((STakeProfit/100)*0.50))
if useTrailTP
if TrailSteps == 3
if TrailSteps == 4
//Long
TrailExecution :
= 0
TrailGate1 :
= strategy.position_avg_price * (1 + ((LTakeProfit/TrailSteps)/100))
if TrailSteps == 3
TrailGate2 :
= strategy.position_avg_price + ((TrailGate1-strategy.position_avg_price)*2)
if TrailSteps == 4
TrailGate2 :
= strategy.position_avg_price + ((TrailGate1-strategy.position_avg_price)*2)
TrailGate3 :
= strategy.position_avg_price + ((TrailGate1-strategy.position_avg_price)*3)
if TrailSteps == 2
strategy.cancel_all()
sllLevel :
TrailExecution := 1
TrailTPstep := 1
if TrailSteps == 3
strategy.cancel_all()
sllLevel :
TrailExecution := 1
TrailTPstep := 1
if TrailExecution == 0
strategy.cancel_all()
sllLevel :
= LadderTrail ? close * (1 - ((LTakeProfit/TrailSteps)/100)) :
strategy.position_avg_price * (1 - (LStopLoss / 100))
TrailExecution := 2
TrailTPstep := 2
if TrailExecution == 1
strategy.cancel_all()
sllLevel :
TrailExecution := 2
TrailTPstep := 2
if TrailSteps == 4
strategy.cancel_all()
sllLevel :
TrailExecution := 1
TrailTPstep := 1
strategy.cancel_all()
sllLevel :
TrailExecution := 2
TrailTPstep := 2
if TrailExecution == 1
strategy.cancel_all()
sllLevel :
TrailExecution := 2
TrailTPstep := 2
if TrailExecution == 0
strategy.cancel_all()
sllLevel :
TrailExecution := 3
TrailTPstep := 3
if TrailExecution == 1
strategy.cancel_all()
sllLevel :
TrailExecution := 3
TrailTPstep := 3
if TrailExecution == 2
strategy.cancel_all()
sllLevel :
TrailExecution := 3
TrailTPstep := 3
//Short
strategy.position_avg_price
TrailExecution :
= 0
TrailGate1 :
= strategy.position_avg_price * (1 - ((STakeProfit/TrailSteps)/100))
if TrailSteps == 3
TrailGate2 :
= strategy.position_avg_price - ((strategy.position_avg_price-TrailGate1)*2)
if TrailSteps == 4
TrailGate2 :
= strategy.position_avg_price - ((strategy.position_avg_price-TrailGate1)*2)
TrailGate3 :
= strategy.position_avg_price - ((strategy.position_avg_price-TrailGate1)*3)
if TrailSteps == 2
strategy.cancel_all()
slsLevel :
TrailExecution := 1
TrailTPstep := 1
if TrailSteps == 3
strategy.cancel_all()
slsLevel :
TrailExecution := 1
TrailTPstep := 1
if TrailExecution == 0
strategy.cancel_all()
slsLevel :
TrailExecution := 2
TrailTPstep := 2
if TrailExecution == 1
strategy.cancel_all()
slsLevel :
TrailExecution := 2
TrailTPstep := 2
if TrailSteps == 4
strategy.cancel_all()
strategy.close("Short" + str.tostring(PositionID), comment = "TP1 short",
qty_percent = 25)
slsLevel :
TrailExecution := 1
TrailTPstep := 1
if TrailExecution == 0
strategy.cancel_all()
slsLevel :
TrailExecution := 2
TrailTPstep := 2
if TrailExecution == 1
strategy.cancel_all()
slsLevel :
TrailExecution := 2
TrailTPstep := 2
if TrailExecution == 0
strategy.cancel_all()
slsLevel :
TrailExecution := 3
TrailTPstep := 3
if TrailExecution == 1
strategy.cancel_all()
slsLevel :
TrailExecution := 3
TrailTPstep := 3
if TrailExecution == 2
strategy.cancel_all()
slsLevel :
TrailExecution := 3
TrailTPstep := 3
// Track Trail
//Long
if TrailSignal == false
TrailSLPrice := sllLevel
TrailSignal :
= true
TrailSLPrice :
= (close*(1-(StopLossTrail/100)))
strategy.cancel_all()
//Short
if TrailSignal == false
TrailSLPrice :
= slsLevel
TrailSignal :
= true
TrailSLPrice :
= (close*(1+(StopLossTrail/100)))
strategy.cancel_all()
table_text_size(s) =>
switch s
=> size.tiny
tableTextSize = table_text_size(i_tableTextSize)
//
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
if i_showDashboard
if newWin
lossRow :
= 0
winRow :
= winRow + 1
if winRow > maxWinRow
maxWinRow :
= winRow
if newLoss
winRow :
= 0
lossRow :
= lossRow + 1
maxLossRow :
= lossRow
if barstate.islastconfirmedhistory
// Update table
dollarReturn = strategy.netprofit
_numOfDaysInStrategy = (strategy.opentrades.entry_time(0) -
strategy.closedtrades.entry_time(0)) / (1000 * 3600 * 24)
//
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
i_monthlyReturnPercision = 2
if i_showMonthlyPerformance
new_month = month(time)
!= month(time[1])
eq = strategy.equity
bar_pnl = eq / eq[1] - 1
cur_month_pnl = 0.0
cur_year_pnl = 0.0
cur_month_pnl :
= new_month ? 0.0 :
(1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1
// Current Yearly P&L
(1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1
last_computed = false
if(last_computed[1])
array.pop(month_pnl)
array.pop(month_time)
array.push(month_pnl, cur_month_pnl[1])
array.push(month_time, time[1])
if(last_computed[1])
array.pop(year_pnl)
array.pop(year_time)
array.push(year_pnl, cur_year_pnl[1])
array.push(year_time, time[1])
last_computed :
monthly_table :
for yi = 0 to array.size(year_pnl)
- 1
for mi = 0 to array.size(month_time)
- 1