Hi there, I've just started off with coding so everything is new to me. I am playing around with a simple BO strategy based on an EMA lineup and 30 day high.
The code is below
// Backtest Setup
SetOption( "InitialEquity", 250000);
SetOption("MaxOpenPositions", 1000);
SetOption("AccountMargin", 100);
SetOption("CommissionMode",1);
SetOption("CommissionAmount", 0.5);
SetBacktestMode(backtestRegular);
SetTradeDelays(1,1,1,1);
BuyPrice = O;
SellPrice = O;
Short = Cover = 0;
// Trading Rules
MA5 = EMA(C,5);
MA15 = EMA(C,15);
MA30 = EMA(C,30);
MA60 = EMA(C,60);
BuyRule1 = C==HHV(H,30);
MLU1 = C > MA5;
MLU2 = MA5 > MA15;
MLU3 = MA15 > MA30;
MLU4 = MA30 > MA60;
MALineup = MLU1 AND MLU2 AND MLU3 AND MLU4;
Green = C>O;
SellRule1 = 0;
shareprice = C>0.02;
Buy = MALineup AND BuyRule1 AND Green AND shareprice;
Sell = 0;
amount = 25; // 25% loss (trailing)
ApplyStop( stopTypeTrailing, stopModePercent, amount, True );
RiskPerShare = O - (O*0.75);
PercentRiskPerTrade = 2;
PctSize = PercentRiskPerTrade * BuyPrice / RiskPerSharetype
After running the backtest on my chosen samples I wanted to investigate whether the system was recognizing the entry signal. I was basically after the raw signals. I have noticed that the entry signal was absent in quite a few instances. Below is a screen capture where a signal (green arrow next to purple vertical line) is present on the 26/08/16. However, I was expecting for it to be generated already on the bar circled in red. I can't figure out why the signal was generated on the 26/08/19 and not earlier as the condition had been met unless which is probably the reason my code is wrong.