Learn how to code moving average strategy, and KDJ indicator to analyze and predict changes in stock trends and price patterns using pine script in Tradingview.
strategy("Yaonology Moving Average Tutoring", overlay=true, default_qty_type= strategy.percent_of_equity ,default_qty_value=100, currency=currency.USD, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0)
fst = input(title = “MA_Fast”, defval = 20)
slw = input(title = “MA_Slow”, defval = 40)
ma_fast = sma(close, fst)
ma_slow = sma(close, slw)
plot(ma_fast, color = color.blue)
plot(ma_slow, color = color.green)
if ma_fast > ma_slow
strategy.entry(id = “ma_long”, long = true)
if ma_slow > ma_fast
strategy.close(id = “ma_long”)
// KDJ Indicators
strategy(“Yaonology KDJ Indicators Tutorial”, overlay=false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, currency = currency.USD, initial_capital = 10000, commission_type = strategy.commission.percent, commission_value = 0)
prd = input(9, title=”period”)
sgnl = input(3, title=”signal”)
v(s,l,m) =>
v = 0.0
v := (m*s+(l-m)*nz(v[1]))/l
c = close
h = highest(high, prd)
l = lowest(low,prd)
RSV = 100*((c-l)/(h-l))
K = v(RSV, sgnl, 1)
D = v(K, sgnl, 1)
J = 3 * K-2 * D
plot(K, color = color.green)
plot(D, color = color.red)
plot(J, color = color.black)
if (K < 20 and D < 20 and J < 20 and K > D and K[1] < D[1]) or (J > 0 and J[1] < 0)
strategy.entry(id = “kd”, long = true)
if (K > 80 and D > 80 and J > 80 and K < D and K[1] > D[1]) or (J < 100 and J[1] > 100)
strategy.close(id = “kd”)
The function sets a number of strategy properties | |
Example | strategy(“Yaonology Moving Average Tutoring”, overlay=true, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, currency = currency.USD, initial_capital = 10000, commission_type = strategy.commission.percent, commission_value = 0) |
Details | overlay:
|
User can see and edit inputs on the Format Object dialog of the script study | |
Example | fst = input(title = “MA_Fast”, defval = “20”) |
Details | title title of the input defval default value of the input valuable |
The sma function returns the moving average | |
Example | ma_fast = sma(close, fst) |
Details | source(series) close : close price open: open price high: highest price lowe: lowest price length(integer) Number of bars |
Plots a series of data on the chart | |
Example | plot(ma_fast, color = color.blue) |
Details | source(series) Series of data to be plotted color color of the plot. color = color.red color = #ff001a color = close >= open ? color.green : color.red |
It is a command to enter market position | |
Example | strategy.entry(id = “ma_long”, long = true) |
Details | id A required parameter. The order identifier. long true: the strategy.entry for long false: the strategy.entry for short |
It is a command to exit from the entry with the specified ID. | |
Example | strategy.close(id = “ma_long”) |
Details | id A required parameter. The order identifier. |
Read Privacy Policy