Hello,
I have tried to implement sigScale In in my codes according to Example 1 from the following entry: Portfolio-level back testing .However, I am unable to make it work. Take the following simple code as an example:
BuyCondition1 = RSI(2) < 20;
BuyCondition2 = RSI(2) < 10;
SellCondition = RSI(2) > 65;
Buy = IIf(BuyCondition1, 1, IIf(BuyCondition2, sigScaleIn, 0));
Sell = SellCondition;
SetPositionSize(1, 4);
The system works fine for BuyCondition1, but I get no scaling for BuyCondition2.
I should appreciate it if you would let me know what I am doing wrong.
Best regards.
Buy Condition 1 will always be true whenever Buy Condition 2 is true. Therefore, your nested IIf will always set the Buy array to 1, not sigScaleIn. Try switching the order of the nesting to check for the most restrictive condition first.
2 Likes
mradtke,
Thank you for your prompt answer.
You are right, the problem was that BuyCondition2 is more restrictive than BuyCondition1. After switching the order, the code works as intended.
I set an additional ExRem condition to allow the code scaling just once (otherwise, it was scaling for every bar when Buycondition2 was true).
Best regards.
BuyCondition1 = RSI(2) < 20;
BuyCondition2 = RSI(2) < 10;
SellCondition = RSI(2) > 65;
DoScaleIn = ExRem(BuyCondition2, SellCondition);
Buy = IIf(BuyCondition2 AND DoScaleIn, sigScaleIn, IIf(BuyCondition1, 1, 0));
Sell = SellCondition;
SetPositionSize(1, 4);