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

Parameter Value
Preferred Timeframe Daily
Indicators Used Bollinger Band
Buy Condition If the closing price of the day exceeds the upper band of the Bollinger Band.
Short Condition If the closing price of the day falls below the lower band of the Bollinger Band.
Sell Condition Same as the Short Condition.
Cover Condition Same as the Buy Condition.
Stop Loss 1%
Targets No fixed target
Position Size 50% of initial equity
Initial Equity 200,000
Brokerage 100 per order
Margin 20%

AFL Code

				
					//------------------------------------------------------
//
//  Formula Name:    Crude Oil Trading Startegy
//  Website:         zerobrokerageclub.com
//------------------------------------------------------
_SECTION_BEGIN("Crude Oil Trading Startegy");
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 ) ) ));
//Initial Parameters
SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",100);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(50,spsPercentOfEquity);
SetOption( "AllowPositionShrinking", True );
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;
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 );
Sell=Short;
Cover=Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
printf("nBuy : " + Buy );  
printf("nSell : " + Sell );  
printf("nShort : " + Short );  
printf("nCover : " + Cover );  
Stoploss=Optimize("SL",1,1,5,1);
ApplyStop(Type=0,Mode=1,Amount=StopLoss);
/* 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);
_SECTION_END();
				
			

AFL Screenshot

Crude-Oil

Backtest Report

Parameter Value
  Fixed Position Size
Initial Capital 200,000
Final Capital 581,072
Scrip Name MCX Crude Oil Futures
Backtest Period 16-Mar-2015 to 03-June-2016
Timeframe Daily
Net Profit % 190.54%
Annual Return % 111.72%
Number of Trades 8
Winning Trade % 37.50%
Average Holding Period 27.50 periods
Max Consecutive Losses 3
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

Crude-Oil_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:

Crude-Oil_Symbol-Information

2 Comments

Leave a Reply