In my trading, I like to manually enter my trade orders and allow the software to exit them. This type of "one-time-only" algorithmic trading is not natively supported by WealthabPro. For this to work, the strategy must be either long or short the security in order to place an exit trade and then switch off so no further live trades are placed.
The following example code creates this functionality. Be aware that the algorithm does not know if a trade has actually occurred in your account. Moreover, if you use stops to exit a trade, as in this example code, they can be canceled in your account during a bar update, while the algorithm shows the exit on the chart, you may not have exited the trade in your account. Unfortunately, this happens quite frequently and it is a direct result of WealthlabPro being decoupled from your account, and the fact that Fidelity will reject an order if the price is at or on the exit side of your stop order.
The code as presented supports two modes of entry, manual or algorithmic, and three modes of exit for both long and short positions. It works on any timeframe. The sliders "LongExitMode" and "ShortExitMode" are normally in the off state at value 0. To enable algorithmic exit after a manual trade entry first turn off streaming mode using the bottom left button, select one of the three exit strategies on the appropriate slider, and re-enable streaming. You will see the algorithm is automatically long or short your position and that an exit alert has been generated. If "Auto-place" is enabled and you are in "Live Trade Mode" this Alert will be a alive order. Once the exit condition is met the appropriate slider is reset to zero and no further orders will be generated.
The code supplied here is for information purposes only and it is the responsibility of the user to test it before risking real money. I would encourage those that use it to post back their algorithm trading ideas.I feel that the ability to enter trades on a "onetime only basis" and know that you have software managing them affords the opportunity to go find other trades and to profitably trade fast-changing markets.
Let's get people using WLP, would hate to see it disappear.
CODE:
Please log in to see this code.