The strategy you have built uses an EMA20 (an exponential moving average indicator with a period of 20) and a stochastic oscillator.
At the beginning, you have set up the parameters for the stochastic oscillator, which consists of %K and %D parameters. %K measures the current market rate for an asset, and %D is a moving average of %K.
Then you calculate the values of %K and %D based on the historical prices of the asset (close, high, low).
Next, the 20-period EMA is calculated.
After this, you plot the EMA20 on the chart.
Then you define the conditions for entering a long position (buying) and exiting the position (selling).
You will enter a position when:
You will exit the position when:
According to this strategy, you might invest when the market has been oversold and is now starting a trend upwards. And you would sell off your investment when the trend is about to return downwards again.
Please remember that all trading strategies come with risks and should be used wisely.
/*backtest start: 2022-09-01 00:00:00 end: 2023-09-07 00:00:00 period: 4h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // © dragolite95 //@version=5 strategy("Simple EMA20 Strat", overlay=true, margin_long=100, margin_short=100) periodK = input.int(14, title="%K Length", minval=1) smoothK = input.int(1, title="%K Smoothing", minval=1) periodD = input.int(3, title="%D Smoothing", minval=1) k = ta.sma(ta.stoch(close, high, low, periodK), smoothK) d = ta.sma(k, periodD) ema = ta.ema(close, 20) plot(series=ema, title="ema 20", color=color.blue) if(low > ema and k > d and ema > ema[20]) strategy.entry("long", strategy.long) if(close < ema) strategy.close("long")