How To Backtest Trading Strategy Signals In Amibroker Trading Platform?

Trading Strategy Code For Golden Cross Moving Average

To know about how to use moving average in trading and investment click on this link first. Here Is The Amibroker Code For Golden Cross Moving Average. If you are not sure how to use it in Amibroker software please watch this video. To adjust the period and levels right click on the indicator in Amibroker and set from parameter window. To know how to backtest trading strategy in Amibroker you can also watch it in this video tutorial.

/* Golder Cross MA Strategy
Created By : Rakesh Solanki
For www.nascenttraders.com
Date: 02/03/2017*/
_SECTION_BEGIN("Golden Cross Moving Average");
SetBarsRequired(sbrAll,sbrAll);
SetFormulaName( "Golden Cross Moving Average" );
SetOption( "Initialequity", 100000 );
SetOption( "AccountMargin", 0.25 );
SetOption( "MinShares", 1 );
MaxOpenPos = Param( "MaxOpenPos", 20, 1, 200, 1 );
SetOption( "MaxOpenPositions", MaxOpenPos );
SetOption( "PriceBoundChecking", 1 );
SetOption( "CommissionMode", 1 );
SetOption( "CommissionAmount", 0.01 );
PositionSize = -400/MaxOpenPos;

FPeriod = Param("Fast MA Period",20,2,25,1);
SPeriod = Param("Slow MA Period",50,10,200,1);
//FPeriod = Optimize("Fast MA Period",10,2,25,1);
//SPeriod = Optimize("Slow MA Period",50,10,200,1);

FLine = EMA(C,FPeriod);
SLine = EMA(C,SPeriod);

SLineRising = SLine>Ref(SLine,-1);
SLineDecling = SLine<Ref(SLine,-1);
Buy = (FLine>SLine) AND SLineRising ;
Short = (SLine>FLine) AND SLineDecling ;
Sell = (SLine>FLine);
Cover =(FLine>SLine);
 
Buy = ExRem(Buy,Sell OR Short);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover OR Buy);
Cover = ExRem(Cover,Short);
BuyPrice = ValueWhen(Buy,C,1);
SellPrice = ValueWhen(Sell,C,1);
ShortPrice = ValueWhen(Short,C,1);
CoverPrice = ValueWhen(Cover,C,1);
Offset = -12;
PlotShapes(Buy*shapeUpTriangle,colorBrightGreen,0,Min(FLine,SLine),Offset);
PlotShapes(Short*shapeDownTriangle,colorRed,0,Max(FLine,SLine),Offset);
PlotShapes(Cover*shapeUpArrow,colorBrightGreen,0,Min(FLine,SLine),Offset);
PlotShapes(Sell*shapeDownArrow,colorRed,0,Max(FLine,SLine),Offset);
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 ) ) ));
PlotOHLC(O,H,L,C,"Close",colorDefault,styleCandle|styleNoTitle);
Plot(FLine,"Fast MA",IIf(FLine>Ref(FLine,-1),colorGreen ,colorRed),styleLine|styleNoTitle);
Plot(SLine,"Slow MA",IIf(SLine>Ref(SLine,-1),colorGreen ,colorRed),styleLine|styleThick|styleNoTitle);

GfxSetOverlayMode(1);
GfxSelectFont("Verdana", 12, 800, True ); 
GfxSetBkMode(0); 
GfxSetTextColor(ColorRGB(18,18,18)); 
GfxTextOut("Created By: Rakesh Solanki", 800 , 430 );
GfxSelectFont("Verdana", 14, 800, True ); 
GfxSetBkMode(1); 
GfxTextOut("www.nascenttraders.com" , 800 ,400 );
Open_Long = Flip( Buy, Sell ); 
Open_Short = Flip( Sell, Buy ); 
Buy_Price = ValueWhen( Buy, BuyPrice, 1 ); 
Short_Price = ValueWhen( Short, ShortPrice, 1 ); 
Sell_Price = IIf( Sell, ValueWhen( Sell, SellPrice, 1 ), Short_Price ); 
Cover_Price = IIf( Cover, ValueWhen( Cover, CoverPrice, 1 ), Buy_Price ); 
Profit = IIf( Open_Long, ( Close - Buy_Price ), IIf( Open_Short, ( Short_Price - Close ), 0 ) ); 
Last_Profit = IIf( Ref( Open_Long, -1 ) == 1 AND Open_Long != 1, ( Sell_Price - Buy_Price ), IIf( Ref( Open_Short, -1 ) == 1 AND Open_Short != 1, ( Short_Price - Cover_Price ), 0 ) ); 
Cum_Profit[0] = Last_Profit[0]; 
PreviousProfit = ValueWhen(Last_Profit!=0,Last_Profit,1); 
for ( i = 1;i < BarCount;i++ ) 
{ 
 Cum_Profit[i] = Cum_Profit[i-1] + Last_Profit[i]; 
} 
Trade[0] = 0; 
for ( i = 1;i < BarCount;i++ ) 
{ 
 if ( Buy[i] == 1 OR Short[i] == 1 ) 
 { 
 Trade[i] = Trade[i-1] + 1; 
 } 
 else 
 { 
 Trade[i] = Trade[i-1]; 
 } 
} 
// Trade Report // 
TR = ParamToggle( "Trade Report", "Show|Hide", 1 ); 
 
