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

[amibroker] Re: Scaling out example code does not work



PureBytes Links

Trading Reference Links

--- In amibroker@xxxxxxxxxxxxxxx, "Howard B" <howardbandy@xxx> wrote:
Hi Howard,

Thanks for posting this.  I've been playing with your code and I am
seeing some behavior I don't understand.  Not what the original poster
was talking about, though.  I've set Report to be Detailed Log and I
receive many buy signals each day but the same message appears at the
beginning of the backtest run:

<symbol> not entered because of insufficient funds.

I thought my settings were off so I added:

SetOption( "initialequity", 60000 );
SetOption( "AllowPositionShrinking", True ); 
SetOption( "MaxOpenPositions", 1 ); 

to the beginning of the formula but the results were similar.

i.e. On 03/01/2006 I get Entry Signals(score):ABN=Buy(1),AGU=Buy(2)
but the message says ABN not entered because of insufficient funds.

Trades do eventually get entered but I'm not sure why (in my test the
first trade was 21/02/2006).

This seems strange to me since I don't understand how there are
insufficient funds on the first bar of the backtest.

So I'm curious if anyone else sees the same behavior and if the
behavior is as expected?  (I'm wondering if it has anything to do with
PositionScore?)


Thanks,

Tuzo

>
> Hi EZ --
> 
> The following code comes from my book, "Quantitative Trading
Systems".  See
> if this helps.
> 
> ////////////////////////////////////////////////////////////////////
> 
> 
> //    ScaleOut.afl
> //
> //    Sells part of holdings at one profit target,
> //    sells remainder of holding at second profit target,
> //    sells entire holding on trailing stop.
> //
> //    This example patterned after one in the
> //        AmiBroker User's Guide.
> //
> SetTradeDelays(0,0,0,0);
> BuyPrice = C;
> SellPrice = C;
> 
> //    Use a moving average crossover to enter long positions
> Buy = Cross(MA(C,5),MA(C,25));
> Sell = 0;
> 
> //    Targets are in percentages.
> FirstProfitTarget = 10;
> SecondProfitTarget = 20;
> TrailingStop = 10;
> 
> //    Scalars to keep track of prices while in trade.
> PriceAtBuy=0;
> HighSinceBuy = 0;
> Exit = 0;
> 
> 
> //    Loop through all the bars.
> for( i = 0; i < BarCount; i++ )
> {
>     if (PriceAtBuy==0 AND Buy[i]==1)
>     {
>         PriceAtBuy = BuyPrice[i];
>     }
>     else
>         if(PriceAtBuy > 0 )
>         {
>             HighSinceBuy = Max(High[i],HighSinceBuy);
>             if (exit==0 AND
>                 High[i] >= (1 + FirstProfitTarget*0.01)
>                     * PriceAtBuy)
>             {
>                 // first profit target hit - scale-out
>                 Exit = 1;
>                 Buy[i] = sigScaleOut;
>                 BuyPrice[i] = (1 + FirstProfitTarget*0.01)
>                     * PriceAtBuy;
>             }
>             if(Exit==1 AND
>                 High[i] >= (1 + SecondProfitTarget*0.01)
>                     * PriceAtBuy)
>             {
>                 // second profit target hit - exit
>                 Exit = 2;
>                 SellPrice[i] = Max(Open[i],
>                     (1 + SecondProfitTarget*0.01) * PriceAtBuy);
>             }
>             if (Low[i] <= (1 - TrailingStop*0.01) * HighSinceBuy)
>             {
>                 // trailing stop hit - exit
>                 Exit = 3;
>                 SellPrice[i] = Min(Open[i],
>                     (1 - TrailingStop*0.01) * HighSinceBuy);
>             }
>             if (Exit >= 2)
>             {
>                 Buy[i] = 0;
>                 Sell[i] = Exit + 1; // mark appropriate exit code
>                 Exit = 0;
>                 PriceAtBuy = 0;
>                 HighSinceBuy = 0;
>             }
>     }
> }
> 
> SetPositionSize( 50, spsPercentOfEquity );
> // scale out 50% of position
> SetPositionSize( 50, spsPercentOfPosition * ( Buy==sigScaleOut) );
> 
> //Buy = ExRem(Buy,Sell);
> //Sell = ExRem(Sell,Buy);
> //Figure 7.10 Scale Out
> 
> //////////////////////////////////////////////////////////////
> 
> Thanks,
> Howard
> 
> On Sun, Dec 28, 2008 at 8:45 PM, ezbentley <ezbentley@xxx> wrote:
> 
> >   I copied and pasted the code from example 4 at the following url
to test
> > scaling out:
> >
> > http://amibroker.com/guide/h_pyramid.html
> >
> > However, it simply does not work. All positions are exited at once
when the
> > first profit target
> > is met.
> >
> > The desired behavior is to exit half of the position at first
profit target
> > and exit the other half
> > at the second profit target.
> >
> > It is very frustrating when the example code from the official
source is
> > not behaving
> > correctly.
> >
> > Does anyone know how to correctly implement scaling out?
> >
> > Thanks in advance,
> >
> >  
> >
>



------------------------------------

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL 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/