Range Data and Backtest

Good morning, a little help with this please.
I have read a post where it is indicated that the date range is applied to the Backtest but not to the generation of signals and if you want to avoid this, you should use: inrange= Status("barinrange"); but I have not managed to do it well.
I attach a simple code to Buy when the price crosses the WMA30. I want it to show the signals from the start date of my Backtest (01/01/24) but as the system gives a Buy signal on 06/11/23 and the price does not close below the WMA30 again, this signal that should be given on 05/08/24 does not appear.
Please, how can I make it not take into account the signals prior to the date range of my backtest?
Thank you very much

The AFL code:

_SECTION_BEGIN("Sistema WMA30 Semanal");

// 1. TIPO DE SISTEMA [SIEMPRE]
SetBacktestMode( backtestRegular ); 

// 5. BACKTESTER SETTINGS [SIEMPRE]
SetOption( "InitialEquity", 30000 ); // Establecemos el tamaño total de la cartera, el Capital Inicial
SetTradeDelays(0,0,0,0); //Compra y Vende el mismo día de la señal (sin retrasos)
SetOption("CommissionMode", 2); // El Mode 2 es: $ per trade
SetOption( "CommissionAmount", 1 ); // Establecemos las comisiones de entrada y de salida: 1$
BuyPrice = SellPrice = Close; // Utilizará el Close como precio
Short=Cover=0;  // No permitimos cortos

// 8. TAMAÑO DE LA POSICIÓN [SIEMPRE]
// Posición variable en función de la curva de capital (reinvirtiendo beneficios)
SetPositionSize( 100, spsPercentOfEquity);  // Para 1 posición, el 100%

// 9. CÁLCULO INDICADORES [SIEMPRE]
SPX=Foreign("$SPX","C");//En el AFL cogerá los datos del índice pero el backtest lo pasaré sobre el ETF SPY (del que aplicaré las características)
MediaPonderada = WMA(SPX,30);

// 10. REGLAS DEL SISTEMA [SIEMPRE]
CruceAlcista = Cross(SPX,MediaPonderada);// Cruce Alcista 
CruceBajista = Cross(MediaPonderada, SPX); // Cruce Bajista
Buy = CruceAlcista;
Sell = CruceBajista;
BuyPrice = SellPrice = Close;// Qué precio usará, en este caso el Close
Short=Cover=0;  // No permitimos cortos

_SECTION_END();


Did you try ?


Buy = CruceAlcista AND Status("barinrange");

Hi awilson, thank you very much for your answer.
I have tried it but when I put the backtest with a start date of 01/01/2024, the Purchase that should be made on 05/08/24 still does not appear.
It seems that the system continues to take into account the Purchase that is made on 06/11/23.
I have been able to "half solve" it with:
CruceAlcista = Open<WMA(C,30) AND Close>WMA(C,30);
CruceBajista = Open>WMA(C,30) AND Close<WMA(C,30);
But I'm not sure if I'm doing it right.

When you bactest you set to current symbol
Which symbol did you use ?
Did you enable Pad Align option in Analysis settings ?

Hi awilson,
yes, $SPX, yes.
But I solve this problem, thank you very much.

ok, now I see

the reason you do not see a Buy signal in 20224 using Cross is because there is NO cross in 2024.
The last cross was 10/11/2023

https://www.amibroker.com/guide/afl/cross.html

2 Likes

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