Algorithmic Trading Strategy Using Three Moving Averages & Python

#Python #Stocks #StockTrading #AlgorithmicTrading
Algorithmic Trading Strategy Using Three Moving Averages & Python

⭐Please Subscribe !⭐

⭐Get the code and data sets by becoming a supporter on Patreon:


⭐Support the channel on Patreon:

⭐Helpful Programming Books
► Python (Hands-Machine-Learning-Scikit-Learn-TensorFlow):

Similar Posts

36 thoughts on “Algorithmic Trading Strategy Using Three Moving Averages & Python
  1. i came back to this video . have an issue with the strategy. if your only doing long then there would 2 buy and sell markers. if your doing shorts 2 additional signals are needed. look at the strategy more closely.

  2. Ahhhhhh, excellent point (and silly oversight on my part). I do have a question regarding that last block of code. When I attempted to run it, I received the following error message:

    AttributeError Traceback (most recent call last)

    /usr/local/lib/python3.7/dist-packages/matplotlib/ in convert_units(self, x)

    1572 try:

    -> 1573 ret = self.converter.convert(x, self.units, self)

    1574 except Exception as e:

    22 frames

    AttributeError: 'numpy.float64' object has no attribute 'toordinal'

    The above exception was the direct cause of the following exception:

    ConversionError Traceback (most recent call last)

    /usr/local/lib/python3.7/dist-packages/matplotlib/ in convert_units(self, x)

    1574 except Exception as e:

    1575 raise munits.ConversionError('Failed to convert value(s) to axis '

    -> 1576 f'units: {x!r}') from e

    1577 return ret


    ConversionError: Failed to convert value(s) to axis units: masked_array(data=[–, –, –, –, –, –, –, –, –, –, –, –, –, –,

    –, –, –, –, –, –, –, –, –, –, –, –, –, –,

    –, –, –, –, –, –, –, –, –, –, –, –, –, –,

    –, –, –, –, –, –, –, –, – etc., etc.

    I prompted the issue on stack overflow. However, I figured I'd ask the source as well. Do you have any suggestions as to how I can go about resolving this issue? I am very new to this, so I apologize for my "rookie-ness".

  3. Really great stuff. One thing I feel compelled to point is the fact that your end of 2019 stock prices are off. TESLA was trading in the $70-90 range at that time. I'm sure you (and others) have picked up on that. Other than that price range issue, this tutorial is a fantastic learning aid/tool for newbies like myself.

  4. df['Buy'] = buy_sell_function(df)[0]
    df['Sell'] = buy_sell_function(df)[1]

    what does the index 0 and 1 mean here?
    And I tried to put 2, why does it gives me a traceback?

  5. it seems you are getting your signals from historical data. what is the sense of that? there is no predictive power whatsoever or am I missing something fundamental?

  6. Hello, Thanks for the good video. You should confirm the EMA input signal additionally, eg MACD. This can eliminate a large number of missed inputs.

    On entry, set STOP LOSS to the previous minimum (buy) and previous maximum (sell). This way, you will evaluate the profitability of all entries (buy and sell).

  7. Tips : you can use "command"+"D"' to duplicate the line or for multiple line instead of copy past.
    can please someone help me with this Error knowing that i import stream data using this 

    *df = web.DataReader('AAPL', data_source='yahoo', start=('2020-01-01'), end=(*

    Traceback (most recent call last):
    File "/Users/–/Desktop/Language/python/___Project4/Ema'", line 80, in <module>
    File "/Users/–/Desktop/Language/python/___Project4/Ema'", line 63, in buy_sell_function

    IndexError: list index out of range

  8. Excellent video, can you also make a video as an add on to this video to calculate the portfolio based on long and short position and also set up a n alert to notify about buyl and sell. It will be a good addition to already great content that you are uploading on this channel everyday!

  9. The first sell marker price was about $ 315 ?? . Python Plot cant show the precise value when the arrow pointed at the curve. On the other side, Excel can show the value if the arrow was pointed at the curve .

  10. Excellent Work!!.. and you need to add the details about those all lines in the chart man.. the output in the chart is not categorized.. which is price line and which all are the EMA lines.. anyhow great work

  11. 9:40
    Its Showed me an error and I don't know how to fix it here is the code :

    Please help me

    #Calculate the three moving averages

    #Calculate the short/ fast exponential moving average

    ShortEMA = df.Close.ewm(span=5, adjust = False).mean()

    #Calculate the Middle/Medium exponential moving average

    MiddleEMA = df.Close.ewm(span=21, adjust = False).mean()

    #Calculate the long/slow exponential moving average

    LongEMA = df.Close.ewm(span=63, adjust = False).mean()

  12. Thanks for all recent videos about various strategies!
    Now i think we need the next step, namely how to calculate the winnings and losses after plotting the strategy.

  13. Help Please, this code not work for me:

    #Add the Buy and Sell signals to the data set
    df['Buy'] = buy_sell_function(df)[0]
    df['Sell'] = buy_sell_function(df)[1]
    ValueError Traceback (most recent call last)
    <ipython-input-25-5f2589dcc654> in <module>()
    1 #Add the Buy and Sell signals to the data set
    —-> 2 df['Buy'] = buy_sell_function(df)[0]
    3 df['Sell'] = buy_sell_function(df)[1]
    3 frames
    /usr/local/lib/python3.6/dist-packages/pandas/core/internals/ in sanitize_index(data, index, copy)
    610 if len(data) != len(index):
    –> 611 raise ValueError("Length of values does not match length of index")
    613 if isinstance(data, ABCIndexClass) and not copy:
    ValueError: Length of values does not match length of index

Leave a Reply

Your email address will not be published. Required fields are marked *