Hello ,
There are some issues with your code. I'm not a expert, but maybe this helps you.
I didn't correct your formula ... only where are some obvious problems with the code.
IF you use the Errormessages in the Pine-Editor window ( bellow) .. then you will see where the problem is.
First !!! You didn't used Pine //@version=5
You wrote //@version 5 ... for this reason the Pine Editor thought you are creating Code for Pine //@version=1
The right instruction for unsing PineScript Version 5 --> // @version=5
When you decleare a veriable with a input then you need to say witch variable should be created with this Input ... so right is .. length = input.int (title=Length of EMAs
, defval20) ...
you neet the quotes, this was several times not used in Methods of you.
There was several other issues with the Namespace where you not said to the system where he should take the funktion ... ta.crossover ... crossover allone not working ... then you used crossabove .. this is not a existing method.
You will find the full help in the Reference Manual for Pinescript on Tradingview.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Werner_Stiegler
//@version=5
strategy(20 EMA & 50 EMA Crossover with Stochastic RSI Filter
)
length = input.int (title=Length of EMAs
, defval=20)
oversold = input.int (title=Oversold level
, defval=20)
overbought = input.int (title=Overbought level
, defval=80)
// calculate the exponential moving averages
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
// calculate the stochastic RSI
rsi = ta.rsi(close, 14)
//k = ta.stoch(rsi, 3) -- Stoch benötigt mehr Parameter
// d = ta.sma(k, 3) --> when K with Stochastic variable is working then this could work when you give the right amound of criterias to the SMA function.
// long entry conditions
// long_entry = crossover(ema20, ema50) and crossunder(k, oversold) ... --> // needs the namespace ta.crossover !!! then works with the right criteria
// long exit conditions
// long_exit = crossabove(k, overbought) --> corssabove not exists !!! ta.crossunder ??
// short entry conditions
// short_entry = crossunder(ema20, ema50) and crossabove(k, overbought) --> Namespace ta.crossunder / ta.crossover
// short exit conditions
// short_exit = crossunder(k, oversold) // --> Namespace ta.crossunder
// plot the long entry and exit signals
//plot(long_entry ? close : na, title=Long Entry
, style=plot.style_circles, color=color.green, linewidth=3)
// plot(long_exit ? close : na, title=Long Exit
, style=plot.style_circles, color=color.red, linewidth=3)
// plot the short entry and exit signals
//plot(short_entry ? close : na, title=Short Entry
, style=plot.style_circles, color=color.red, linewidth=3)
//plot(short_exit ? close : na, title=Short Exit
, style=plot.style_circles, color=color.green, linewidth=3)
// create overlay to display on the chart
plot(ema20, title=20 EMA
, color=color.yellow)
plot(ema50, title=50 EMA
, color=color.blue)