Hi,
Here are some observations re: your code:
1. It's positively not surprising that short trades are never triggered. Likely because you didn't code them. ;) SellAtLimit exits from long positions whereas your intention was to use ShortAt* instead. Strike F11 key to load the QuickRef and see the proper syntax of trading methods.
2. It's not clear to me why your supposed short entries have the "LastPosition" in them. Just in case I provided two versions of code:
a) long-only system that uses SellAtLimit as exits and
b) trading from the short side as well.
3. The main (trading) loop should start at least from
GetTradingLoopStartBar(Per20 * 3), not bar==1. For the whys and whereabouts please refer to the WealthScript Programming Guide > Indicators > Stability of Indicators.
4. To understand the handling of multiple positions, check out the same Guide > Programming Trading Strategies > Multi-Position Strategies.
a) CODE:
Please log in to see this code.
b)CODE:
Please log in to see this code.