Hi all, I am designing a short strategy which has a 2-steps entry. The first entry is when RSI < 40 and VHSI < 30 (The volatility index of Hang Seng Index), using only 50% of equity. Then, I would like when only the first entry has been entered, and RSI < 40 with VHSI > 30, then I will enter another trade with the remaining 50% of equity. All positions will be covered when meeting the "Cover" criteria.
However, I am not able to debug why the ScaleinEntry will be entered earlier than InitialEntry. It seems like the InitialEntry and ScaleinEntry are independent signal in my codes. I used the exploration function and saw the above phenomenon happened. For example, on 27/3/2001, there was a short action(ScaleInEntry) and without previous InitialEntry done. Could someone point me where I did wrong? Thanks.
MaxPos = 2; SetOption("InitialEquity",1000000); SetOption("MaxOpenPositions",MaxPos); RSI_display = RSIa(Close,5); EMA_display = EMA(Close,50); RSI_param = 5; RSI_threshold = 40; EMA_param = 50; VHSI = Foreign("VHSI","Close"); marketpanic = VHSI > 30 notmarketpanic = NOT marketpanic; Entry1 = RSI(RSI_param) < 40 AND notmarketpanic; Entry2 = RSI(RSI_param) < 40 AND marketpanic; SL_above_previous_high = Ref(High,-1) * 1.02; ExitSignal = H > SL_above_previous_high; Entry2 = ExRem(Entry2, ExitSignal); InitialEntry = Entry1; ScaleInEntry = Entry2; Short = IIf(InitialEntry, 1, IIf(ScaleInEntry, sigScaleIn,0)); Cover = ExitSignal; CoverPrice = IIf(Cover==1, Max(O, Ref(High,-1)*1.03), C); ApplyStop(stopTypeLoss, stopModePercent,3,1); ApplyStop( stopTypeNBar, stopModeBars,Optimize( "num of days to stop",17,5,30,1 ),1); //ApplyStop( stopTypeTrailing, stopModePercent, SL_above_previous_high ,1); ApplyStop( stopTypeProfit, stopModePercent, 20,1); //Position sizing EntryPosSize1 = 50; //Size for first entry EntryPosSize2 = 50; //Size for second entry PosSize = (Entry1 * EntryPosSize1) + (Entry2 * EntryPosSize2); SetPositionSize(PosSize,spsPercentOfEquity);