2-steps entry with 50% of equity per trade

Hi all, I am trying to write codes for a short-only strategy with 2-steps entry, and each with 50% of equity per trade. The logics is simple, when ShortSignal_2 is in effective (market not in panic), I will enter short position with 50% of equity per this trade, and then I will wait for ShortSignal_1 (if market in panic, as advised by high VHSI level) to be in effective. If this will happen, I will enter another short trade position with the remaining 50% of equity per trade. All the trades close by their own stop loss and take profit mechanism rather than closing at the same time.

I tried to set the backtest mode to "backtestRegularRawMulti" in order to be able to execute more than 1 position when the short signal is still in effective, but the result generated seem only reflect only one trade (position) is entered throughout the history.

On the other hand, I understood that I currently did not set the order for entry 1 and then entry 2. I looked up the "PositionScore" function and is currently looking for a more efficient way to do so. Does anyone can point me how I should look for? Thanks.

//Backtesting Only Code will not plot any signals

_SECTION_BEGIN("Simple RSI Momentum Long Only Strategy");

SetOption("MaxOpenPositions", 2); //This sets maximum number of open positions to 2
PositionSize = -50; // invest 50% of portfolio equity in signle trade

VHSI = Foreign("VHSI","Close");

marketpanic = VHSI > Optimize("VHSI level", 30,22,40,3);
notmarketpanic = NOT marketpanic;

//Trading Logic
RSI_param = Optimize("rsi_param",5,5,10,5);
RSI_threshold = Optimize("rsi_threshold",40,40,45,5);
EMA_param = Optimize("ema_param",50,50,55,5);
Close_param = Optimize("close_param",-21,-26,-21,5);

ShortSignal_1 = RSI(RSI_param) < RSI_threshold and Ref(RSI(RSI_param),-1) > RSI_threshold and (EMA(Close,EMA_param) < ref(EMA(Close,EMA_param),-1))  AND marketpanic;
ShortSignal_2 = RSI(RSI_param) < RSI_threshold and Ref(RSI(RSI_param),-1) > RSI_threshold and (EMA(Close,EMA_param) < ref(EMA(Close,EMA_param),-1))  AND notmarketpanic;
SL_above_previous_high = Ref(High,-1) * 1.02;
CoverSignal = H > SL_above_previous_high;
CoverPrice = IIf(CoverSignal==1, Max(O, Ref(High,-1)*1.02), C);
//CoverPrice = Max(0, Ref(High,-1)*1.02);

Short = ShortSignal_1 OR ShortSignal_2;
Cover = Coversignal;

ApplyStop(stopTypeLoss,	stopModePercent, Optimize( "max. loss stop level", 3, 2, 30, 5 ),1);
//ApplyStop( stopTypeNBar, stopModeBars,Optimize( "num of days to stop",17,5,30,5 ),1);

//ApplyStop( stopTypeTrailing, stopModePercent, SL_above_previous_high ,1);

ApplyStop( stopTypeProfit, stopModePercent, Optimize("profit stop",20,1,30,5),1);


SetStopPrecedence( stopTypeNBar, stopTypeTrailing, stopTypeLoss, stopTypeProfit );

//Position Size
//PositionSize = MarginDeposit = 1;



Plot( Close,"Price",colorBlack,styleBar);
Plot(SL_above_previous_high , "trailing stop line", colorRed );

AddColumn( ShortSignal_1, "ShortSignal_1", 1, colorDefault, IIf( ShortSignal_1, colorGreen, colorDefault ) );
AddColumn( ShortSignal_2, "ShortSignal_2", 1, colorDefault, IIf( ShortSignal_2, colorGreen, colorDefault ) );

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.