top of page

Buy-Sell Signals:
Exponential Moving Average(EMA)

The project creates buy and sell signals using 3 different EMA periods. The strategy is as follows:

Open Long position if:

- Fast and mid EMA's are above Slow EMA and fast EMA crosses above mid EMA

Open Short position if:

-Fast and mid EMA's are below slow EMA and fast EMA crosses below mid EMA

Close Long position if:

-Fast EMA crosses below mid EMA

Close Short position if:

-Fast EMA crosses above mid EMA

where;

Fast EMA is the shortest period and Slow EMA is the longest period.

Importing required libraries:

Screen Shot 2022-09-13 at 15.06.13.png

Getting historical data and calculating EMA's:

Screen Shot 2022-09-13 at 15.07.06.png

Defining the conditions for long positions:

Screen Shot 2022-09-13 at 15.07.30.png

Defining conditions for short positions:

Screen Shot 2022-09-13 at 15.08.35.png

Defining a function to plot the chart:

Screen Shot 2022-09-13 at 15.08.52.png

Final output where buy and sell signals are plotted along with the price chart

Tickers, timeframe, time interval and EMA periods could be changed as desired.

Screen Shot 2022-09-13 at 15.11.01.png
bottom of page