[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [amibroker] Re: Changing backtester settings for each symbol



PureBytes Links

Trading Reference Links

Here's my include file with all setups for futures trading for selected
symbols. It does what you ask and sets all options.

 

_SECTION_BEGIN("SetOptions");

 

SetTradeDelays(0,0,0,0);

 

BuyPrice = SellPrice = ShortPrice = CoverPrice = O;

 

//////////////////////////////////////// SETUP CONTRACT SPECIFICATIONS FOR
LISTED SYMBOLS

 

fm           = True; //Default to futures. If you don't find it below,
switch to stocks//Set trading mode and commissions

cm           = 3;    //Commission mode

margin       = 100;  //AA takes care of this, but you must check the Futures
box in AA->Settings->General

myCommission = 2.4;  //$2.40 per contract each way IB

 

//Set Futures Contract Info

_N(emsg = "");

if      (StrLeft(Name(),2) == "ER") {myPointValue = 100;    myTickSize =
0.10;     myMarginDeposit = 3375;} //Russell 2000 emini

else if (StrLeft(Name(),2) == "AB") {myPointValue = 100;    myTickSize =
0.10;     myMarginDeposit = 3375;} //Russell 2000 emini using eSignal's "AB
#f"

else if (StrLeft(Name(),2) == "EM") {myPointValue = 100;    myTickSize =
0.10;     myMarginDeposit = 3375;} //Midcap 400 identical to ER2

else if (StrLeft(Name(),2) == "ES") {myPointValue = 50;     myTickSize =
0.25;     myMarginDeposit = 3938;} //S&P 500 emini

else if (StrLeft(Name(),2) == "NQ") {myPointValue = 20;     myTickSize =
0.25;     myMarginDeposit = 3750;} //Nasdaq100 emini

else if (StrLeft(Name(),2) == "YG") {myPointValue = 100;    myTickSize =
0.10;     myMarginDeposit =  911;} //33.2 Oz. Gold

else if (StrLeft(Name(),2) == "YM") {myPointValue = 5;      myTickSize =
1.00;     myMarginDeposit = 2438;} //DOW emini

else if (StrLeft(Name(),2) == "QM") {myPointValue = 500;    myTickSize =
0.025;    myMarginDeposit = 1688;} //Light Sweet Crude

else if (StrLeft(Name(),2) == "ZC") {myPointValue = 5000;   myTickSize =
0.25;     myMarginDeposit = 1148;} //Corn is quoted in cents/bushel! Change
tickSize to .25 (vs .0025) and use a Currency = 0.01

else if (StrLeft(Name(),2) == "ZB") {myPointValue = 1000;   myTickSize =
0.03125;  myMarginDeposit = 1215;} //30 year Treasury

else if (StrLeft(Name(),2) == "ZG") {myPointValue = 100;    myTickSize =
0.10;     myMarginDeposit = 2734;} //100 Oz. Gold

else if (StrLeft(Name(),2) == "ZN") {myPointValue = 1000;   myTickSize =
0.015625; myMarginDeposit =  810;} //10 year Treasury

else if (StrLeft(Name(),2) == "6E") {myPointValue = 125000; myTickSize =
0.0001;   myMarginDeposit = 2835;} //EuroDollar

else

{

    emsg = Name() + " Selected symbol is not defined in code. It will still
work if 'Contract Specifications' are set in View->Symbol Information\n";

    myPointValue    = PointValue;

    myTickSize      = TickSize;

    myMarginDeposit = MarginDeposit;

}

if (emsg != "") emsg; //Display error message

 

SetOption("FuturesMode",fm); //Requires True or False //NOTE: This is
insufficient. You must also check Futures mode in AA-Settings.

SetOption("CommissionMode", cm);

SetOption("CommissionAmount", myCommission);

 

ieFixed      = Param("Initial Equity. 0 = calc",0,0,1000000,1000);

numContracts = Param("Contracts to trade",10,1,100,1);

incScaleOut  = Param("ScaleOut increments",10,1,100,1);

numScaleOut  = round((1/incScaleOut) * numContracts);

iePercent    = Param("Percent Equity",15,-100,100,1); //+ trades fixed # of
contracts

RoundLotSize = 1; //Always 1 contract

maxPos       = 1; // Just one for Futures code

 

//Set IntialEquity based on the above choices

if (ieFixed > 0)

{

    ie = ieFixed; //Just use this amount as the Initial Equity

}

else //We need to compute the Initial Equity which is based on the # of
contracts to start.

{

    if (iePercent == 0)

    {

        ie = round(myMarginDeposit * numContracts / 1000 + 0.5) * 1000;
//Need to insure it rounds up

        //Both ieFixed and iePercent == 0. You will get barely enough money
to trade numContracts

    }

    else

    {

        ie = round(myMarginDeposit / (abs(iePercent) / 100) / 1000) * 1000 *
numContracts;

        //Initial Equity per contract to nearest $1000

    }

    //Will be HUGE when user picks to trade a very low % of their equity

}

 

//Set PositionSize based on the above choices

if (iePercent == 0)

{

    PSize = myMarginDeposit * numContracts;

    PSize = Min(ie,PSize); //Don't trade more than Initial Equity in case it
was set manually

}

else if (iePercent > 0)

{

    PSize = ie * (iePercent / 100);

    if (fm) PSize = Max(myMarginDeposit,PSize); //Trade at least 1 contract
for Futures. Leave Stock alone.

}

else

{

    PSize = iePercent; //Value is negative, this means we are compounding so
just leave it

    if (fm AND abs(PSize/100 * ie) < myMarginDeposit AND ieFixed > 0) PSize
= -round(myMarginDeposit / ie * 100 + 0.5);

    //User isn't trading enough PSize to get any position so we are forcing
additional PSize to allow the first trade.

    //Testing for ieFixed > 0 because the PSize was already computed and
fixed for this condition above

}

 

//////////////////////////////////////// SET IE + GENERAL AA SETTINGS

SetOption("InitialEquity", ie);

SetOption("AllowSameBarExit",True);

SetOption("ActivateStopsImmediately",True);

SetOption("AllowPositionShrinking",True);

SetOption("InterestRate",0);

SetOption("MarginRequirement",margin);

SetOption("MaxOpenPositions", maxPos);

SetOption("MinShares",1);

SetOption("NoDefaultColumns",False);

SetOption("PriceBoundChecking",True); //NOT THE PROBLEM. It checks H-L, not
O-C.

SetOption("ReverseSignalForcesExit",True); //Normally True if not trading
Long and Short simultaneously

SetOption("UsePrevBarEquityForPosSizing",False);

SetOption("DisableRuinStop", False);

 

//////////////////////////////////////// SHOW USER THEIR SETTINGS

"\nInitial Equity = $" + NumToStr(ie,1.0);

"Initial PositionSize = " + WriteIf(PSize < 0,NumToStr(PSize,1.0) + "% of
Equity","$" + NumToStr(PSize,1.0));

"Scale out size = " + NumToStr(numScaleOut,1.2);

"ScaleOut increments = " + NumToStr(incScaleOut,1.0);

 

SetPositionSize( numContracts, spsShares ); //HELP says to use this "new"
way of PositionSize

 

 

//This section would actually override Contract Specifications above if they
have been set in the Symbol Information

//if (PointValue    == 0) PointValue    = myPointValue;

//if (TickSize      == 0) TickSize      = myTickSize;

//if (MarginDeposit == 0) MarginDeposit = myMarginDeposit;

 

 

//////////////////////////////////////// STOPS - JUST TURN THEM OFF

//The following 4 lines for ApplyStop are here to prevent AA Settings from
over-riding this code.

ApplyStop(stopTypeLoss,stopModeDisable,100,1,False,0);

ApplyStop(stopTypeTrailing,stopModeDisable,100,1,False,0);

ApplyStop(stopTypeNBar,stopModeDisable,100,1,False,0);

ApplyStop(stopTypeProfit,stopModeDisable,100,1,False,0);

 

//////////////////////// End of Include file

_SECTION_END();

 

--

Terry

 

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of mikelaurataylor
Sent: Tuesday, January 30, 2007 05:55
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Changing backtester settings for each symbol

 

Check the devlog or knowledge base on the amibroker site.   There was

an article about this just a little while ago.    I think it was here...

http://www.amibroker.com/kb/2006/09/29/how-to-set-individual-trading-rules-f
or-symbols-in-the-same-backtest/

 

In this case he uses if statements.  I assume you could also build an

excel file, save it as a csv and read the values dynamicly from that

file if you had a long list.

 

--- In amibroker@xxxxxxxxxxxxxxx, "dralexchambers"

<dralexchambers@xxx> wrote:

>

> I have several symbols I wish to backtest on:

> 

> GOOG

> GBPUSD

> etc...

> 

> Is it possible to change the AFL settings in code according to the 

> symbol being tested, eg:-

> 

> If Symbol = GOOG then:

>  PointValue = 0.01

> 

> If Symbol = GBPUSD then:

>  PointValue = 0.0001

> 

> 

> - Also, how do I change the interest rates for FX in AFL?

> 

> Thanks - alex

>

 

 

 

 

Please note that this group is for discussion between users only.

 

To get support from AmiBroker please send an e-mail directly to 

SUPPORT {at} amibroker.com

 

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:

http://www.amibroker.com/devlog/

 

For other support material please check also:

http://www.amibroker.com/support.html

 

Yahoo! Groups Links

 

    http://groups.yahoo.com/group/amibroker/

 

    Individual Email | Traditional

 

    http://groups.yahoo.com/group/amibroker/join

    (Yahoo! ID required)

 

    mailto:amibroker-digest@xxxxxxxxxxxxxxx 

    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

 

    amibroker-unsubscribe@xxxxxxxxxxxxxxx

 

    http://docs.yahoo.com/info/terms/

 


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.12/655 - Release Date: 1/28/2007 1:12 PM