Review Req.- Backtesting Shows Short Trade Time and Huge Profit

Hello everyone,

I've been working an Amibroker script recently and would appreciate some guidance from the experienced members here.

The script shown promising results in terms of increased profit during backtesting. However, I've observed that the trade time is only 5 minutes, which seems unusual to me and raises some questions about the accuracy of my modifications.

I'm reaching out to the community to seek your expertise in reviewing the modified script. If there are any mistakes in my code or if you notice anything abnormal in the results, your insights would be invaluable.

Additionally, if the script is deemed fine after your review, I'm curious to know whether it's advisable to use it for live trading. Are there any specific considerations or precautions I should be aware of before implementing it in a live trading environment?

Below, I've included the relevant sections of the modified script for your reference:

_SECTION_BEGIN("Trading System");

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartOptions(0,chartShowArrows|chartShowDates);//Enable Date/Time Axis

Plot( C, "Close", colorDefault, styleNoTitle | GetPriceStyle() ); //plotting candle chart


_SECTION_BEGIN("MA Crossover");

PORP=ParamToggle("Percentage or Point", "Percentage | Point", 0);
TG = Param("Target", 5, 0.05, 100, 0.05);
SL = Param("StopLoss", 1, 0.05, 100, 0.05);
MinSpread = Param("Minimum Spread", 0.05, 0.001, 10, 0.001);
line = ParamToggle("Plot Line", "OFF|ON", 1);


_SECTION_BEGIN( "Market Setting" );
IM = ParamToggle( "Intraday Mode", "off|on", 1);
TradeStartTime = Param( "Trade Start From(HHMM)", 916, 600, 2400, 1);
NoEntryTime = Param( "No Entry After(HHMM)", 1445, 900, 2400, 1);
ExitTime = Param( "Square Off Time(HHMM)", 1515, 900, 2400, 1);
MinSpread = Param("Minimum Spread", 0.05, 0.001, 10, 0.001);


_SECTION_BEGIN( "Display Setting" );

MessageBox = ParamToggle("Message Box", "Hide|Show", 1);



FC = DateNum() != Ref( DateNum(), -1 );
LC = DateNum() != Ref( DateNum(), 1 );
EntryTime = IIf(IM, TimeNum()>= TradeStartTime * 100 AND TimeNum()<NoEntryTime * 100, 1);
MarketClose = IIf(IM, ExRem(TimeNum()>= ExitTime*100, LC), 0);

_SECTION_BEGIN("Trading Logics");

//plotting of EMAs




	Plot(EMA1, "EMA-1", colorOrange, styleDots);
	Plot(EMA2, "EMA-2", colorYellow, styleDots);

//When to trade-Trading logic

PBuy = Cross(EMA1, EMA2) ;
PShort=Cross(EMA2, EMA1);

PBuy = ExRem(PBuy, Pshort OR (IM AND FC));
PShort = ExRem(PShort, PBuy OR (IM AND FC));

BZ = Flip(PBuy, PShort OR (IM AND FC));
SZ = Flip(PShort, PBuy OR (IM AND FC));

Buy = BZ AND EntryTime;
Short = SZ AND EntryTime;

Sell = Short OR MarketClose;
Cover = Buy OR MarketClose;





	BTP1 =BuyPrice + TG;
	STP1 = ShortPrice - TG;
	BTP1 = (round(BuyPrice *(1 + TG / 100)/MinSpread)*MinSpread);


BTPrice1 = IIf(OpenLong OR Sell, BTP1, Null);
STPrice1 = IIf(OpenShort OR Cover, STP1, Null);

	BSLP = (round(BuyPrice * (1 - SL / 100)/MinSpread)*MinSpread);
	SSLP= (round(ShortPrice * (1 + SL / 100)/MinSpread)*MinSpread);

BSLPrice = IIf(OpenLong OR Sell, BSLP, Null);
SSLPrice = IIf(OpenShort OR Cover, SSLP, Null);


TSell1 = (H>=BTPrice1) AND !IsNull(BTPrice1);
SLSell = (L<=BSLPrice AND !Buy) AND !IsNull(BSLPrice);

TCover1 = (L<=STPrice1) AND !IsNull(STPrice1);
SLCover = (H>=SSLPrice AND !Short) AND !IsNull(SSLPrice);

Sell = (Sell OR TSell1) OR SLSell;
Cover = (Cover OR TCover1) OR SLCover;



