algo
algo
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
//$
$
//$ Gratitude is appreciated!
$
//$ You may donate via:
$
//$
$
//$ Crypto-multi-currency wallet
$
//$ https://tinyurl.com/4f9dr9nw
$
//$
$
//$ - BTC: 1EpDN7pg1WqURcK7te5kQtgx3H17wuHiV7
$
//$
$
//$ - LTC: MJyEtVt7EFmA18Bo1vjRMbguivHnVbbWvp
$
//$
$
//$ - Tether TRC20 (USDT): TWQdh36osEJ3mDrG7kGEHgSVHQSgSR61ZY
$
//$
$
//$ Donate as much as you see fit.
$
//$ Do it if you find the stuff useful!
$
//$ Disclaimer: I am not a financial advisor.
$
//$ For purpose educate only. Use at your own risk.
$
//$
$
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
//END SETTINGS
else if swing_type == -1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HL'
else
label_text := 'LL'
label.new(
bar_index - swing_length,
array.get(array,0),
text = label_text,
style = label.style_label_up,
textcolor = swing_type_color,
color = swing_type_color,
size = size.tiny)
atr_threshold = atrValue * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2
if zone_type == 1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_top(array.get(box_array,i))
// if ta.crossover(close, level_to_break)
if close >= level_to_break
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) +
box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_color)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_center)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
if zone_type == -1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_bottom(array.get(box_array,i))
// if ta.crossunder(close, level_to_break)
if close <= level_to_break
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) +
box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_color)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_center)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 100)
//
stratRes = timeframe.ismonthly ? str.tostring(timeframe.multiplier * intRes,
'###M') :
timeframe.isweekly ? str.tostring(timeframe.multiplier * intRes,
'###W') :
timeframe.isdaily ? str.tostring(timeframe.multiplier * intRes,
'###D') :
timeframe.isintraday ? str.tostring(timeframe.multiplier * intRes,
'####') :
'60'
src = h ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, close, lookahead = barmerge.lookahead_off) : close
// CALCULATE ATR
atrValue = ta.atr(50)
//END CALCULATIONS
f_extend_box_endpoint(current_supply_box)
f_extend_box_endpoint(current_demand_box)
//
[_, upperKC1, lowerKC1] = ta.kc(close, 80, 10.5)
[_, upperKC2, lowerKC2] = ta.kc(close, 80, 9.5)
[_, upperKC3, lowerKC3] = ta.kc(close, 80, 8)
[_, upperKC4, lowerKC4] = ta.kc(close, 80, 3)
barsL = 10
barsR = 10
pivotHigh = fixnan(ta.pivothigh(barsL, barsR)[1])
pivotLow = fixnan(ta.pivotlow(barsL, barsR)[1])
source = close, period = 150
[s, a, i] = lr_slope(source, period)
[upDev, dnDev] = lr_dev(source, period, s, a, i)
//Functions
//Line Style function
get_line_style(style) =>
out = switch style
'???' => line.style_solid
'----' => line.style_dashed
' ' => line.style_dotted
float ob = na
array.unshift(ob_top, top)
array.unshift(ob_btm, btm)
array.unshift(ob_avg, avg)
ob := ob_val
array.remove(ob_top, idx)
array.remove(ob_btm, idx)
array.remove(ob_avg, idx)
array.remove(ob_left, idx)
mitigated
//Global elements
var os = 0
var target_bull = 0.
var target_bear = 0.
// Main Indicator
// Functions
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
: x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
percWidth(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
securityNoRep(sym, res, src) => request.security(sym, res, src, barmerge.gaps_off,
barmerge.lookahead_on)
swingPoints(prd) =>
pivHi = ta.pivothigh(prd, prd)
pivLo = ta.pivotlow (prd, prd)
last_pivHi = ta.valuewhen(pivHi, pivHi, 1)
last_pivLo = ta.valuewhen(pivLo, pivLo, 1)
hh = pivHi and pivHi > last_pivHi ? pivHi : na
lh = pivHi and pivHi < last_pivHi ? pivHi : na
hl = pivLo and pivLo > last_pivLo ? pivLo : na
ll = pivLo and pivLo < last_pivLo ? pivLo : na
[hh, lh, hl, ll]
f_chartTfInMinutes() =>
float _resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
f_kc(src, len, sensitivity) =>
basis = ta.sma(src, len)
span = ta.atr(len)
[basis + span * sensitivity, basis - span * sensitivity]
wavetrend(src, chlLen, avgLen) =>
esa = ta.ema(src, chlLen)
d = ta.ema(math.abs(src - esa), chlLen)
ci = (src - esa) / (0.015 * d)
wt1 = ta.ema(ci, avgLen)
wt2 = ta.sma(wt1, 3)
[wt1, wt2]
f_top_fractal(_src) => _src[4] < _src[2] and _src[3] < _src[2] and _src[2] >
_src[1] and _src[2] > _src[0]
f_bot_fractal(_src) => _src[4] > _src[2] and _src[3] > _src[2] and _src[2] <
_src[1] and _src[2] < _src[0]
top_fractal = f_top_fractal(src)
bot_fractal = f_bot_fractal(src)
f_fractalize (_src) => top_fractal ? 1 : bot_fractal ? -1 : 0
f_findDivs(src, topLimit, botLimit) =>
fractalTop = f_fractalize(src) > 0 and src[2] >= topLimit ? src[2] : na
fractalBot = f_fractalize(src) < 0 and src[2] <= botLimit ? src[2] : na
highPrev = ta.valuewhen(fractalTop, src[2], 0)[2]
highPrice = ta.valuewhen(fractalTop, high[2], 0)[2]
lowPrev = ta.valuewhen(fractalBot, src[2], 0)[2]
lowPrice = ta.valuewhen(fractalBot, low[2], 0)[2]
bearSignal = fractalTop and high[1] > highPrice and src[1] < highPrev
bullSignal = fractalBot and low[1] < lowPrice and src[1] > lowPrev
[bearSignal, bullSignal]
// Get user input
enableSR = input(false , "SR On/Off", group="SR")
colorSup = input(#00000000 , "Support Color", group="SR")
colorRes = input(#00000000 , "Resistance Color", group="SR")
strengthSR = input.int(2 , "S/R Strength", 1, group="SR")
lineStyle = input.string("Dotted", "Line Style", ["Solid", "Dotted", "Dashed"],
group="SR")
lineWidth = input.int(2 , "S/R Line Width", 1, group="SR")
useZones = input(true , "Zones On/Off", group="SR")
useHLZones = input(true , "High Low Zones On/Off", group="SR")
zoneWidth = input.int(2 , "Zone Width %", 0,
tooltip = "it's calculated using % of the distance between highest/lowest in
last 300 bars", group="SR")
expandSR = input(true , "Expand SR")
// Get components
rb = 10
prd = 284
ChannelW = 10
label_loc = 55
style = lineStyle == "Solid" ? line.style_solid :
lineStyle == "Dotted" ? line.style_dotted : line.style_dashed
ph = ta.pivothigh(rb, rb)
pl = ta.pivotlow (rb, rb)
sr_levels = array.new_float(21, na)
prdhighest = ta.highest(prd)
prdlowest = ta.lowest(prd)
cwidth = percWidth(prd, ChannelW)
zonePerc = percWidth(300, zoneWidth)
aas = array.new_bool(41, true)
u1 = 0.0, u1 := nz(u1[1])
d1 = 0.0, d1 := nz(d1[1])
highestph = 0.0, highestph := highestph[1]
lowestpl = 0.0, lowestpl := lowestpl[1]
// Get components
rsi = ta.rsi(close, 28)
//rsiOb = rsi > 78 and rsi > ta.ema(rsi, 10)
//rsiOs = rsi < 27 and rsi < ta.ema(rsi, 10)
rsiOb = rsi > 65 and rsi > ta.ema(rsi, 10)
rsiOs = rsi < 35 and rsi < ta.ema(rsi, 10)
dHigh = securityNoRep(syminfo.tickerid, "D", high [1])
dLow = securityNoRep(syminfo.tickerid, "D", low [1])
dClose = securityNoRep(syminfo.tickerid, "D", close[1])
ema = ta.ema(close, 144)
emaBull = close > ema
equal_tf(res) => str.tonumber(res) == f_chartTfInMinutes() and not
timeframe.isseconds
higher_tf(res) => str.tonumber(res) > f_chartTfInMinutes() or timeframe.isseconds
too_small_tf(res) => (timeframe.isweekly and res=="1") or (timeframe.ismonthly and
str.tonumber(res) < 10)
securityNoRep1(sym, res, src) =>
bool bull_ = na
bull_ := equal_tf(res) ? src : bull_
bull_ := higher_tf(res) ? request.security(sym, res, src, barmerge.gaps_off,
barmerge.lookahead_on) : bull_
bull_array = request.security_lower_tf(syminfo.tickerid, higher_tf(res) ?
str.tostring(f_chartTfInMinutes()) + (timeframe.isseconds ? "S" : "") :
too_small_tf(res) ? (timeframe.isweekly ? "3" : "10") : res, src)
if array.size(bull_array) > 1 and not equal_tf(res) and not higher_tf(res)
bull_ := array.pop(bull_array)
array.clear(bull_array)
bull_
//<triggers>
lxTrigger = false
sxTrigger = false
leTrigger = ta.crossover (closeSeriesAlt, openSeriesAlt)
seTrigger = ta.crossunder(closeSeriesAlt, openSeriesAlt)
// ——————————— <constant_declarations>
//Tooltip
T_LVL = '(%) Exit Level'
T_QTY = '(%) Adjust trade exit volume'
T_MSG = 'Paste JSON message for your bot'
//Webhook Message
O_LEMSG = 'Long Entry'
O_LXMSGSL = 'Long SL'
O_LXMSGTP1 = 'Long TP1'
O_LXMSGTP2 = 'Long TP2'
O_LXMSGTP3 = 'Long TP3'
O_LXMSG = 'Long Exit'
O_SEMSG = 'Short Entry'
O_SXMSGSL = 'Short SL'
O_SXMSGA = 'Short TP1'
O_SXMSGB = 'Short TP2'
O_SXMSGC = 'Short TP3'
O_SXMSGX = 'Short Exit'
// ——————————— <input> | | |
Line length guide |
i_lxLvlTP1 = input.float (0.2, 'Level TP1' ,
group = G_RISK,
tooltip = T_LVL)
//i_lxQtyTP1 = input.float (80.0, 'Qty TP1' ,
group = G_RISK,
//tooltip = T_QTY)
//i_lxLvlTP2 = input.float (0.5, 'Level TP2' ,
group = G_RISK,
///tooltip = T_LVL)
//i_lxQtyTP2 = input.float (10.0, 'Qty TP2' ,
group = G_RISK,
//tooltip = T_QTY)
//i_lxLvlTP3 = input.float (7.0, 'Level TP3' ,
group = G_RISK,
//tooltip = T_LVL)
//i_lxQtyTP3 = input.float (2, 'Qty TP3' ,
group = G_RISK,
//tooltip = T_QTY)
i_lxLvlSL = input.float (0.5, 'Stop Loss' , group
= G_RISK,
tooltip = T_LVL)
i_sxLvlTP1 = i_lxLvlTP1
//i_sxQtyTP1 = i_lxQtyTP1
//i_sxLvlTP2 = i_lxLvlTP2
//i_sxQtyTP2 = i_lxQtyTP2
//i_sxLvlTP3 = i_lxLvlTP3
//i_sxQtyTP3 = i_lxQtyTP3
i_sxLvlSL = i_lxLvlSL
G_DISPLAY = 'Display'
//<display>
i_alertOn = input.bool (true, 'Alert Labels On/Off' , group
= G_DISPLAY)
i_barColOn = input.bool (true, 'Bar Color On/Off' , group
= G_DISPLAY)
// ——————————— <function_declarations>
// @function Calculate the Take Profit line, and the crossover or crossunder
f_tp(_condition, _conditionValue, _leTrigger, _seTrigger, _src, _lxLvlTP,
_sxLvlTP)=>
var float _tpLine = 0.0
_topLvl = _src + (_src * (_lxLvlTP / 100))
_botLvl = _src - (_src * (_sxLvlTP / 100))
_tpLine := _condition[1] != _conditionValue and _leTrigger ? _topLvl :
_condition[1] != -_conditionValue and _seTrigger ? _botLvl :
nz(_tpLine[1])
[_tpLine]
// ——————————— <calculations>
//<set initial values>
var float condition = 0.0
var float slLine = 0.0
var float entryLine = 0.0
switch
leTrigger and condition[1] <= 0.0 => condition := 1.0
seTrigger and condition[1] >= 0.0 => condition := -1.0
//tp3Long and condition[1] == 1.2 => condition := 1.3
//tp3Short and condition[1] == -1.2 => condition := -1.3
//tp2Long and condition[1] == 1.1 => condition := 1.2
//tp2Short and condition[1] == -1.1 => condition := -1.2
tp1Long and condition[1] == 1.0 => condition := 1.1
tp1Short and condition[1] == -1.0 => condition := -1.1
slLong and condition[1] >= 1.0 => condition := 0.0
slShort and condition[1] <= -1.0 => condition := 0.0
lxTrigger and condition[1] >= 1.0 => condition := 0.0
sxTrigger and condition[1] <= -1.0 => condition := 0.0
// ——————————— <visuals>
c_tp = leTrigger or seTrigger ? na :
condition == 0.0 ? na : color.green
c_entry = leTrigger or seTrigger ? na :
condition == 0.0 ? na : color.blue
c_sl = leTrigger or seTrigger ? na :
condition == 0.0 ? na : color.red
p_tp1Line = plot (condition == 1.0 or condition == -1.0 ? tp1Line : na, title
= "TP Line 1", color = c_tp, linewidth = 1, style =
plot.style_linebr)
//p_tp2Line = plot ( condition == 1.0 or condition == -1.0 or condition == 1.1
or condition == -1.1 ? tp2Line : na, title = "TP Line 2", color = c_tp,
linewidth = 1, style = plot.style_linebr)
//p_tp3Line = plot (condition == 1.0 or condition == -1.0 or condition == 1.1
or condition == -1.1 or condition == 1.2 or condition == -1.2 ? tp3Line : na,
title = "TP Line 3", color = c_tp, linewidth = 1, style =
plot.style_linebr)
p_entryLine = plot (condition >= 1.0 or condition <= -1.0 ? entryLine : na,
title = "Entry Line", color = c_entry, linewidth = 1, style =
plot.style_linebr)
p_slLine = plot ( condition == 1.0 or condition == -1.0 or condition == 1.1
or condition == -1.1 or condition == 1.2 or condition == -1.2 ? slLine : na,
title = "SL Line", color = c_sl, linewidth = 1, style =
plot.style_linebr)
//fill( p_tp3Line, p_entryLine, color = leTrigger or seTrigger ?
na :color.new(color.green, 90))
fill( p_entryLine, p_slLine, color = leTrigger or seTrigger ?
na :color.new(color.red, 90))
//<alerts labels>
plotshape( i_alertOn and longE, title = 'Long', text = 'Long', textcolor =
color.white, color= color.green, style = shape.labelup, size = size.tiny,
location = location.belowbar)
plotshape(i_alertOn and shortE, title = 'Short', text = 'Short', textcolor =
color.white, color = color.red, style = shape.labeldown, size = size.tiny,
location = location.abovebar)
plotshape(i_alertOn and (longX or shortX) ? close : na, title = 'Close', text
= 'Close', textcolor = color.white, color = color.gray, style =
shape.labelup,size = size.tiny, location = location.absolute)
l_tp = i_alertOn and (longTP1 or shortTP1) ? close : na
plotshape( l_tp, title = "TP1 Cross", text = "TP1", textcolor =
color.white, color = color.olive, style = shape.labelup, size =
size.tiny, location = location.absolute)
//plotshape(i_alertOn and (longTP2 or shortTP2) ? close : na, title = "TP2
Cross",text = "TP2", textcolor = color.white, color = color.olive,
style = shape.labelup, size = size.tiny, location = location.absolute)
//plotshape(i_alertOn and (longTP3 or shortTP3) ? close : na, title = "TP3
Cross", text = "TP3", textcolor = color.white, color = color.olive, style
= shape.labelup, size = size.tiny, location = location.absolute)
plotshape(i_alertOn and (longSL or shortSL) ? close : na, title = "SL Cross",
text = "SL", textcolor = color.white, color = color.maroon, style
= shape.labelup, size = size.tiny, location = location.absolute)
//<debug>
plot( na, title = "─── <debug> ───", editable = false, display =
display.data_window)
plot(condition, title = "condition", editable = false, display =
display.data_window)
//plot(strategy.position_size * 100, title = ".position_size", editable =
false, display = display.data_window)
//#endregion }
// ——————————— <↑↑↑ G_RISK ↑↑↑>
// ——————————— <alerts>
//<any_alert_function_call>
if longE or shortE or longX or shortX
alert(message = 'Any Alert', freq = alert.freq_once_per_bar_close)
if longE
alert(message = 'Long Entry', freq = alert.freq_once_per_bar_close)
if shortE
alert(message = 'Short Entry', freq = alert.freq_once_per_bar_close)
if longX
alert(message = 'Long Exit', freq = alert.freq_once_per_bar_close)
if shortX
alert(message = 'Short Exit', freq = alert.freq_once_per_bar_close)
//#endregion }
// ——————————— <↑↑↑ G_SCRIPT03 ↑↑↑>
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © simplygr8pratik
////======================================================
paraEMA1 = input.int(5, "Period : EMA-1 : ", minval = 1, group = "Trade Settings",
inline = "EMA")
paraEMA2 = input.int(20, "EMA-2 : ", minval = 1, group = "Trade Settings", inline =
"EMA")
////======================================================
paraSystemMode = input.session(defval="Intraday", title="System Mode",
options=["Intraday", "Positional"], group = "System Settings")
////======================================================
FC = session.isfirstbar
LC = session.islastbar
eSignal = 0
eBuy = eBuy1
eShort = eShort1
eSell = eShort or et
eCover = eBuy or et
eSignal := eBuy ? 1 : eShort ? -1 : eSell and eSignal[1] > 0 ? 0 : eCover and
eSignal[1] < 0 ? 0 : eSignal[1]
MainSignal = 0
//BuySignal = paraTradeMode!="ShortOnly" and st and eSignal > 0 and eSignal[1] <= 0
and barstate.isconfirmed and (nz(MainSignal[1]) <= 0)
BuySignal = leTrigger
//ShortSignal = paraTradeMode!="LongOnly" and st and eSignal < 0 and eSignal[1] >=
0 and barstate.isconfirmed and (nz(MainSignal[1]) >= 0)
ShortSignal = tp1Long or slLong
//SellSignal = (((ShortSignal or eSignal <= 0) and barstate.isconfirmed) or et) and
(nz(MainSignal[1]) == 1)
SellSignal = seTrigger
//CoverSignal = (((BuySignal or eSignal >= 0) and barstate.isconfirmed) or et) and
(nz(MainSignal[1]) == -1)
CoverSignal = tp1Short or slShort
MainSignal := BuySignal ? 1 : ShortSignal ? -1 : SellSignal and MainSignal[1] > 0 ?
0 : CoverSignal and MainSignal[1] < 0 ? 0 : MainSignal[1]
////======================================================
////======================================================
symbol = syminfo.ticker
BuyPrice = ta.valuewhen(strategy.position_size > 0, strategy.position_avg_price, 0)
ShortPrice = ta.valuewhen(strategy.position_size < 0, strategy.position_avg_price,
0)
BATM = math.round(BuyPrice/paraOptSteps)*paraOptSteps
SATM = math.round(ShortPrice/paraOptSteps)*paraOptSteps
LEStrike = BATM + (paraOptMulti * paraOptSteps)
SEStrike = SATM - (paraOptMulti * paraOptSteps)
LESym = str.tostring(syminfo.ticker)
LXSym = str.tostring(syminfo.ticker)
SESym = str.tostring(syminfo.ticker)
SXSym = str.tostring(syminfo.ticker)
if (paraInstr=="OPTIDX" or paraInstr=="OPTSTK")
LESym := str.tostring(syminfo.ticker) + '|' + paraOptExpiry + '|' +
str.tostring(LEStrike) + '|' + 'CE'
LXSym := str.tostring(syminfo.ticker) + '|' + paraOptExpiry + '|' +
str.tostring(LEStrike[1]) + '|' + 'CE'
SESym := str.tostring(syminfo.ticker) + '|' + paraOptExpiry + '|' +
str.tostring(SEStrike) + '|' + 'PE'
SXSym := str.tostring(syminfo.ticker) + '|' + paraOptExpiry + '|' +
str.tostring(SEStrike[1]) + '|' + 'PE'
if (paraOptTrade=="Long")
buyData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": '
+ str.tostring(close) + ',"Ticker": "' + LESym + '","OrderType":
"BUY","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(paraQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
sellData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": '
+ str.tostring(close) + ',"Ticker": "' + LXSym + '","OrderType":
"SELL","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(paraQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
shortData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close":
' + str.tostring(close) + ',"Ticker": "' + SESym + '","OrderType":
"BUY","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(paraQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
coverData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close":
' + str.tostring(close) + ',"Ticker": "' + SXSym + '","OrderType":
"SELL","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(paraQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
else
buyData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": '
+ str.tostring(close) + ',"Ticker": "' + SESym + '","OrderType":
"SHORT","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr
+ '","Quantity": '+str.tostring(paraQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
sellData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": '
+ str.tostring(close) + ',"Ticker": "' + SXSym + '","OrderType":
"COVER","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr
+ '","Quantity": '+str.tostring(paraQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
shortData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close":
' + str.tostring(close) + ',"Ticker": "' + LESym + '","OrderType":
"SHORT","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(paraQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
coverData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close":
' + str.tostring(close) + ',"Ticker": "' + LXSym + '","OrderType":
"COVER","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(paraQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
BuyTradeQty := 1 //paraQty
ShortTradeQty := 1 //paraQty
if (paraQtyType=="Exposure")
BuyTradeQty := paraQty / BuyPrice
BuyTradeQty := math.round(BuyTradeQty / syminfo.pointvalue)
ShortTradeQty := paraQty / ShortPrice
ShortTradeQty := math.round(ShortTradeQty / syminfo.pointvalue)
if (BuyTradeQty < 0)
BuyTradeQty := 1
if (ShortTradeQty < 0)
ShortTradeQty := 1
////======================================================
////======================================================
if BuySignal and strategy.position_size < 0
//strategy.close(id='SHORT', comment="Cover", alert_message="["+coverData+"]")
strategy.entry('BUY', strategy.long, comment='Buy', qty=1,
alert_message="["+coverData+","+buyData+"]")
else if BuySignal and strategy.position_size == 0
strategy.entry('BUY', strategy.long, comment='Buy', qty=1,
alert_message="["+buyData+"]")
BuyPrice := strategy.position_avg_price
ShortPrice := strategy.position_avg_price
ut = (paraTGTMode != "Off")
us = (paraSLMode != "Off")
if (paraTGTMode=="%")
BuyTGT1 := BuyPrice * (1+(paraTGT1/100))
BuyTGT := BuyPrice * (1+(paraTGT/100))
else if (paraTGTMode=="Pts")
BuyTGT1 := BuyPrice + (paraTGT1)
BuyTGT := BuyPrice + (paraTGT)
if (paraTGTMode=="%")
ShortTGT1 := ShortPrice * (1-(paraTGT1/100))
ShortTGT := ShortPrice * (1-(paraTGT/100))
else if (paraTGTMode=="Pts")
ShortTGT1 := ShortPrice - (paraTGT1)
ShortTGT := ShortPrice - (paraTGT)
if (paraTSLMode != "Off")
if (strategy.position_size > 0)
if (paraTSLMode=="%")
BuyTSL := high[1] * (1-(paraTSL/100))
else
BuyTSL := high[1] - paraTSL
if (BuySL < BuyTSL)
BuySL := BuyTSL
if (strategy.position_size < 0)
if (paraTSLMode=="%")
ShortTSL := low[1] * (1+(paraTSL/100))
else
ShortTSL := low[1] + paraTSL
if (ShortSL > ShortTSL)
ShortSL := ShortTSL
if (paraMaxProfit > 0)
if (strategy.position_size > 0 and
strategy.opentrades.profit(strategy.opentrades - 1) >= paraMaxProfit)
strategy.close("BUY", immediately = true, alert_message="["+sellData+"]")
if (strategy.position_size < 0 and
strategy.opentrades.profit(strategy.opentrades - 1) >= paraMaxProfit)
strategy.close("SHORT", immediately = true,
alert_message="["+coverData+"]")
if (paraMaxLoss > 0)
if (strategy.position_size > 0 and
strategy.opentrades.profit(strategy.opentrades - 1) <= -(paraMaxLoss))
strategy.close("BUY", immediately = true, alert_message="["+sellData+"]")
if (strategy.position_size < 0 and
strategy.opentrades.profit(strategy.opentrades - 1) <= -(paraMaxLoss))
strategy.close("SHORT", immediately = true,
alert_message="["+coverData+"]")
////======================================================
plot(EMA1, "EMA", color.green)
plot(EMA2, "EMA", color.red)
////======================================================
totalCols = 2
totalRows = 5
stgTGTFlag = paraTGTMode != "Off"
stgSLFlag = paraSLMode != "Off"
if stgTGTFlag
totalRows += 1
if stgSLFlag
totalRows += 1
table_text_size = size.small
openProfit = strategy.openprofit
lastProfit = strategy.closedtrades.profit(strategy.closedtrades-1)
openProfitColor = openProfit >= 0 ? cell_up : cell_dn
lastProfitColor = lastProfit >= 0 ? cell_up : cell_dn
rowCtr = 0
colCtr = 0
if strategy.position_size > 0
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"Buy",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_avg_price,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,toolti
p="")
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"Qty.",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_size,
"#"),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
if (stgTGTFlag)
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"TGT",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
if (BuyTGT1)
table.cell(dashtable, 1, rowCtr, str.tostring(BuyTGT1,
format.mintick) + "/"+ str.tostring(BuyTGT,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,toolti
p="")
else
table.cell(dashtable, 1, rowCtr, str.tostring(BuyTGT,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,toolti
p="")
if (stgSLFlag)
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"SL",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
table.cell(dashtable, 1, rowCtr, str.tostring(BuySL,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,toolti
p="")
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"P&L",text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColor,tooltip=
"")
table.cell(dashtable, 1, rowCtr, str.tostring(openProfit,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColo
r,tooltip="")
if strategy.position_size < 0
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"Short",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_avg_price,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,toolti
p="")
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"Qty.",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_size,
"#"),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
if (stgTGTFlag)
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"TGT",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
if (ShortTGT1)
table.cell(dashtable, 1, rowCtr, str.tostring(ShortTGT1,
format.mintick) + "/"+ str.tostring(ShortTGT,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,toolti
p="")
else
table.cell(dashtable, 1, rowCtr, str.tostring(ShortTGT,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,toolti
p="")
if (stgSLFlag)
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"SL",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
table.cell(dashtable, 1, rowCtr, str.tostring(ShortSL,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,toolti
p="")
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"P&L",text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColor,tooltip=
"")
table.cell(dashtable, 1, rowCtr, str.tostring(openProfit,
format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColo
r,tooltip="")
if strategy.position_size == 0
rowCtr += 1
table.cell(dashtable, 0, rowCtr, "No Trade",
text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
table.cell(dashtable, 1, rowCtr, "Relax",
text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
table.cell(dashtable, 1, rowCtr,
"",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
if (stgTGTFlag)
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
table.cell(dashtable, 1, rowCtr,
"",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
if (stgSLFlag)
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
table.cell(dashtable, 1, rowCtr,
"",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
rowCtr += 1
table.cell(dashtable, 0, rowCtr,
"",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
table.cell(dashtable, 1, rowCtr,
"",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")