//---------------------------------------------------------------------------------------------------------------------} //Functions //---------------------------------------------------------------------------------------------------------------------{ n = bar_index atr = nz(ta.atr(200))
tpsl(condition, opposite_condition, level, islong)=> var box tp_area = na var box sl_area = na var reached = false
if condition if islong if showTp tp_area := box.new(n, level + atr * tpMult, n, level, na, bgcolor = tpCss) if showSl sl_area := box.new(n, level, n, level - atr * slMult, na, bgcolor = slCss) else if showTp tp_area := box.new(n, level, n, level - atr * tpMult, na, bgcolor = tpCss) if showSl sl_area := box.new(n, level + atr * slMult, n, level, na, bgcolor = slCss)
reached := false
else if opposite_condition reached := true
if not reached tp_area.set_right(n) sl_area.set_right(n)
if islong if high > tp_area.get_top() or low < sl_area.get_bottom() reached := true else if low < tp_area.get_bottom() or high > sl_area.get_top() reached := true
reached
trailing_stop(trigger, trend, mult)=> var float ts = na var reached = false
if trigger ts := switch trend 1 => close - atr * mult 0 => close + atr * mult
reached := false else ts := switch trend 1 => close - ts > atr * mult ? close - atr * mult : ts 0 => ts - close > atr * mult ? close + atr * mult : ts
if close < ts and trend == 1 reached := true else if close > ts and trend == 0 reached := true
[ts, reached]
filter(a, b)=> a - b > atr * filterWidth
//---------------------------------------------------------------------------------------------------------------------} //Signals //---------------------------------------------------------------------------------------------------------------------{ var line bull_line = na var bool bull_lvl_reached = na var line bear_line = na var bool bear_lvl_reached = na
var os = 0
//Bullish Signals bull = low[3] > high[1] and close[2] < low[3] and close > low[3] and filter(low[3], high[1]) and showBull
//Set bullish tpsl zones if bull //Imbalance area box.new(n-3, low[3], n, high[1], na, bgcolor = color.new(bullCss, 50)) avg = math.avg(low[3], high[1])
//Imbalance area average if bullAvg bull_line := line.new(n, avg, n, avg, color = bullCss, style = line.style_dashed)
//---------------------------------------------------------------------------------------------------------------------} //Plots //---------------------------------------------------------------------------------------------------------------------{ barcolor(ts_reached ? na : os == 1 and not bull_reached ? bullCss : os == 0 and not bear_reached ? bearCss : na)
plot(ts, 'Trailing Stop', ts_reached or bull or bear ? na : os ? bullCss : bearCss)
ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יוכלו להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אבל השימוש החוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.
רוצה להשתמש בסקריפ זה בגרף?
כתב ויתור
המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.