Search
Products
Community
Markets
News
Brokers
More
EN
Get started
Community
/
Ideas
/
ali
Bitcoin
ali
By morvarid_rayaneh
Follow
Follow
Aug 6, 2022
0
Aug 6, 2022
//
version
=4
// Indicator to combines:
study (title = "Golden cross", shorttitle = "GD cross", overlay = true)
// --------- Inputs
i_showEmas = input(defval = true, title = "=========== EMAs ============")
i_maSrc = input(defval = close, title = "EMA Source")
i_maFast1 = input(defval = 12, title = "EMA Fast 1")
i_maFast2 = input(defval = 50, title = "EMA Fast 2")
i_maLen = input(defval = 200, title = "SMA Length")
i_rangeLen = input(defval = 0.618, title = "Range Length", type = input.float)
i_currentT = input(defval = true, title = "Use Current Time?")
i_tf = input(defval = "D", title = "Selec Diferent Timeframe", type = input.resolution)
i_showCh = input(defval = false, title = "Show Channel")
i_showbarCol = input(defval = true, title = "Show Bar Color")
i_showAlert = input(defval = true, title = "Show Alert")
// --------- Calculations
f_maFast1 = ema(i_maSrc, i_maFast1)
f_maFast2 = ema(i_maSrc, i_maFast2)
f_maTrend = i_currentT ?
sma(i_maSrc, i_maLen) :
security(syminfo.tickerid, i_tf,
sma(i_maSrc, i_maLen) )
f_chBasis = atr(i_maLen) * i_rangeLen
f_chTop = f_maTrend + f_chBasis
f_chBot = f_maTrend - f_chBasis
f_range = ((open <= f_chTop) or (close <= f_chTop)) and
((open >= f_chBot) or (close >= f_chBot))
f_GCross = crossover (f_maFast2, f_maTrend)
f_DCross = crossunder (f_maFast2, f_maTrend)
f_dirTrend = f_range ? 0 :
i_maSrc >= f_maTrend ? 1 : -1
// Set initial values
f_condition = 0
f_buyCond = f_dirTrend == 1 and f_maFast1 > f_maFast2
f_sellCond = f_dirTrend == -1 and f_maFast1 < f_maFast2
f_buyCloseCo = f_dirTrend == 1 and f_maFast1 < f_maFast2
f_sellCloseC = f_dirTrend == -1 and f_maFast1 > f_maFast2
f_closeCond = f_buyCloseCo or f_sellCloseC
//Conditions
f_condition := f_condition[1] != 1 and f_buyCond ? 1 :
f_condition[1] != -1 and f_sellCond ? -1 :
f_condition[1] != 0 and f_closeCond ? 0 :
nz(f_condition[1])
f_buy = f_condition == 1 and f_condition[1] != 1
f_sell = f_condition == -1 and f_condition[1] != -1
f_close = f_condition[1] != 0 and f_closeCond
// --------- Colors
c_orange = #f57f17 //Orange
c_green = #006400 //Green
c_green100 = #006400FF//Green 100%
c_greenLight = #388e3c //Green Light
c_red = #8B0000 //Red
c_red100 = #8B0000FF//Red 100%
c_redLight = #b71c1c //Red Light
c_white = #ffffff //White
c_gray = #808080 //Gray
c_maFast = f_range ? c_orange :
f_buyCloseCo ? c_orange :
f_sellCloseC ? c_orange :
f_dirTrend == 1 ? c_green :
f_dirTrend == -1 ? c_red : na
c_maTrend = f_dirTrend == 0 ? c_orange :
f_dirTrend == 1 ? c_green100 :
f_dirTrend == -1 ? c_red100 : na
c_ch = f_dirTrend == 0 ? c_orange :
f_dirTrend == 1 ? c_green :
f_dirTrend == -1 ? c_red : na
c_barCol = f_dirTrend == 0 ? c_orange :
f_dirTrend == 1 and (open <= close) ? c_green100 :
f_dirTrend == 1 and (open > close) ? c_greenLight :
f_dirTrend == -1 and (open >= close) ? c_red100 :
f_dirTrend == -1 and (open < close) ? c_redLight : na
// --------- Plots
p_maFast1 = plot(
f_maFast1,
title = "EMA Fast 1",
color = c_maFast,
linewidth = 1)
p_maFast2 = plot(
f_maFast2,
title = "EMA Fast 2",
color = c_maFast,
linewidth = 2)
fill(
p_maFast1,
p_maFast2,
title = "EMAs Fill",
transp = 80,
color = c_maFast)
plot(
f_maTrend,
title = "SMA Trend",
color = c_maTrend,
linewidth = 3)
p_chTop = plot(
i_showCh ? f_chTop : na,
title = "Top Channel",
color = c_maTrend,
linewidth = 1)
p_chBot = plot(
i_showCh ? f_chBot : na,
title = "Bottom Channel",
color = c_maTrend,
linewidth = 1)
fill(
p_chTop,
p_chBot,
title = "Channel",
color = c_ch)
// --------- Alerts
plotshape(
i_showAlert and f_buy ? high : na,
title = "Buy Label",
text = "Buy",
textcolor = c_white,
color = c_green100,
transp = 0,
style = shape.labelup,
size = size.normal,
location = location.belowbar)
plotshape(
i_showAlert and f_sell ? low : na,
title = "Sell Label",
text = "Sell",
textcolor = c_white,
color = c_red100,
transp = 0,
style = shape.labeldown,
size = size.normal,
location = location.abovebar)
plotshape(
i_showAlert and f_close ? close : na,
title = "Close Label",
text = "Close",
textcolor = c_orange,
color = c_orange,
transp = 0,
style = shape.xcross,
size = size.small,
location = location.absolute)
plotshape(
i_showAlert and f_GCross ? f_maTrend : na,
title = "Golden Cross Label",
text = "Golden\nCross",
textcolor = c_white,
color = c_orange,
transp = 0,
style = shape.labelup,
size = size.normal,
location = location.absolute)
plotshape(
i_showAlert and f_DCross ? f_maTrend : na,
title = "Death Cross Label",
text = "Death\nCross",
textcolor = c_white,
color = c_orange,
transp = 0,
style = shape.labeldown,
size = size.normal,
location = location.absolute)
barcolor(
i_showbarCol ? c_barCol : na)
alertcondition(
f_buy or f_sell or f_close or f_GCross or f_DCross,
title = "Alert",
message = "Alert")
alertcondition(
f_buy,
title = "Buy Alert",
message = "Buy Alert")
alertcondition(
f_sell,
title = "Sell Alert",
message = "Sell Alert")
alertcondition(
f_close,
title = "Close Alert",
message = "Close Alert")
alertcondition(
f_GCross,
title = "Golden Cross Alert",
message = "Golden Cross Alert")
alertcondition(
f_DCross,
title = "Death Cross Alert",
message = "Death Cross Alert")
Crab
morvarid_rayaneh
Follow
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the
Terms of Use
.