Index Type of Day Analysis


I am trying to figure out how to analyze different day of execution conditions, I have multiple strategies that detect a buy signal, and then execute the buy at open the next day.

What I want to do is test for multiple opening types of the $SPX index, up/down, bigup, bigdown etc

The only way I can think about doing this is using maybe a custom metric in the CBT?

Filters Results by:

SPX > 0.2%

SPX > 0.4%

SPX > 0.6%

SPX > 0.8%

SPX < -0.2%

SPX < -0.6%

SPX < -0.8%


Am I overcomplicating this, the other thought was to put an IF statement into the BuyPrice but don’t think this can be done?


percent = Optimize("percent (non-fractional)", 2, -8, 8, 2);

Exclude = AlmostEqual(percent, 0) OR AlmostEqual(percent, -4);

forgn = Foreign("$SPX", "C");
rc = ROC(forgn,1);
rc_cond = IIf(percent > 0, rc > percent/10, rc < percent/10);

SetOption("GenerateReport", 1);// force generation of full report 

Buy = rc_cond;

Thanks fxshrat, this is very helpful, and insightful code. Works perfectly.

Apart from the optimisation determines the performance of the strategy based on Index pricing the day the buy signal is detected, not the day the trade is executed. Forgive me, if this is my implementation.

For example:

Cond1 = Range < 0.5;
Cond2 = ADX(5) > 40;
Cond3 = C > MA(C,100);
Cond4 = rc_cond;
BuySetUp = Cond1 AND Cond2 AND Cond3 AND Cond4; 

Buy = Ref(BuySetUp,-1);

As a futher explanation, I have list of trades from the strategy, from day before, and I need to decide to whether I turn the strategy on based where the Index is pricing the following day, so it's less an actual strategy, more answering a hypothetical question.

Something like this:

Current is

BuyPrice = Open;

It would be somthing like (if this worked)?

BuyPrice = IIF(rc_cond, Open, Not Open / False);


Yes, if you want to enter on next day open then you can add delay via Ref() function as you did.
So it is a technically correct way.

If rc_cond is false then there is no Buy entry since you connected each Buy condition via AND operator.
So doing this BuyPrice = IIF(rc_cond, Open, Not Open / False); does not make sense.
(Besides Buy signal has delay but rc_cond in Buyprice line doesn't have one)

1 Like

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