Thanks Tomasz,

It s gonna take me some time to understand your idea. I'm  not very
satisfied with the overall way AB is handling this kind of topic.. anyways
thanks for the assistance. could you explain a little more on how you put
the #include statements? 

 

How many systems did you plug together? How many different timeframes? Did
optimization for capital allocation work? ("optimize percentrisked")

 

Greets,

 

Matthias

 

From: amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] On Behalf
Of tf28373
Sent: Donnerstag, 9. September 2010 11:01
To: amibroker@yahoogroups.com
Subject: [amibroker] Re: Backtest multiple systems across multiple
timeframes

 

  

Hi Matthias

Some time ago I was working on the same problem. The solution I have come
across is as following:

1) use #include command in the main code
2) inside the #include function do like this (of course all is just an
example which will need adjustment to your needs):
a) function(parameter1, parameter2,...,timeframe,...,parameterN)
{
switch (timeframe)
{
case 60: TimeFrameSet(inHourly); break;
case 15: TimeFrameSet(in15Minute); break;
case 5: TimeFrameSet(in5Minute); break;
default: break;
}
//here comes the calculations of channels, threshold,
averages, oscillator, etc, everything you need to obtain
signals' conditions

TimeFrameRestore();//AGAIN - it is just an example, by the way - sorry for
illegable layout
switch (timeframe)
{
case 60: channel1=TimeFrameExpand(chan1,inHourly,expandLast);
channel2=TimeFrameExpand(chan2,inHourly,expandLast);
oscillator1=TimeFrameExpand(osc1,inHourly,expandLast);
break;
case 15: //the logic of code the same as above...
break;
case 5: //as above break;
default: channel1=chan;
channel2=chan2;
oscillator1=osc2;
break;
}

//here comes the buy/sell/cover/short/stop conditions and
position sizing, etc
}

Although using #include results in slower code exection, it is a kind of
idea to handle different timeframes system backtest, so I hope that even if
it does not help directly, it will at least inspire you to find your own
solution.

Regards 
Tomasz

