I'm testing the code below on weekly data with a time period set to 1/1/2016 - 12/31/2025. It consistently makes trades before 2016 and the equity chart goes all the way back to 1995 (my max data from Norgate). I've tested a lot of systems in the last few months and never had this issue before.
I added the qualifier Status("barinrange") to the buy and sell signals in an attempt to fix it but the error persists.
Any advice you have on how to fix this issue would be much appreciated.
/*
Core Plus Satellites Trading System
Simple rotation using built-in AmiBroker ranking
...System holds one "core" index ETF and then allocates remaining capital
to other sector or industry ETFs in a Watchlist based on simple trend following
entry criteria and momentum.
WEEKLY DATA ONLY - Set Analysis Periodicity to WEEKLY
*/
SetTradeDelays(1, 1, 1, 1);
BuyPrice = Open;
SellPrice = Open;
// Include my custom functions
#include <KS_functions.afl>
// ========================================
// PARAMETERS
// ========================================
SetOption("MaxOpenPositions", 4);
SetOption("WorstRankHeld", 3);
SetPositionSize(15, spsPercentOfEquity);
WatchlistName = ParamStr("Watchlist Name", "_SecNav2");
CoreSymbol = ParamStr("Core Holding", "SPY");
MALength = Param("MA Length", 10, 5, 50, 1);
MomPeriod = Param("Momentum Period", 26, 10, 52, 1);
// Find watchlist
WatchlistNum = -1;
for(i = 0; i < 256; i++)
{
if(CategoryGetName(categoryWatchlist, i) == WatchlistName)
{
WatchlistNum = i;
break;
}
}
InWL = InWatchList(WatchlistNum);
IsCore = Name() == CoreSymbol;
// ========================================
// WEEKLY INDICATORS
// ========================================
MA10 = MA(C, MALength);
Mom = ROC(C, MomPeriod);
// ========================================
// ENTRY/EXIT LOGIC
// ========================================
if(IsCore)
{
// Core: Always hold
Buy = Status("barinrange");
Sell = 0;
PositionScore = 1000000; // Highest priority
SetPositionSize(55, spsPercentOfEquity);
}
else if(InWL AND NOT IsCore)
{
// Satellites: Above MA, positive momentum
Buy = C > MA10 AND Mom > 0 AND Status("barinrange");
Sell = C < MA10;
// Rank by momentum
PositionScore = Mom;
}
else
{
// Not in system
Buy = Sell = 0;
PositionScore = 0;
}