Converted Cost Basis and Trailing Stop calculations to functions.
Added options to input exiting quantity and cost basis. If you use these options, you have to set the date to "TODAY"s date or it will not function as expected.
This will also allow a trader to "Start Over" and have the script recalculate new buy/sell points moving forward if they miss any of the buy or sell signals.
Made a minor change to the trailing take profit calculation.
Major update to the algo. I have given the user the opportunity to manipulate the time frame that the different algos operate on. I am only able to give the user the ability to change the time frame for the normal buy algo and the dca/buy the dip algo. I am not able to give the user the ability to change time frame of the take profit/trailing take profit due to the complexity of the function to calculate everything. As such, it is recommended that you create the alert on the time frame that you want the Take Profit/Trailing Take Profit to take effect. This workaround gives the user the ability to manipulate all 3 algos time frames.
I have also reorganized the configuration options/settings to make it more obvious which algo is being manipulated by the user.
I have defaulted the normal buy algo to "1D" timeframe which should capture a stock in an uptrend and DCA/Buy the Dip Algo to the "120" try to capture intraday lows. This may be tweaked by the user and results will vary.
For manipulating the Take Profit/Trailing Take Profit, your main chart resolution will determine the frequency of updates/alerts. The lower the time frame, the tighter more frequent the stops will be. I recommend this be the lowest time frame of all 3. You do not want the other two time frames to be lower than this time frame.
There are many articles about issues accessing time frames lower than the charts actual time frame.