Skip to main content
Our readers asked for an easy-to-use AFL (AmiBroker Formula Language) for USD-INR Currency Trading, and we’ve got you covered. This strategy, ideal for day trading, relies on a triple Exponential Moving Average (EMA) crossover. It works like a charm for trading USD-INR, consistently bringing in profits. Check out the backtest report for all the details. For learning AFL coding and creating your own trading systems, click here.

USD-INR Currency Trading Strategy: AFL Overview

Parameters Value
Indicators Used EMA 3, EMA 21, EMA 46
Buy Condition EMA Period 3 is greater than EMA period 21, and EMA period 21 is greater than EMA period 46.
Sell Condition EMA Period 3 is less than EMA period 21, and EMA period 21 is less than EMA period 46
Stop Loss 0.5%
Targets No fixed target, Stop and reverse when AFL gives an opposite signal
Position Size 80% of Trading Capital
Initial Equity 100,000
Brokerage 50 per order
Margin 2.5% (for USD-INR Currency futures)

AFL Code

				
					//------------------------------------------------------
//
//  Formula Name:    USD-INR Trading Startegy
//  Website:         zerobrokerageclub.com
//------------------------------------------------------

_SECTION_BEGIN("USD-INR Trading Startegy");

SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 100000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",50);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize( 80, spsPercentOfEquity ); 
SetOption( "AllowPositionShrinking", True );
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;

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 ) ) ));

EMAPeriod1=3;
EMAPeriod2=21;
EMAPeriod3=46;

Buy = EMA(C, EMAPeriod1) > EMA(C, EMAPeriod2) AND EMA(C, EMAPeriod2) < EMA(C, EMAPeriod3);
Sell = EMA(C, EMAPeriod1) < EMA(C, EMAPeriod2) AND EMA(C, EMAPeriod2) > EMA(C, EMAPeriod3);
 
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = Sell;
Cover = Buy;

StopLoss=0.5;
ApplyStop(Type=0,Mode=1,Amount=StopLoss);

Plot( Close, "Price", colorWhite, styleCandle );
Plot(ema( C, EMAPeriod1 ),"3EMA",colorWhite);
Plot(ema( C, EMAPeriod2 ),"21EMA",colorBlue);
Plot(ema( C, EMAPeriod3 ),"46EMA",colorRed);
 

/* Plot Buy and Sell Signal Arrows */
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(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, 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);
 
_SECTION_END();
				
			

AFL Screenshot

USD-INR-Trading-Startegy

Backtest Report

ParameterValue
USD-INR Currency Futures
Initial Capital100,000
Final Capital896,807.50
Backtest Period07-07-2015 to 03-03-2016
Timeframe10 minutes
Net Profit %796.81%
Annual Return %2672.58%
Number of Trades111
Winning Trade %39.64%
Average Holding Period64 periods
Max Consecutive Losses8
Max System % Drawdown-44.49%
Max Trade % Drawdown-28.39%

Download the detailed backtest report here.

Please note that you can expect even better results if you allow compounding of your returns.

Equity Curve

USD-INR-Trading-Startegy-Equity-Curve

Additional Amibroker Settings for Backtesting

Go to Symbol –> Information and specify the lot size and margin requirement. The below screenshot shows a lot size of 1000 and a margin requirement of 2.5% for USD-INR:

Symbol-Info_USDINR

Leave a Reply