BBands Breakout Strategy : Multi-Positions Issues

Posted By: Sage

BBands Breakout Strategy : Multi-Positions Issues - 12/03/21 17:03

Hello! I am backtesting a BBands breakout strategy. Found out that Zorro enters a new position every time a breakout happens regardless if the previous positions are closed or not meanwhile I need only one position at a time till the position either closes in loss or profit. What I need is a simple reverse strategy

Here is the code for the strategy. I just need the code to prevent multi-positions till a reverse happens



function run()
{
set(LOGFILE);
StartDate = 20050101;
EndDate = 20210101;
BarPeriod = 1440;
LookBack = 200;


vars Close = series(priceClose());
vars Prices = series(price());


BBands(Prices,50,2,2,MAType_SMA);
vars upperBand = series(rRealUpperBand);
vars lowerBand = series(rRealLowerBand);


if (crossOver(Close, upperBand)) enterLong();
else if (crossUnder(Close, lowerBand)) enterShort();

}

Attached picture Forum.PNG
Posted By: MegaTanker

Re: BBands Breakout Strategy : Multi-Positions Issues - 12/03/21 21:30

Set MaxLong and MaxShort to 1, then Zorro will not open multiple trades in the same direction
Posted By: Sage

Re: BBands Breakout Strategy : Multi-Positions Issues - 12/03/21 23:03

Perfect! It works. Thanks
© 2024 lite-C Forums