PureBytes Links
Trading Reference Links
|
Actually ExRem functions should NOT be used at all in any trading system
(unless you specifically *need* to convert from state to signal form for some logic).
They are completely redundant and actually are the source of problems point (1).
Specifically they are NOT needed by the backtester! Backtester does this
job internally way better (because it RESPECTS from/to dates).
Backtester in regular mode does not enter more than one pos on one symbol at a time:
http://www.amibroker.com/guide/h_portfolio.html
therefore ExRems are not needed at all.
>>
>> Buy=ExRem(Buy,Sell); // REMOVE IT !
>> Sell=ExRem(Sell,Buy); // REMOVE IT !
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "Mike" <sfclimbers@xxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Wednesday, June 18, 2008 10:10 AM
Subject: [amibroker] Re: optimisation not working correctly?
> Rich,
>
> There are a couple of reasons for why your results are not as
> expected.
>
> 1. Misaligned signals due to missing checks for "barinrange".
> 2. Coding errors.
> 3. Remaining Open positions skewing the figures.
>
> 1. The largest contributor for the "faulty" results is that even
> though your backtest range is defined as from xxx to yyy, all
> calculations are still performed over the entire data range. So, your
> Buy array will contain signals for all bars, even bars that precede
> your starting date. As such, your counting of bars within your loop
> will include signals received before the first date of your backtest
> and your Sell signals will therefore be misaligned.
>
> For example; if your backtest started on Feb 1, 2008 and a Buy signal
> was found on Jan 28, 2008 and again on Feb 5, 2008. Then using a 12
> bar length, your code would put the first Sell signal on Feb 13, 12
> days after the Jan 28 Buy instead of 12 days after the Feb 5 Buy.
>
> The backtester would later filter out all signals occuring before
> your start date (e.g. filter out the Jan 28 buy), but would keep
> those occurring after it (i.e. the Feb 5 Buy and the Feb 13 Sell).
>
> The result is that your bars held will now be incorrect. This would
> have a ripple effect as the ExRem might now end up removing some of
> your intended Sells and keeping the unintended ones.
>
> 2. The next problem is some minor coding errors.
> 2a. You need to reset the bar count after recognizing a Sell.
> 2b. You need to set the bar count to 1 after recognizing a Buy.
>
> 3. Any remaining open positions are included in the bars held
> calculations of the backtester. So, if you have open positions that
> are 3 days old, they will pull down the average 12 day bars held
> figure to be less than 12.
>
> Your modified code should now look something like the following. I do
> still see the odd long trade. So, something is still not quite right.
> Might be a case of buy/sell on the same date or something along those
> lines. But, this should get you a lot closer to where you want to
> be :)
>
> Mike
>
> SetTradeDelays( 0, 0, 0, 0 );
> PositionSize = -10;
>
> PB = Optimize( "PB", 0.99, 0.97, 0.998, 0.002 );
> Length = Optimize( "Length", 12, 3, 15, 1 );
>
> InRange = Status( "barinrange" );
> Cond0 = Ref(InRange, -2);
> Cond1 = Ref( C, -1 ) < PB * Ref( C, -2 );
> Cond2 = C > Ref( C, -1 );
>
> Buy = Cond0 AND Cond1 AND Cond2;
> Sell = False;
> inTrade = False;
> bcnt = 0;
>
> for ( i = 0; i < BarCount; i++ )
> {
> if ( NOT Cond0[i] )
> {
> continue;
> }
>
> if ( inTrade )
> {
> Buy[i] = False;
> }
>
> if ( ++bcnt == Length )
> {
> inTrade = False;
> Sell[i] = True;
> bcnt = 0;
> }
> else
> {
> if ( Buy[i] )
> {
> inTrade = True;
> bcnt = 1;
> }
> }
> }
>
> Buy = ExRem( Buy, Sell );
> Sell = ExRem( Sell, Buy );
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "foxblade2000invest" <foxblade@xxx>
> wrote:
>>
>> I'm trying to optimise with the folowing code. When I look at the
>> results, the winning and losing average bars (which should be fixed)
>> does not correspond at all with the "length" parameter, which should
>> govern it?
>>
>> The code is as follows;
>>
>> PB=Optimize("PB",0.99,0.97,0.998,0.002);
>> Length=Optimize("Length",12,3,15,1);
>>
>> Cond1=Ref(C,-1)<PB*Ref(C,-2);
>> Cond2=C>Ref(C,-1);
>>
>>
>> Buy = Cond1 AND Cond2;
>> Sell = False;
>> inTrade = False;
>> bcnt = 0;
>>
>> for (i = 0; i < BarCount; i++)
>> { if (inTrade)
>> {
>> Buy[i] = False;
>> }
>> if (++bcnt == Length)
>> {inTrade = False;
>> Sell[i] = True;
>> }else
>> {
>> if (Buy[i])
>> {inTrade = True;bcnt = 0;
>> }
>> }}
>>
>> Buy=ExRem(Buy,Sell);
>> Sell=ExRem(Sell,Buy);
>>
>> Can anyone help?
>>
>> Thanks,
>> Rich
>>
>
>
>
> ------------------------------------
>
> 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
>
>
>
------------------------------------
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
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|