AFL of the week: A simple Crude Oil Trading Strategy

On our reader’s demand, we have developed a Simple strategy to trade on Crude Oil futures in MCX. This is a Trend following swing trading strategy which takes positions on daily timeframe. Bollinger Bands is used as an indicator to determine Trend breakout. The number of trades generated using this strategy is very low which makes it easier to trade. However, max drawdown is on a little higher side, so risk management is necessary. This Crude oil Trading Strategy is specifically developed for beginners in commodity markets. Read below for the strategy overview and AFL details.

 Read our article on AFL tutorial here.

AFL Overview

Paramter Value
Preferred Timeframe Daily
Indicators Used Bollinger Band
Buy Condition Closing price of the day is greater than upper band of Bollinger Band.
Short Condition Closing price of the day is less than lower band of Bollinger Band.
Sell Condition Same as Short
Cover Condition Same as Buy
Stop Loss 1%
Targets No fixed target
Position Size 50% of initial equity
Initial Equity 200000
Brokerage 100 per order
Margin 20%

AFL Code

//------------------------------------------------------
//
//  Formula Name:    Crude Oil Trading Startegy
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.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 ));

//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 AFL

Backtest Report

 Paramter Value
  Fixed Position Size
Initial Capital  200000
Final Capital 581072
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 has little higher drawdown figures. But it would be always profitable on the long term. Download the detailed backtest report here.

Equity Curve

Crude Oil_Equity Curve

Additional Amibroker settings for backtesting

Goto Symbol–>Information, and specify the lot size and margin requirement. The below screenshot shows lot size of 100 and margin requirement of 20% for Crude Oil Futures:

Crude Oil_Symbol Information

Disclaimer:

All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at support@tradingtuitions.com

12 Comments

  1. Greetings.
    Good to see ur efforts in commodity. Myself experienced that, commodities future trading are much fruitful to build capital than NF & BNF. Forget individual stock buying & holding. These are very lazy game & not my cup of tea.
    Bye the way, I request u to make this system in Excel, as most of the individual traders still do not have access to Amibroker. And fixed numerical entry & exit point shown in Excel cell gives much more control over emotion, than seeing a chart. 😉
    Thanks in advance.

    • Thanks for your suggestion Gautam. Are you requesting the same system to be coded in Excel or do you have any other recommendation?

  2. Another suggestion is: If we make some change in short/long covering by crossover of price with 20 SMA, than just swinging the position wrt BB. Hope this will give better results. Regards.

  3. @Admin: Yes same system in Excel, with a little change of exit current position when price crosses 20 SMA.
    Then re entry with BB signal as said in system.
    (IMO, this exit rule can give better result. Ur expertise is welcome.)

    • Sure! Stay tuned to see an Excel sheet based on this system. Cannot commit on the ETA though :)

  4. Can we trade this strategy for intraday. If its works in intraday which time frame suitable like 5 Min, 15 Min

    • Hi Anandhan,

      No, this is a Swing Trading strategy. Intraday trading is not recommended.

      • Ok, Thanks for your hope sir, Any intraday strategy For crudeoil or how to get the open, high, low excel system in Mcx

  5. Hi admin,This Crude Oil Trading has sniper technique ?
    I am confuse name code which i saw in youtube name crude sniper.
    This code use in time frame?.
    Thank you for share.

  6. Can you share the strategy result for the last 10 years. You can use crude spot data.

  7. Hi I am new in commodities. Can u detail out some steps in this strategy for me to understand. Pls

Leave a Reply

Your email address will not be published. Required fields are marked *