So far I've been able to successfully code my 'in-person' manual swing trading strategies on a handpicked basket of stocks. Normally, for each stock traded I use charts from Google Finance to visually inspect the chart and parameterize MACD settings specific to each stock. Its also worth nothing that I view stocks in the 1-month, 30-minute interval view and manually fit MACD values that produce crossovers at my desired entry and exit points. There are no mathematic optimizations involved and I only hold long positions until a sell signal has been reached.
In the example algorithm attached, I focused on the stock AMD, emulating how to trade in real life. Here are some considerations in the logic of my algorithm:
- Long Positions only (utilizing Robinhood)
- Produce charting data that is similar to my view in Google Finance (1-month window, 30-minute intervals)
- Calculate MACD values using TA-LIB
- Trade on MACD crossovers - if 'MACD_hist > 0' then BUY, if 'MACD < 0' then SELL
Essentially the meat of the algorithm is described in pseudo-code below:
Start_of_Day (before_trading_start):
traded_today_stock1 = False
traded_today_stock2 = False
traded_today_stock3 = False
etc...
Every_minute (handle_data)
macd_function_stock1
macd_function_stock2
macd_function_stock3
etc...
macd_function_stock1(context, data)
talib_calculate_MACD_variables
if MACD crossover positive and not traded today:
BUY
traded_today_stock1 = True
elif MACD crossover negative and not traded today:
SELL
traded_today_stock1 = True
Essentially, the results of the backtest reveal that as the MACD parameters are tuned correctly, the algorithm works so long as you are staying updated on the stock's volatility. This post was meant for other programming noobs transitioning from technical or fundamental trading to automated algorithmic trading. Any questions or comments are highly appreciated!