Hello, how are you?
I would appreciate some help with this question.
I want to design a system for indices but I have read that the analysis and the signals must be generated with the indices instead of the ETFs (because the latter can be accumulation, distribution, etc. and can generate false signals) but that then I must operate on the ETFs (which in the end, is what is operable since the indices themselves cannot be bought or sold). I hope I am explaining myself well.
With this, starting from this simple AFL:
_SECTION_BEGIN("Sistema MA");
SetBacktestMode( backtestRegular );
//Analysis Settings
SetOption( "InitialEquity", 10000 );
SetOption( "AllowPositionShrinking", True );
PosQty = 1;
SetOption("MaxOpenPositions", PosQty );
PositionSize = -100/PosQty;
RoundLotSize = 1;
SetTradeDelays(1,0,0,0);
// Entrada y Salida
Buy = Cross(Close, WMA(Close,30));
Sell = Cross(WMA(Close,30),Close);
Short=Cover=0;
_SECTION_END();
How can I make it analyze and generate the signals in the $SPX index but operate on the SPY ETF?
After tinkering around a bit, I also created this other AFL and it seems to get what I want, but I'm not sure.
Could this be what I'm looking for? Or is there a different way to do it?
_SECTION_BEGIN("Sistema MA");
SetBacktestMode( backtestRegular );
//ANALYSIS SETTINGS - Manda el AFL sobre las pestañas
SetOption( "InitialEquity", 10000 );
SetOption( "AllowPositionShrinking", True );
PosQty = 1;
SetOption("MaxOpenPositions", PosQty );
PositionSize = -100/PosQty;
RoundLotSize = 1;
SetTradeDelays(1,0,0,0);
// Obtener los datos del índice $SPX
SPX_Close = Foreign("$SPX", "C"); // Precio de cierre del índice SPX
SPX_WMA30 = WMA(SPX_Close, 30); // Media móvil ponderada de 30 periodos del SPX
// Generar señales de compra y venta usando el $SPX
Buy = Cross(SPX_Close, SPX_WMA30); // Compra cuando el SPX cruza sobre su WMA30
Sell = Cross(SPX_WMA30, SPX_Close); // Venta cuando el SPX cruza por debajo de su WMA30
Short=Cover=0;
_SECTION_END();
Thank you very much in advance.