Skip to main content

In response to our readers’ requests, we’ve crafted a straightforward strategy for trading Crude Oil futures on MCX. This strategy is a swing trading approach that follows trends, focusing on daily timeframes. It utilizes the Bollinger Bands indicator to identify trend breakouts. While this strategy generates a low number of trades, making it user-friendly, it does come with a slightly higher maximum drawdown. Therefore, proper risk management is essential. Designed with beginners in commodity markets in mind, this Crude Oil Trading Strategy offers an overview and AFL code details.

Explore here to learn AFL coding and create your own trading systems.

AFL Overview

Preferred TimeframeDaily
Indicators UsedBollinger Band
Buy ConditionIf the closing price of the day exceeds the upper band of the Bollinger Band.
Short ConditionIf the closing price of the day falls below the lower band of the Bollinger Band.
Sell ConditionSame as the Short Condition.
Cover ConditionSame as the Buy Condition.
Stop Loss1%
TargetsNo fixed target
Position Size50% of initial equity
Initial Equity200,000
Brokerage100 per order

AFL Code

//  Formula Name:    Crude Oil Trading Startegy
//  Website:

_SECTION_BEGIN("Crude Oil Trading Startegy");

_N(Title = StrFormat("{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

//Initial Parameters
SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption( "AllowPositionShrinking", True );

Plot( Close, "Price", colorWhite, styleCandle );
Periods = param("Periods", 40, 5, 100, 5 );
Width = param("Width", 1, 1, 10, 1 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoLabel;
Plot( bbt = BBandTop( Close, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style ); 
Plot( bbb = BBandBot( Close, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style ); 
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, GetChartBkColor(), 0.8 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );

Buy=Close>=BBandTop( Close, Periods, Width );
Short=Close<=BBandBot( Close, Periods, Width );

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

printf("\nBuy : " + Buy );  
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover );  



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

PlotGrid(0, colorLightGrey);
PlotGrid(25, colorLightGrey);
PlotGrid(-25, colorLightGrey);

AFL Screenshot


Backtest Report

  Fixed Position Size
Initial Capital200,000
Final Capital581,072
Scrip NameMCX Crude Oil Futures
Backtest Period16-Mar-2015 to 03-June-2016
Net Profit %190.54%
Annual Return %111.72%
Number of Trades8
Winning Trade %37.50%
Average Holding Period27.50 periods
Max Consecutive Losses3
Max System % Drawdown-26.97%
Max Trade % Drawdown-42.07%

This Crude Oil Trading strategy exhibits slightly higher drawdown figures. Nevertheless, it remains profitable over the long term. Access the comprehensive backtest report here.

Equity Curve


Additional Amibroker settings for backtesting

Go to Symbol–>Information and specify the lot size and margin requirement. The screenshot below illustrates a lot size of 100 and a margin requirement of 20% for Crude Oil Futures: