ALGOX Trading Strategy v6.1.23
ALGOX Trading Strategy v6.1.23
0)
// [Link]
// © gu5tavo71 (Gustavo Cardelle)
//@version=5
VERSION = 'v6_1_23'// 2023.10.13
strategy(
'ALGOX',
shorttitle = 'ALGOX ' + VERSION,
overlay = true,
explicit_plot_zorder = true,
pyramiding = 0,
default_qty_type = strategy.percent_of_equity,
default_qty_value = 10,
calc_on_every_tick = false,
process_orders_on_close = true)
// Project #827
// Actual version: @gu5tavo71 for Riccardo (@rikyfx for PineScripters Jobs)
// This script reuses open source code from another authors:
// @PineCoders, Built-in Library, and Community Scripts
// Disclaimer: I am not a financial advisor.
// For purpose educate only. Use at your own risk.
//END SETTINGS
//FUNCTIONS
else if swing_type == -1
if [Link](array, 0) >= [Link](array, 1)
label_text := 'HL'
else
label_text := 'LL'
[Link](
bar_index - swing_length,
[Link](array,0),
text = label_text,
style = label.style_label_up,
textcolor = swing_type_color,
color = swing_type_color,
size = [Link])
atr_threshold = atrValue * 2
okay_to_draw = true
for i = 0 to [Link](box_array) - 1
top = box.get_top([Link](box_array, i))
bottom = box.get_bottom([Link](box_array, i))
poi = (top + bottom) / 2
if zone_type == 1
for i = 0 to [Link](box_array) - 1
level_to_break = box.get_top([Link](box_array,i))
// if [Link](close, level_to_break)
if close >= level_to_break
copied_box = [Link]([Link](box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top([Link](box_array,i)) +
box.get_bottom([Link](box_array,i))) / 2
box.set_top([Link](bos_array,0), mid)
box.set_bottom([Link](bos_array,0), mid)
box.set_extend( [Link](bos_array,0), [Link])
box.set_right( [Link](bos_array,0), bar_index)
box.set_text( [Link](bos_array,0), 'BOS' )
box.set_text_color( [Link](bos_array,0), bos_label_color)
box.set_text_size( [Link](bos_array,0), [Link])
box.set_text_halign( [Link](bos_array,0), text.align_center)
box.set_text_valign( [Link](bos_array,0), text.align_center)
[Link]([Link](box_array, i))
[Link]([Link](label_array, i))
if zone_type == -1
for i = 0 to [Link](box_array) - 1
level_to_break = box.get_bottom([Link](box_array,i))
// if [Link](close, level_to_break)
if close <= level_to_break
copied_box = [Link]([Link](box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top([Link](box_array,i)) +
box.get_bottom([Link](box_array,i))) / 2
box.set_top([Link](bos_array,0), mid)
box.set_bottom([Link](bos_array,0), mid)
box.set_extend( [Link](bos_array,0), [Link])
box.set_right( [Link](bos_array,0), bar_index)
box.set_text( [Link](bos_array,0), 'BOS' )
box.set_text_color( [Link](bos_array,0), bos_label_color)
box.set_text_size( [Link](bos_array,0), [Link])
box.set_text_halign( [Link](bos_array,0), text.align_center)
box.set_text_valign( [Link](bos_array,0), text.align_center)
[Link]([Link](box_array, i))
[Link]([Link](label_array, i))
for i = 0 to [Link](box_array) - 1
box.set_right([Link](box_array, i), bar_index + 100)
//
//END FUNCTIONS
//
//
//CALCULATIONS
//
stratRes = [Link] ? [Link]([Link] * intRes,
'###M') :
[Link] ? [Link]([Link] * intRes,
'###W') :
[Link] ? [Link]([Link] * intRes,
'###D') :
[Link] ? [Link]([Link] * intRes,
'####') :
'60'
src = h ? [Link]([Link]([Link]),
[Link], close, lookahead = barmerge.lookahead_off) : close
// CALCULATE ATR
atrValue = [Link](50)
f_extend_box_endpoint(current_supply_box)
f_extend_box_endpoint(current_demand_box)
// if [Link]
// [Link](x = bar_index + 10, y = close[1], text =
[Link]( [Link](current_supply_poi) ))
// [Link](x = bar_index + 20, y = close[1], text =
[Link]( box.get_bottom( [Link](current_supply_box, 0))))
// [Link](x = bar_index + 30, y = close[1], text =
[Link]( box.get_bottom( [Link](current_supply_box, 1))))
// [Link](x = bar_index + 40, y = close[1], text =
[Link]( box.get_bottom( [Link](current_supply_box, 2))))
// [Link](x = bar_index + 50, y = close[1], text =
[Link]( box.get_bottom( [Link](current_supply_box, 3))))
// [Link](x = bar_index + 60, y = close[1], text =
[Link]( box.get_bottom( [Link](current_supply_box, 4))))
// // Get Components
// ocAvg = [Link](open, close)
// sma1 = [Link](close, 5)
// sma2 = [Link](close, 6)
// sma3 = [Link](close, 7)
// sma4 = [Link](close, 8)
// sma5 = [Link](close, 9)
// sma6 = [Link](close, 10)
// sma7 = [Link](close, 11)
// sma8 = [Link](close, 12)
// sma9 = [Link](close, 13)
// sma10 = [Link](close, 14)
// sma11 = [Link](close, 15)
// sma12 = [Link](close, 16)
// sma13 = [Link](close, 17)
// sma14 = [Link](close, 18)
// sma15 = [Link](close, 19)
// sma16 = [Link](close, 20)
// psar = [Link](0.02, 0.02, 0.2)
[_, upperKC1, lowerKC1] = [Link](close, 80, 10.5)
[_, upperKC2, lowerKC2] = [Link](close, 80, 9.5)
[_, upperKC3, lowerKC3] = [Link](close, 80, 8)
[_, upperKC4, lowerKC4] = [Link](close, 80, 3)
barsL = 10
barsR = 10
pivotHigh = fixnan([Link](barsL, barsR)[1])
pivotLow = fixnan([Link](barsL, barsR)[1])
source = close, period = 150
[s, a, i] = lr_slope(source, period)
[upDev, dnDev] = lr_dev(source, period, s, a, i)
// // Colors
// green = #00d9ff, green2 = #00d9ff
// red = #ff0090, red2 = #ff0090
// // Plots
// k1 = plot([Link](upperKC1, 50), "k1", na, editable = false)
// k2 = plot([Link](upperKC2, 50), "k2", na, editable = false)
// k3 = plot([Link](upperKC3, 50), "k3", na, editable = false)
// k4 = plot([Link](upperKC4, 50), "k4", na, editable = false)
// k5 = plot([Link](lowerKC4, 50), "k5", na, editable = false)
// k6 = plot([Link](lowerKC3, 50), "k6", na, editable = false)
// k7 = plot([Link](lowerKC2, 50), "k7", na, editable = false)
// k8 = plot([Link](lowerKC1, 50), "k8", na, editable = false)
// fill(k1, k2, channelBal ? [Link](red2, 40) : na, editable = false)
// fill(k2, k3, channelBal ? [Link](red2, 65) : na, editable = false)
// fill(k3, k4, channelBal ? [Link](red2, 90) : na, editable = false)
// fill(k5, k6, channelBal ? [Link](green2, 90) : na, editable = false)
// fill(k6, k7, channelBal ? [Link](green2, 65) : na, editable = false)
// fill(k7, k8, channelBal ? [Link](green2, 40) : na, editable = false)
//Functions
//Line Style function
get_line_style(style) =>
out = switch style
'???' => line.style_solid
'----' => line.style_dashed
' ' => line.style_dotted
float ob = na
[Link](ob_top, top)
[Link](ob_btm, btm)
[Link](ob_avg, avg)
ob := ob_val
[Link](ob_top, idx)
[Link](ob_btm, idx)
[Link](ob_avg, idx)
[Link](ob_left, idx)
mitigated
//Global elements
var os = 0
var target_bull = 0.
var target_bear = 0.
/////////////////////////////////////////////
// Create non-repainting security function
rp_security(_symbol, _res, _src) =>
[Link](_symbol, _res, _src[[Link] ? 1 : 0])
// Main Indicator
// Functions
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = [Link]([Link](x - x[1]), t)
smoothrng = [Link](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) => ([Link](len) - [Link](len)) * perc / 100
securityNoRep(sym, res, src) => [Link](sym, res, src, barmerge.gaps_off,
barmerge.lookahead_on)
swingPoints(prd) =>
pivHi = [Link](prd, prd)
pivLo = [Link] (prd, prd)
last_pivHi = [Link](pivHi, pivHi, 1)
last_pivLo = [Link](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 = [Link] * (
[Link] ? 1 :
[Link] ? 1. :
[Link] ? 60. * 24 :
[Link] ? 60. * 24 * 7 :
[Link] ? 60. * 24 * 30.4375 : na)
f_kc(src, len, sensitivity) =>
basis = [Link](src, len)
span = [Link](len)
[basis + span * sensitivity, basis - span * sensitivity]
wavetrend(src, chlLen, avgLen) =>
esa = [Link](src, chlLen)
d = [Link]([Link](src - esa), chlLen)
ci = (src - esa) / (0.015 * d)
wt1 = [Link](ci, avgLen)
wt2 = [Link](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 = [Link](fractalTop, src[2], 0)[2]
highPrice = [Link](fractalTop, high[2], 0)[2]
lowPrev = [Link](fractalBot, src[2], 0)[2]
lowPrice = [Link](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 = [Link](2 , "S/R Strength", 1, group="SR")
lineStyle = [Link]("Dotted", "Line Style", ["Solid", "Dotted", "Dashed"],
group="SR")
lineWidth = [Link](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 = [Link](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 = [Link](rb, rb)
pl = [Link] (rb, rb)
sr_levels = array.new_float(21, na)
prdhighest = [Link](prd)
prdlowest = [Link](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 = [Link](close, 28)
//rsiOb = rsi > 78 and rsi > [Link](rsi, 10)
//rsiOs = rsi < 27 and rsi < [Link](rsi, 10)
rsiOb = rsi > 65 and rsi > [Link](rsi, 10)
rsiOs = rsi < 35 and rsi < [Link](rsi, 10)
dHigh = securityNoRep([Link], "D", high [1])
dLow = securityNoRep([Link], "D", low [1])
dClose = securityNoRep([Link], "D", close[1])
ema = [Link](close, 144)
emaBull = close > ema
equal_tf(res) => [Link](res) == f_chartTfInMinutes() and not
[Link]
higher_tf(res) => [Link](res) > f_chartTfInMinutes() or [Link]
too_small_tf(res) => ([Link] and res=="1") or ([Link] and
[Link](res) < 10)
securityNoRep1(sym, res, src) =>
bool bull_ = na
bull_ := equal_tf(res) ? src : bull_
bull_ := higher_tf(res) ? [Link](sym, res, src, barmerge.gaps_off,
barmerge.lookahead_on) : bull_
bull_array = request.security_lower_tf([Link], higher_tf(res) ?
[Link](f_chartTfInMinutes()) + ([Link] ? "S" : "") :
too_small_tf(res) ? ([Link] ? "3" : "10") : res, src)
if [Link](bull_array) > 1 and not equal_tf(res) and not higher_tf(res)
bull_ := [Link](bull_array)
[Link](bull_array)
bull_
// TF1Bull = securityNoRep1([Link], "1" , emaBull)
// TF3Bull = securityNoRep1([Link], "3" , emaBull)
// TF5Bull = securityNoRep1([Link], "5" , emaBull)
// TF15Bull = securityNoRep1([Link], "15" , emaBull)
// TF30Bull = securityNoRep1([Link], "30" , emaBull)
// TF60Bull = securityNoRep1([Link], "60" , emaBull)
// TF120Bull = securityNoRep1([Link], "120" , emaBull)
// TF240Bull = securityNoRep1([Link], "240" , emaBull)
// TF480Bull = securityNoRep1([Link], "480" , emaBull)
// TFDBull = securityNoRep1([Link], "1440", emaBull)
// [wt1, wt2] = wavetrend(close, 5, 10)
// [wtDivBear1, wtDivBull1] = f_findDivs(wt2, 15, -40)
// [wtDivBear2, wtDivBull2] = f_findDivs(wt2, 45, -65)
// wtDivBull = wtDivBull1 or wtDivBull2
// wtDivBear = wtDivBear1 or wtDivBear2
////////////////////////////////////////////////////////
// === BASE FUNCTIONS ===
// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len, offSig, offALMA) =>
v1 = [Link](src, len) // Simple
v2 = [Link](src, len) // Exponential
v3 = 2 * v2 - [Link](v2, len) // Double Exponential
v4 = 3 * (v2 - [Link](v2, len)) + [Link]([Link](v2, len), len) // Triple
Exponential
v5 = [Link](src, len) // Weighted
v6 = [Link](src, len) // Volume Weighted
v7 = 0.0
sma_1 = [Link](src, len) // Smoothed
v7 := na(v7[1]) ? sma_1 : (v7[1] * (len - 1) + src) / len
v8 = [Link](2 * [Link](src, len / 2) - [Link](src, len),
[Link]([Link](len))) // Hull
v9 = [Link](src, len, offSig) // Least Squares
v10 = [Link](src, len, offALMA, offSig) // Arnaud Legoux
v11 = [Link](v1, len) // Triangular (extreme smooth)
// SuperSmoother filter
// 2013 John F. Ehlers
a1 = [Link](-1.414 * 3.14159 / len)
b1 = 2 * a1 * [Link](1.414 * 3.14159 / len)
c2 = b1
c3 = -a1 * a1
c1 = 1 - c2 - c3
v12 = 0.0
v12 := c1 * (src + nz(src[1])) / 2 + c2 * nz(v12[1]) + c3 * nz(v12[2])
type == 'EMA' ? v2 : type == 'DEMA' ? v3 : type == 'TEMA' ? v4 : type ==
'WMA' ? v5 : type == 'VWMA' ? v6 : type == 'SMMA' ? v7 : type == 'HullMA' ? v8 :
type == 'LSMA' ? v9 : type == 'ALMA' ? v10 : type == 'TMA' ? v11 : type == 'SSMA' ?
v12 : v1
// plotcandle(
// open, high, low, close,
// title = 'plotcandle',
// color = close > open ? [Link](120, 9, 139) : [Link](69, 155, 225),
// wickcolor = close > open ? [Link](120, 9, 139) : [Link](69, 155, 225))
// if sell
// //[Link]("Long" , alert_message = i_alert_txt_exit_long)
// [Link]("Short" , [Link], alert_message =
i_alert_txt_entry_short)
// alert(message = "SHort position")
//#endregion }
// ——————————— <↑↑↑ G_SCRIPT01 ↑↑↑>
//<triggers>
lxTrigger = false
sxTrigger = false
leTrigger = [Link] (closeSeriesAlt, openSeriesAlt)
seTrigger = [Link](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 = [Link] (1, 'Level TP1' , group
= G_RISK,
tooltip = T_LVL)
i_lxQtyTP1 = [Link] (50, 'Qty TP1' , group
= G_RISK,
tooltip = T_QTY)
i_lxLvlTP2 = [Link] (1.5, 'Level TP2' , group
= G_RISK,
tooltip = T_LVL)
i_lxQtyTP2 = [Link] (30, 'Qty TP2' , group
= G_RISK,
tooltip = T_QTY)
i_lxLvlTP3 = [Link] (2, 'Level TP3' , group
= G_RISK,
tooltip = T_LVL)
i_lxQtyTP3 = [Link] (20, 'Qty TP3' , group
= G_RISK,
tooltip = T_QTY)
i_lxLvlSL = [Link] (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 = [Link] (true, 'Alert Labels On/Off' , group
= G_DISPLAY)
i_barColOn = [Link] (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
// ——————————— <strategy_calls> {
//<long orders>
if strategy.position_size <= 0 and longE and [Link]
[Link](
'Long',
[Link],
alert_message = i_leMsg,
comment = 'LE')
if strategy.position_size > 0 and condition == 1.0
[Link](
id = 'LXTP1',
from_entry = 'Long',
qty_percent = i_lxQtyTP1,
limit = tp1Line,
stop = slLine,
comment_profit = 'LXTP1',
comment_loss = 'SL',
alert_profit = i_lxMsgTP1,
alert_loss = i_lxMsgSL)
if strategy.position_size > 0 and condition == 1.1
[Link](
id = 'LXTP2',
from_entry = 'Long',
qty_percent = i_lxQtyTP2,
limit = tp2Line,
stop = slLine,
comment_profit = 'LXTP2',
comment_loss = 'SL',
alert_profit = i_lxMsgTP2,
alert_loss = i_lxMsgSL)
if strategy.position_size > 0 and condition == 1.2
[Link](
id = 'LXTP3',
from_entry = 'Long',
qty_percent = i_lxQtyTP3,
limit = tp3Line,
stop = slLine,
comment_profit = 'LXTP3',
comment_loss = 'SL',
alert_profit = i_lxMsgTP3,
alert_loss = i_lxMsgSL)
if longX
[Link](
'Long',
alert_message = i_lxMsg,
comment = 'LX')
//<short orders>
if strategy.position_size >= 0 and shortE and [Link]
[Link](
'Short',
[Link],
alert_message = i_leMsg,
comment = 'SE')
if strategy.position_size < 0 and condition == -1.0
[Link](
id = 'SXTP1',
from_entry = 'Short',
qty_percent = i_sxQtyTP1,
limit = tp1Line,
stop = slLine,
comment_profit = 'SXTP1',
comment_loss = 'SL',
alert_profit = i_sxMsgTP1,
alert_loss = i_sxMsgSL)
if strategy.position_size < 0 and condition == -1.1
[Link](
id = 'SXTP2',
from_entry = 'Short',
qty_percent = i_sxQtyTP2,
limit = tp2Line,
stop = slLine,
comment_profit = 'SXTP2',
comment_loss = 'SL',
alert_profit = i_sxMsgTP2,
alert_loss = i_sxMsgSL)
if strategy.position_size < 0 and condition == -1.2
[Link](
id = 'SXTP3',
from_entry = 'Short',
qty_percent = i_sxQtyTP3,
limit = tp3Line,
stop = slLine,
comment_profit = 'SXTP3',
comment_loss = 'SL',
alert_profit = i_sxMsgTP3,
alert_loss = i_sxMsgSL)
if shortX
[Link](
'Short',
alert_message = i_sxMsg,
comment = 'SX')
// ——————————— <visuals>
c_tp = leTrigger or seTrigger ? na :
condition == 0.0 ? na : [Link]
c_entry = leTrigger or seTrigger ? na :
condition == 0.0 ? na : [Link]
c_sl = leTrigger or seTrigger ? na :
condition == 0.0 ? na : [Link]
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 :[Link]([Link], 90))
fill(
p_entryLine, p_slLine,
color = leTrigger or seTrigger ? na :[Link]([Link], 90))
//<alerts labels>
plotshape(
i_alertOn and longE,
title = 'Long',
text = 'Long',
textcolor = [Link],
color = [Link],
style = [Link],
size = [Link],
location = [Link])
plotshape(
i_alertOn and shortE,
title = 'Short',
text = 'Short',
textcolor = [Link],
color = [Link],
style = [Link],
size = [Link],
location = [Link])
plotshape(
i_alertOn and (longX or shortX) ? close : na,
title = 'Close',
text = 'Close',
textcolor = [Link],
color = [Link],
style = [Link],
size = [Link],
location = [Link])
l_tp = i_alertOn and (longTP1 or shortTP1) ? close : na
plotshape(
l_tp,
title = "TP1 Cross",
text = "TP1",
textcolor = [Link],
color = [Link],
style = [Link],
size = [Link],
location = [Link])
plotshape(
i_alertOn and (longTP2 or shortTP2) ? close : na,
title = "TP2 Cross",
text = "TP2",
textcolor = [Link],
color = [Link],
style = [Link],
size = [Link],
location = [Link])
plotshape(
i_alertOn and (longTP3 or shortTP3) ? close : na,
title = "TP3 Cross",
text = "TP3",
textcolor = [Link],
color = [Link],
style = [Link],
size = [Link],
location = [Link])
plotshape(
i_alertOn and (longSL or shortSL) ? close : na,
title = "SL Cross",
text = "SL",
textcolor = [Link],
color = [Link],
style = [Link],
size = [Link],
location = [Link])
//<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 ↑↑↑>
[Link](
f_qDq(a_slLine,
[Link](
entryIndex,
slLine,
last_bar_index + l_right,
slLine,
style = line.style_solid,
color = c_sl)))
[Link](
f_qDq(a_entryLine,
[Link](
entryIndex,
entryLine,
last_bar_index + l_right,
entryLine,
style = line.style_solid,
color = [Link])))
[Link](
f_qDq(a_tp3Line,
[Link](
entryIndex,
tp3Line,
last_bar_index + l_right,
tp3Line,
style = line.style_solid,
color = c_tp)))
[Link](
f_qDq(a_tp2Line,
[Link](
entryIndex,
tp2Line,
last_bar_index + l_right,
tp2Line,
style = line.style_solid,
color = c_tp)))
[Link](
f_qDq(a_tp1Line,
[Link](
entryIndex,
tp1Line,
last_bar_index + l_right,
tp1Line,
style = line.style_solid,
color = c_tp)))
[Link](
f_qDq(a_slLabel,
[Link](
last_bar_index + l_right,
slLine,
'SL: ' + [Link](slLine, '##.###'),
style = label.style_label_left,
textcolor = [Link],
color = c_sl)))
[Link](
f_qDq(a_entryLabel,
[Link](
last_bar_index + l_right,
entryLine,
'Entry: ' + [Link](entryLine, '##.###'),
style = label.style_label_left,
textcolor = [Link],
color = [Link])))
[Link](
f_qDq(a_tp3label,
[Link](
last_bar_index + l_right,
tp3Line,
'TP3: ' + [Link](tp3Line, '##.###'),
style = label.style_label_left,
textcolor = [Link],
color = c_tp)))
[Link](
f_qDq(a_tp2label,
[Link](
last_bar_index + l_right,
tp2Line,
'TP2: ' + [Link](tp2Line, '##.###'),
style = label.style_label_left,
textcolor = [Link],
color = c_tp)))
[Link](
f_qDq(a_tp1label,
[Link](
last_bar_index + l_right,
tp1Line,
'TP1: ' + [Link](tp1Line, '##.###'),
style = label.style_label_left,
textcolor = [Link],
color = c_tp)))
//#endregion }
// ——————————— <↑↑↑ G_SCRIPT02 ↑↑↑>
// ——————————— <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 ↑↑↑>