Hi Tomasz,
Thank you for your reply. I tried a basic buy and hold / crossover system, the system works fine.
This is a system template I have been using, it was generating signals for a long time until last week, it stopped generating buy signals. I added in Buy=1; Sell=1; in case it was the reason buy no luck.
There must be a mistake somewhere I made. Appreciate if you can take a look.
// Backtest Setup
SetOption("InitialEquity", 250000); // Adjust this to match your starting equity. Also adjust in Explore Code at bottom. **Set to 1,000,000 when backtesting**
SetOption("MaxOpenPositions", 1000); // Use this to limit the maximum number of trades you are willing to take
SetOption("AccountMargin", 100); // Adjust the level of leverage here. 100 = No Leverage, 50 = Up to $2 exposure for every $1 of equity
SetOption("usecustombacktestproc", False);
SetOption("CommissionMode",1); // Set the commission mode according to how your broker charges you commissions on each trade
// Mode 1 - percent of trade
// Mode 2 - $ per trade
// Mode 3 - $ per share/contract
SetOption("CommissionAmount", 0.3); // Set commission amount here to match the commission mode you select above
SetOption("ActivateStopsImmediately",True);
SetBacktestMode(backtestRegular);
SetTradeDelays(1,1,1,1); // Trades are delayed by 1 bar. Signals executed on the next bar after the signal
BuyPrice = Open; // Buy stocks at the open of the bar following the signal
SellPrice = Open; // Sell stocks at the open of the bar following the signal
Buy = 1;
Sell = 1;
Short=Cover=0;
RoundLotSize = 100;
Index = Foreign(".SZSC","C",True);
MinimumTurnover = 30000000;
MAXTurnover = 150000000;
PercentPerTrade = 7;
IndexFilterBars = 30;
StockHighFilterBars = 50;
StopLoss = 9;
ActiveBars = 60;
EMALookBackPeriod = 9;
//ReentryDelay1 = Param("Reentry Delay", 0, 0, 20, 1);
//ProfitTakeDelay1 = Param("Profit Delay", 2, 0, 4, 1);
//PercentVolatilityPerTrade = Param("Volatility %", 0.5, 0.1,1,0.1);
// Trading Rules (Entry)
LiquidityFilter = EMA(C*V,5) > MinimumTurnover AND EMA(C*V,5) < MAXTurnover; // Require turnover in a range
IndexFilter = Index > EMA(Index,IndexFilterBars); // Index is above EMA(IndexFilterBars)
StockHighFilter = C == HHV(C,StockHighFilterBars); // The close of the stock is the highest it has been in "StockHighFilterBars" weeks
TradeBars = BarIndex() - NullCount( C, 1 ) + 1;
TradeBarsFilter = TradeBars > ActiveBars;
//************************************************************************************
//Buy = LiquidityFilter AND IndexFilter AND StockHighFilter AND StrFind(FullName()," ORD A"); //Original rules + Certain weeks of trading history
Buy = LiquidityFilter AND IndexFilter AND StockHighFilter AND TradeBarsFilter AND StrFind(FullName()," ORD A"); //Original rules + Certain weeks of trading history
PositionScore = MA(V,10)/V; //Take lowest relative volume trade
//PositionScore = (C-Ref(C,-10))/ATR(10);
//PositionScore = C/Ref(C,-26);
//***************************************
// Trading Rules (Exit)
//Function for Simple Looping Trailing Stop - Only moves up until exit triggered then resets
function TrailingStopClose(data) // This function defines the trailing stop
{
stop[0] = data[0]; // Set first bar's stop value
for (i = 1; i < BarCount; i++) // Loop through all other bars
{
if (Close[i] >= stop[i-1]) // If not stopped out yet
stop[i] = Max(data[i], stop[i-1]); // Set stop level for this bar
else // Else if is stopped out now
stop[i] = data[i]; // Reset to current value of stop data
} // End of for loop
return stop; // Return trailing stop array
} // End of function
PercentTrail = StopLoss / 100;
//TrailingStopExit = TrailingStopClose(C - TrailingMultiple * Ref(ATR(14),-1));
TrailingStopExit = TrailingStopClose(C-C*PercentTrail); // Call the TrailingStopClose function and tell it to use 'C-C*PercentTrail' as the trailing stop value
ExitRule1 = TrailingStopExit < Ref(TrailingStopExit,-1);
ExitRule2 = Ref(EMA(C,EMALookBackPeriod),-1)>EMA(C,EMALookBackPeriod); //Security EMA trend down exit rule
//Sell = TrailingStopExit < Ref(TrailingStopExit,-1) OR SellEmaTrendDown; //Test new added rule of security EMA rule
//Sell = ExitRule1;
Sell = ExitRule1 OR ExitRule2;
// COMPOUNDING 1
SetPositionSize(PercentPerTrade,spsPercentOfEquity); // % of Equity per trade