Back to Community
Beginner - Moving Average stationary points Algorithm

HI, so i'm trying to make an algorithm that uses a 20 day moving average and buys the asset when the moving average moves from a negative gradient to a positive one ie at a local minima, and then uses the next maxima as a signal to sell the asset. I'm pretty unsure about how to register gradients though of the moving average to implement this. Does anyone have any suggestions on how to did this. Thanks in advance!

2 responses

How about this. Let t = today and x = the quantity of interest.

gradient(t) = x(t) - x(t-1)
gradient(t-1) = x(t-1) - x(t-2)

if gradient(t-1) < 0 and gradient(t) > 0 : BUY
if gradient(t-1) > 0 and gradient(t) < 0 : SELL

Thanks Christian, will give it a try