Posts

Showing posts from January, 2022

SMA Trading Strategy Using Python

Image
This strategy works on the basic logic that whenever the 30 Day Simple Moving Average is greater than the closing price of the stock it gives a Buy signal and whenever the 30 Day SMA is smaller than the closing price then it gives a sell signal. This way we get a clear understanding of when to place a buy order and when to exit our position. I've built this strategy using python and here is the program and logic for the strategy. #import libraries import  pandas  as  pd import  numpy  as  np import  matplotlib.pyplot  as  plt plt.style.use ( 'fivethirtyeight' ) #Load data from  google.colab  import  files files.upload () #Store the data df = pd.read_csv ( 'HDFC.NS.csv' ) #set date as index df = df.set_index ( pd.DatetimeIndex ( df [ 'Date' ] .values )) #show data df #visualize the close price plt.figure ( figsize= ( 16 , 8 )) plt.title ( 'Close Pri...