TSell1=(OpenLong OR Sell) AND TSell1;
TCover1=(OpenShort OR Cover) AND TCover1;
SLSell=(OpenLong OR Sell) AND SLSell;
SLCover=(OpenShort OR Cover) AND SLCover;

TSell1 = ExRem(TSell1, Sell);
SLSell = ExRem(SLSell, Sell);

TCover1=ExRem(TCover1, Cover);
SLCover=ExRem(SLCover, Cover);

BuyPrice = IIf(OpenLong OR Sell, BuyPrice, Null);
ShortPrice = IIf(OpenShort OR Cover, ShortPrice, Null);
BTPrice1 = IIf(OpenLong OR Sell, BTPrice1, Null);
STPrice1 = IIf(OpenShort OR Cover, STPrice1, Null);
BSLPrice = IIf(OpenLong OR Sell, BSLPrice, Null);
SSLPrice = IIf(OpenShort OR Cover, SSLPrice, Null);

SellPrice = IIf(Sell*SLSell, BSLPrice, IIf(Sell*TSell1, BTPrice1,IIf(Sell*Short,ShortPrice, IIf(Sell*MarketClose, Close, IIf(Sell, Close, Null)))));
CoverPrice = IIf(Cover*SLCover, SSLPrice, IIf(Cover*TCover1, STPrice1, IIf(Cover*Buy,BuyPrice, IIf(Cover*MarketClose, Close, IIf(Cover, Close, Null)))));


PlotShapes(IIf(Buy, shapeSquare, shapeNone), colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone), colorLime, 0, L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorWhite, 0, L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone), colorRed, 0, H, Offset=-40);
PlotShapes(IIf(Short, shapeSquare, shapeNone), colorOrange, 0, H, Offset=-50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone), colorWhite, 0, H, Offset=-45);

PlotShapes(IIf(Cover, shapeUpTriangle, shapeNone), colorCustom7, 0, L, Offset=-20);
PlotShapes(IIf(Sell, shapeDownTriangle, shapeNone), colorCustom12, 0, H, Offset=-20);

Plot(BuyPrice, "Buy Price", colorBrightGreen, styleLine|styleNoTitle|styleNoLabel);
Plot(ShortPrice, "Short Price", colorRed, styleLine|styleNoTitle|styleNoLabel);

PlotShapes(TSell1*shapeStar, colorBrightGreen, 0, H, 10, 0);
PlotShapes(TCover1*shapeStar, colorRed, 0, L, -10, 0);

PlotShapes(SLSell*shapeStar, colorBlue, 0, L, -20, 0);
PlotShapes(SLCover*shapeStar, colorYellow, 0, H, 20, 0);

Plot(BTPrice1, "BuyTargetPrice", colorGreen, styleLine|styleThick|styleDashed|styleNoTitle);
Plot(STPrice1, "ShortTargetPrice", colorRed, styleLine|styleThick|styleDashed|styleNoTitle);

Plot(BSLPrice, "BuySLPrice", colorLightOrange, styleLine|styleDashed|styleNoTitle);
Plot(SSLPrice, "ShortSLPrice", colorLightOrange, styleLine|styleDashed|styleNoTitle);


_SECTION_BEGIN("BackTest Settings");
Expo = 1000*Param("Initial Equity In Thousand", 10, 1, 1000, 1);
AM = Param("Account Margin", 0.1, 0.01, 1, 0.01);
SetOption("Initialequity", Expo);
SetOption("AccountMargin", AM);
SetOption("PriceBoundChecking", 1);
MaxOpenPos = Param("MaxOpenPos", 1, 1, 200, 1);
SetOption("MaxOpenPositions", MaxOpenPos);
RoundLotSize=Param("Lot Size", 15, 1, 1000, 1);
TickSize = 0.05;
Lot = RoundLotSize;
SetPositionSize((Expo/AM)/MaxOpenPos, spsValue);

Your exposure is super-low. That causes absurd risk adjusted return, because risk adjusted return is calculated by dividing net profit % by your exposure (2.4/1000). Dividing by small amount is equivalent to multiplying by large amount (reciprocal)

As for net profit with such low exposure - for me it looks like you have added some crazy high interest rate and all those results are coming from interest incorrectly set.

If you used newest version of AmIBroker it would warn you about the fact that you are earning majority of profit from interest, not from trading system.

Use DETAILED LOG to see what is going on - To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.