Am using a simple stochastic RSI + macd strategy to trade intraday. The backtest results are good but the actual results don't match with backtests. In fact the results are very different to the backtest results.
Have done code checking and its fine and the code doesn't reference future quotes.
I save amibroker scan results to a text file and then use python to trade thru broker API. I place bracket orders when a signal is generated thru amibroker. Exits are when stoploss or targets are hit and I don't use amibroke exit signals. Python code is on 10 sec loop and amibroker scan is 1 min loop. Am trading on 15 min timeframe. Have also tried on 5 min but results vary there as well.
Request seniors to help and guide as am new to amibroker.
Here is my code:
_SECTION_BEGIN("Stoch 15 min Cross");
SetChartOptions(0,chartShowArrows|chartShowDates);
FirstTradeTime = 100000; // Earliest time to take a trade
LastTradeTime = 143000; // Latest time to take new trades
ExitAllPositionsTime = 150000; // Exit all trades
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
Hist = ml-sl;
MACDN = (Hist < Ref (Hist,-1)) AND Hist < 5 ;
periods = Param( "Periods", 14, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
k15 = StochK( periods , Ksmooth);
d15 = StochD( periods , Ksmooth, DSmooth );
k15_1 = Ref (k15,-1);
k15_2 = Ref (k15,-2);
d15_1 = Ref (d15,-1);
C12= Cross(d15_1,k15_1) AND ((k15_1<k15_2)) AND IIf((d15_1-k15_1)>(1.1),1,0) AND k15>10 ;
Short = (C12 AND MACDN) AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Cover = (TimeNum() >= ExitAllPositionsTime);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
Capital = 2000000;
Risk = 1000;
filepath = "Z:\Downloads\stocks\222.txt";
fh = fopen( filepath, "a", True );
if ( fh )
{
lastbuyDT = LastValue( ValueWhen(Short, DateTime() ) ) ;
str5= StrLeft(DateTimeToStr( lastBuyDT ),5);
str2= StrTrim(str5,"/");
str3 = StrRight(DateTimeToStr( lastBuyDT ),11);
str4= StrTrim(StrLeft(str3,8)," ");
str1 = str2+str4;
str6= StrTrim(NumToStr(Close)," ");
fputs( Name() +";short;" + str2+";"+ str4 + ";"+ str6 + "\n", fh );
// close file handle
fclose( fh );
}
else
{
_TRACE("Failed to open the file");
}
capital = Optimize ("Capital",16000,70000,200000,10000);
SetPositionSize (capital, spsValue);
_SECTION_END();