--- In amibroker@yahoogroups.com <mailto:amibroker%40yahoogroups.com> ,
"Matthias" <meridian...@...> wrote:
>
> Hi,
> 
> thanks to the contribution of Ed Pottasch, supported by Bruce, I was able
to dig a little deeper into Amibroker coding. Everybody who is interested in
applying multiple systems on the same underlying simultaneously should look
here, great piece of work:
http://finance.groups.yahoo.com/group/AmiBroker-at/message/5349
> 
> Thanks Ed, thanks Bruce.
> 
> Unfortunately, I stumbled across a couple of questions when backtesting
multiple systems across different timeframes, hope someone can help, sorry
for the post being a bit lenghty.
> 
> Both systems are traded on the same underlying, in order to make things
easier for AB (Which is a bit strange) I used the same set of data, just
renamed it. both systems operate on the same timeframe, say 15mins.
> 
> 
> Question 1: 
> 
> I use the same variable "percentrisked" for both systems. Wanted to
optimize for percent risked (only!, this is NOT shown in the example below),
so to say capital allocated to each system for the smoothest equity curve,
AB keeps crashing... Can I use the same variable name in each sub-section or
are there limits? should I dedicated "percentrisked1" to system1 and
"percentrisked2" to system2 only? I am not a programmer, but for my
understanding, both variables are local, so AB should not be crashing...?
> 
> Is using "Setoption" in this context appropriate or would it result in
wrong values?
> 
> if(Name()=="DAX_CFD_day1")
> {
> percentrisked=2.0;
> factor=Optimize("ATR-Factor",8.5,3,12,0.5);
> number=(percentrisked)/(ATR(14)*factor)*20;
> SetPositionSize(number, spsPercentOfEquity);
> SetOption("commissionmode",3);
> SetOption("Commissionamount",1.2);
> SetOption("AllowSameBarExit",True);
> SetOption("ActivateStopsImmediately",True);
> 
> .....systemlogic here
> }
> 
> if(Name()=="DAX_CFD_day")
> {
> 
> percentrisked=Optimize("Bolli",0.6,0.5,1,0.1); 
> sl=2;//Optimize("sl",2,2,2.5,0.5);//good:6 
> number=(percentrisked/(Ref(ATR(14),-1)*sl))*20; 
> SetPositionSize(number, spsPercentOfEquity); 
> SetOption("commissionmode",3);
> SetOption("Commissionamount",1.2);
> SetOption("AllowSameBarExit",True);
> SetOption("ActivateStopsImmediately",True);
> SetOption("FuturesMode",True);
> SetTradeDelays(1,1,1,1);
> Equity(1); 
> 
> ... systemlogic here
> }
> 
> 
> Question 2:
> 
> Both systems above use 15min timeframe. Another system is using 1hr
timeframe and is trading FX. I was not able to re-write the logic so that I
could backtest the 3 systems with AA settings 15min timeframe. Any ideas? I
do have about 8 systems, lowest timeframe is 5min, highest timeframe 4hrs.
That would require a lot of "re-writing"... Am I alone with my "I have too
many-systems" Problem or am I missing somehting?
> 
> original logic in 1hr timeframe:
> 
> percentrisked=0.007; 
> sl=4.5;
> tp=2.5;
> 
> number=((percentrisked)/(Ref(ATR(14),-0)*sl)); 
> SetPositionSize(number,spsPercentOfEquity);
> 
> SetOption("maxopenpositions",1); 
> 
> 
> CCIperiod=Optimize("CCI",36,34,40,1); 
> CCIthreshold=optimize("CCIthres",89,88,96,1);
> 
> MAperiod=Optimize("maperiod",7,6,8,1);
> 
> MA1= MA(C,MAperiod);
> MA2= MA(Ref(C,-2),MAperiod);
> 
> CCIshort=CCI(CCIperiod)>=ccithreshold;
> CCIbuy= CCI(CCIperiod)<=-CCIthreshold;
> 
> Buyok=Ref(CCIbuy,-1) AND Cross(MA1,MA2);
> Sellok=CCIshort;
> Shortok=Ref(CCIshort,-1) AND Cross(MA2,MA1);
> Coverok=CCIbuy;
> 
> timestart=020000;
> window=170000 
> Check=timestart+window; 
> timeok=TimeNum()>=timestart AND TimeNum()<=Check; 
> 
> Buy= Buyok AND timeok;
> Sell= Sellok;
> Short= Shortok AND timeok;
> Cover= Coverok;
> 
> ApplyStop(stopTypeLoss,stopModePoint,sl*ATR(14)); //9
> ApplyStop(stopTypeProfit,stopModePoint,tp*ATR(14)); //1.2
> 
> Equity(1);
> 
> 
> 
> 
> System2:
> 
> percentrisked=0.007; 
> sl=4.5;
> tp=2.5;
> 
> SetOption("maxopenpositions",1); 
> 
> CCIperiod=Optimize("CCI",36,34,40,2); 
> CCIthreshold=Optimize("CCIthres",97,88,96,2);
> 
> MAperiod= Optimize("maperiod",7,7,9,1);
> 
> TimeFrameSet(inHourly);
> MA1= MA(C,MAperiod);
> MA2= MA(Ref(C,-0),MAperiod);
> CCIhr= CCI(CCIperiod);
> ATR1= ATR(14);
> TimeFrameRestore();
> 
> number=((percentrisked)/(TimeFrameExpand(Ref(atr1,-0),inHourly)*sl)); 
> SetPositionSize(number,spsPercentOfEquity);
> 
> CCIshort=TimeFrameExpand(CCIhr,inHourly)>ccithreshold;
> CCIbuy= TimeFrameExpand(CCIhr,inHourly)<-CCIthreshold;
> 
> 
>
Crossup=Cross(TimeFrameExpand(MA1,inHourly),TimeFrameExpand(Ref(MA2,-2),inHo
urly));
>
Crossdown=Cross(TimeFrameExpand(Ref(MA2,-2),inHourly),TimeFrameExpand(MA1,in
Hourly));
> 
> Buyok=Ref(CCIbuy,-5) AND Crossup;
> Sellok=CCIshort;
> Shortok=Ref(CCIshort,-5) AND Crossdown;
> Coverok=CCIbuy;
> timestart=20000; 
> window=170000;
> Check=timestart+window; 
> timeok=TimeNum()>=timestart AND TimeNum()<=Check; 
> 
> 
> Buy=Buyok AND timeok;
> Sell= Sellok OR CCIexit;
> Short= Shortok AND timeok;
> Cover= Coverok OR CCIexit;
> 
>
ApplyStop(stopTypeLoss,stopModePoint,sl*TimeFrameExpand(Ref(ATR1,-1),inHourl
y)); 
>
ApplyStop(stopTypeProfit,stopModePoint,tp*TimeFrameExpand(Ref(ATR1,-1),inHou
rly)); 
> 
> Equity(1);
> 
> Thanks a lot for your suggestions,
> 
> Matthias
>



Reply via email to