if ( TR == 1 ) 
{ 
 GfxSelectFont( "Verdana", 10, 100 ); 
 GfxSetBkMode( 1 ); 
 GfxSetTextColor( ColorRGB(50,50,50) ); 
 y = Status( "pxchartheight" );
 
 GfxTextOut( ( "Total Trades : " + WriteVal( Trade, 3.0 ) ), 13, y - 100 ); 
 GfxTextOut( ( "Previous Profit : " + WriteVal( PreviousProfit, 2.2 ) ), 13, y - 50 ); 
 GfxTextOut( ( "Price : " + WriteVal( Close, 2.2 ) ), 13, y - 75 ); 
 GfxTextOut( ( "Current Profit : " + WriteVal( Profit, 2.2 ) ), 13, y - 25 ); 
}
_SECTION_END();

13 thoughts on “How To Backtest Trading Strategy Signals In Amibroker Trading Platform?

  • Pingback:this page

  • 02/11/2017 at 9:17 AM
    Permalink

    Good day! This is kind of off topic but I need some help from an established blog. Is it very difficult to set up your own blog? I’m not very techincal but I can figure things out pretty fast. I’m thinking about setting up my own but I’m not sure where to start. Do you have any tips or suggestions? Appreciate it

    Reply
    • 02/11/2017 at 9:28 AM
      Permalink

      Yes you can start your own blog if you have good of experience on internet and of course on the subject you choose. I use wordpress platform as it is open source like Android. It will take average 1 year of fruitless parttime effort to establish your blog.

      Reply
  • 08/10/2017 at 3:25 AM
    Permalink

    Hi there just wanted to give you a quick heads up and let you know a few of the images aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different internet browsers and both show the same results.

    Reply
  • 12/09/2017 at 3:40 PM
    Permalink

    This is certainly a amazing write-up. Thank you so much for taking the time to detail all of this out for all of us. It’s a great guide!

    Reply
  • 02/09/2017 at 6:28 PM
    Permalink

    Hello, you used to write fantastic articles, but the last several posts have been kinda lackluster… I miss your super posts. Past few posts are just a little bit out of track!

    Reply
  • 19/05/2017 at 12:08 PM
    Permalink

    Great blog here! Also your website loads up fast! What web host
    are you using? Can I get your affiliate link to your
    host? I wish my site loaded up as fast as yours lol

    Reply
  • 01/04/2017 at 7:14 PM
    Permalink

    It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks

    Reply
  • 31/03/2017 at 11:04 PM
    Permalink

    I must say you have very interesting posts here.
    Your blog should go viral. You need initial boost only.
    How to get it? Search for: Miftolo’s tools go viral

    Reply
    • 26/03/2017 at 11:44 PM
      Permalink

      Welcome Bablofil.

      Reply
  • 09/03/2017 at 4:56 PM
    Permalink

    Hey There. I found your blog using msn. This is a very well written article. I will be sure to bookmark it and return to read more of your useful info. Thanks for the post. I’ll definitely comeback.|

    Reply
  • 09/03/2017 at 4:17 PM
    Permalink

    Terrific article! That is the type of information that should be shared around the internet. Shame on the seek engines for no longer positioning this submit upper! Come on over and talk over with my web site . Thanks =)|

    Reply

Leave Your Invaluable Comment Here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: