Backtesting problem

Hi!

I have made a backtest that using daily data.

For one parameter I would like to use Monthly data.
If the Close of an index(^OMX) is below the 12 monthly simple moving average, I would not take the trade.

I use the code below.

MAOMX1 = TimeFrameCompress(FOREIGN("^OMX","Close"), inMonthly );
MAOMX = ma(MAOMX1,12);
var5 = IIf(MAOMX < FOREIGN("^OMX","Close"),1,0);
RES3 = IIf(A3 == 1 AND var5 == 1 AND A3 == 1,100,0);
MAOMX1 = TimeFrameExpand(MAOMX1, inMonthly);

I cant get this function to work.
Does anyone has an idea how I can solve this problem.

Best regards,

Leif Axelsson
Sweden

First of all please use code tags.
This is not your first day and not your first post on this forum.
I don't understand this ignorance.
(BTW another important one here).


As for your code lines... you check a compressed array against an uncompressed array in this line

var5 = IIf(MAOMX < FOREIGN("^OMX","Close"),1,0);

Instead it should be

var5 = IIf(MAOMX < MAOMX1,1,0);

If you want to use var5 later then you should not forget about expanding it (e.g if instead you want to check MAOMX against shorter time frame's ^OMX symbol's price).

so e.g.

OMX = FOREIGN("^OMX","Close"); // OMX's price of shorter interval

MAOMX1 = TimeFrameCompress(OMX, inMonthly );// compressed array
MAOMX = MA(MAOMX1,12);// compressed array

// Expansion
MAOMX1 = TimeFrameExpand(MAOMX1, inMonthly);// monthly OMX expanded
MAOMX_expanded = TimeFrameExpand(MAOMX, inMonthly);// monthly OMX's MA expanded

var5 = IIf(MAOMX_expanded < OMX,1,0);// monthly OMX's MA compared with OMX's price of shorter interval

The rest of your code as well as variables such as A3 are unknown. So....

1 Like

Hi!

Many thanks, Your code worked.

/Leif