Simple crossover strategy Amibroker codes pls

Hi Coders and Traders,

Hope you all are doing well . I want to backtest a strategy on amibroker , but i donot know how to code it and would love some help regarding the codes .

Buy /go Long :

EMA 3 crossover > EMA 50 AND RSI(9days) > 60

Sell/go Short :

EMA 3crossover < EMA 50 AND RSI(9days) < 40

Profit Target/Exit Trade :

50 points on nifty and even stoploss 50 points on nifty .

As you can see , this is a very simple stratergy and would love some help with codeing this .

Thank you ,

lost

For the above given condition

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

Buy = Cross( EMA(Close,50),EMA(Close,3)) AND RSI(Close,9)>60 ;
Sell = Cross( EMA(Close,3),EMA(Close,50)) AND RSI(Close,9)<40 ;

Yes, its a simple strategy. I have coded it in amibroker for you. Copy paste the below code.


_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorBlue)+ "www.squareoff.in" + EncodeColor(colorGreen)+" (" +  Name() + ") " + EncodeColor(colorRed)+ 
 "  " + Date() +" " +" •  Open "+WriteVal(O,1.2)+"  •  "+"Hi "+WriteVal(H,1.2)+"  •  "+"Lo "+WriteVal(L,1.2)+"  •  "+
"Close "+WriteVal(C,1.2)+" ("+WriteVal(C-Ref(C,-1),1,0)+" "+WriteVal((C-Ref(C,-1))*100/Ref(C,-1),1.1)+ "%)  •  Vol= "+ WriteVal(V,1.0)
 
);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);
//SetChartBkColor(ParamColor("bkcolor",ColorRGB( 150,50,150)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);

_SECTION_END();
SetPositionSize(1,spsShares);

_SECTION_BEGIN("EMA CROSSOVER CHART www.squareoff.in");

SetTradeDelays(0,0,0,0);
//SetTradeDelays(1,1,1,1);
RoundLotSize = 1; // Define Round Lot Size of the Trading Instrument
SetPositionSize ( 1,spsShares); // Define Fixed Trading Size
SetOption( "InitialEquity", 150000 );
SetOption( "MinShares", 1 );
SetOption( "MinPosValue", 1 ); // Enable Futures Mode
SetOption( "FuturesMode", True );
SetOption( "AllowPositionShrinking", True );
SetOption( "ActivateStopsImmediately", False );
SetOption( "ReverseSignalForcesExit", False );
SetOption( "AllowSameBarExit", False );
SetOption( "CommissionMode", 2 ); // Fixed Brokerage Commissions (Per Trade)
SetOption( "CommissionAmount", 0 ); // Rs 100/Leg Commisions
SetOption( "InterestRate", 0 );
SetOption( "MarginRequirement", 10 ); //Define Margin Requirement
SetOption("AccountMargin", 10 ); //Define Account Margin

LongPer = 3;//Param("Long Period", 10, 30, 100, 5);
ShortPer = 50;//Param("Short Period", 34, 30, 100, 5);
c1=StochD( periods = 40, Ksmooth=1, Dsmooth=1 );
c2=RSI( periods = 9 );
LongMA = EMA(C, 3);
ShortMA = EMA(C, 50);
LastHigh = HHV(H, LongPer);
GraphXSpace = 10;
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorBlack, styleLine);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorRed, styleLine);
Buy = Cross(LongMA, ShortMA) AND C2>60;// AND C2>50;
Short= Cross(ShortMA, LongMA) AND C2<40;// AND C2<50;
Buy[BarCount-1]=Null;
Short[BarCount-1]=Null;
Buy=ExRem(Buy,Short);
Short=ExRem(Short,Buy);

Sell=Short;
Cover=Buy;

BuyPrice=ValueWhen(Buy,C);

SellPrice=ValueWhen(Sell,C);

ShortPrice=ValueWhen(Short,C);

CoverPrice=ValueWhen(Cover,C);

PlotShapes(Buy*shapeSmallUpTriangle,colorBlue ,0,L,-51);
PlotShapes(Short*shapeHollowDownTriangle,colorPink , 0,L,-45);
PlotShapes(Sell*shapeSmallDownTriangle,colorRed,0, H,-51);
PlotShapes(Cover*shapeHollowUpTriangle,colorSkyblue,0,H,-45);

_SECTION_END(); 

Hi Algo ,
Hope you are doing well . I pasted this on my amibroker and I get errors for the buy and sell . it says Error 16: too many arguments . can you kindly fix . thanks

hi algo ,
also the profit and stop loss targets are not set , could you kindly add them ? Thanks

Hi Karan ,
Thanks a ton for the codes, just wanted to ask if the stop loss and profit target of 50 points have been coded as well ? cause i would like to run the backtest for it on amibroker .
Regards,
Lost

You can keep the stop loss and target points as per your wish in the amibroker backtest settings