0% found this document useful (0 votes)
24 views10 pages

Pine Code

The document contains source code for the 'Vivek Equity Tool', a trading indicator designed for use in financial analysis. It includes inputs for various moving averages, calculations for buy/sell conditions, and customizable visual elements such as colors and alerts. The code is structured for use in the TradingView platform, utilizing Pine Script version 5.

Uploaded by

winy60
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views10 pages

Pine Code

The document contains source code for the 'Vivek Equity Tool', a trading indicator designed for use in financial analysis. It includes inputs for various moving averages, calculations for buy/sell conditions, and customizable visual elements such as colors and alerts. The code is structured for use in the TradingView platform, utilizing Pine Script version 5.

Uploaded by

winy60
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Copy of Tab 2

// This source code is subject to the terms of the Mozilla Public License 2.0 at
[Link]
// © Vivek_AlfaTraders

//@version=4
study​ (title = "Vivek Equity Tool", shorttitle = "Equity", overlay = true)
// --------- Inputs
i_showEmas​ = input(defval = true,​ title = "=========== EMAs ============")
i_maSrc​ ​ = input(defval = close, title = "EMA Source")
i_maFast1​ = input(defval = 10,​ title = "EMA Fast 1")
i_maFast2​ = input(defval = 20,​ title = "EMA Fast 2")
i_maLen​ ​ = input(defval = 40,​ title = "SMA Length")
i_rangeLen​ = input(defval = 0.618, title = "Range Length",​ ​ ​ type =
[Link])
i_currentT​ = input(defval = true,​ title = "Use Current Time?")
i_tf​ ​ = input(defval = "D",​ title = "Selec Diferent Timeframe", type = [Link])
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([Link], 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​ ​ = "Entry",
textcolor​ = c_white,
color​ ​ = c_green100,
transp​ = 0,
style​ ​ = [Link],
size​ ​ = [Link],
location​ = [Link])
plotshape(
i_showAlert and f_sell ? low : na,
title​ ​ = "Sell Label",
text​ ​ = "Exit",
textcolor​ = c_white,
color​ ​ = c_red100,
transp​ = 0,
style​ ​ = [Link],
size​ ​ = [Link],
location​ = [Link])
plotshape(
i_showAlert and f_close ? close : na,
title​ ​ = "Close Label",
text​ ​ = "Close",
textcolor​ = c_orange,
color​ ​ = c_orange,
transp​ = 0,
style​ ​ = [Link],
size​ ​ = [Link],
location​ = [Link])
plotshape(
i_showAlert and f_GCross ? f_maTrend : na,
title​ ​ = "Golden Cross Label",
text​ ​ = "LB",
textcolor​ = c_white,
color​ ​ = c_green,
transp​ = 0,
style​ ​ = [Link],
size​ ​ = [Link],
location​ = [Link])
plotshape(
i_showAlert and f_DCross ? f_maTrend : na,
title​ ​ = "Death Cross Label",
text​ ​ = "LS",
textcolor​ = c_white,
color​ ​ = c_orange,
transp​ = 0,
style​ ​ = [Link],
size​ ​ = [Link],
location​ = [Link])

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​ ​ = "Entry Alert",
message​ = "Entry Alert")
alertcondition(
f_sell,
title​ ​ = "Exit Alert",
message​ = "Exit 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")
@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0
at [Link]
// © Vivek_AlfaTraders//HSH

//@version=5
indicator(title='Vivek Equity Tool', shorttitle='Equity', overlay=true)
// --------- Inputs
i_showEmas = input(defval=true, title='=========== EMAs ============')
i_maSrc = input(defval=close, title='EMA Source')
i_maFast1 = input(defval=10, title='EMA Fast 1')
i_maFast2 = input(defval=20, title='EMA Fast 2')
i_maLen = input(defval=40, title='SMA Length')
i_rangeLen = input(defval=0.618, title='Range Length')
i_currentT = input(defval=true, title='Use Current Time?')
i_tf = [Link](defval='D', title='Selec Diferent Timeframe')
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 = [Link](i_maSrc, i_maFast1)
f_maFast2 = [Link](i_maSrc, i_maFast2)
f_maTrend = i_currentT ? [Link](i_maSrc, i_maLen) :
[Link]([Link], i_tf, [Link](i_maSrc, i_maLen))
f_chBasis = [Link](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 = [Link](f_maFast2, f_maTrend)
f_DCross = [Link](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', color=c_maFast, transp=80)
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, transp=90)

// --------- Alerts
plotshape(i_showAlert and f_buy ? high : na, title='Buy Label', text='Entry',
textcolor=c_white, color=c_green100, style=[Link], size=[Link],
location=[Link], transp=0)
plotshape(i_showAlert and f_sell ? low : na, title='Sell Label', text='Exit',
textcolor=c_white, color=c_red100, style=[Link], size=[Link],
location=[Link], transp=0)
plotshape(i_showAlert and f_close ? close : na, title='Close Label',
text='Close', textcolor=[Link](c_orange, 0), color=[Link](c_orange, 0),
style=[Link], size=[Link], location=[Link])
plotshape(i_showAlert and f_GCross ? f_maTrend : na, title='Golden Cross
Label', text='LB', textcolor=[Link](c_white, 0), color=[Link](c_green,
0), style=[Link], size=[Link], location=[Link])
plotshape(i_showAlert and f_DCross ? f_maTrend : na, title='Death Cross Label',
text='LS', textcolor=[Link](c_white, 0), color=[Link](c_orange, 0),
style=[Link], size=[Link], location=[Link])

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='Entry Alert', message='Entry Alert')
alertcondition(f_sell, title='Exit Alert', message='Exit 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')

You might also like