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

Re: [amibroker] Re: sigScaleOut Problem



PureBytes Links

Trading Reference Links

You may be best to use a for loop to define when you want to scaleout
as in the example from the help files, this should save you ahving to
use the exrem

--
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://e-wire.net.au/~eb_kavan/ab_write.htm


On 12/19/05, dweilmuenster95125 <dweilmuenster95125@xxxxxxxxx> wrote:
> Graham, thanks.  Unfortunately, I am not much of a programmer, so the
> example goes over my head.
>
> However, I may have isolated the problem with the example included
> below after my signature (adapted from the Help files).  Run this code
> against the single symbol "IBM" for the dates 1/1/95 through 2/16/05
> with a weekly Periodicity and load 3200 bars.  Although the scaling
> in/out executes properly, the performance statistics are substantially
> incorrect (e.g., compare total net profit to the sum of net profit for
> all trades).
>
> However, if one replaces
>
>   DoScaleOut = InTrade AND Cross(RSI2,80);
>
>  with
>
>   DoScaleOut = ExRem(InTrade AND Cross(RSI2,80),Sell);
>
>
> the scaling in/out executes properly and the statistics are reported
> correctly.  Unfortunately, this isn't the logic that I want to
> implement because I want to scale out more than once per trade.  But,
> it does illustrate some of the problems I'm encountering.
>
> Any further thoughts?
>
> Regards,
>
> David
>
>
>
> ///////////////////////////////////////////////////////////
> //  Test Scaling  II
>
> SetOption("InitialEquity",100000);
> SetOption("MarginRequirement",100);
> SetTradeDelays(0,0,0,0);
> BuyPrice = SellPrice = ShortPrice = CoverPrice = C;
> RoundLotSize = 10;
>
>
> RSI2 = RSIa(C,2);
>
> // regular trading rules (no pyramiding)
> Buy = C>MA(C,40) AND Cross(20,RSI2);
> Sell = Cross(MA(C,40),C);
>
> InTrade = Flip( Buy, Sell );
>
> DoScaleIn = C>MA(C,40) AND Cross(20,RSI2);
> DoScaleOut = InTrade AND Cross(RSI2,80);
>
> Buy = IIf(DoScaleIn,sigScaleIn,
>      IIf(DoScaleOut,sigScaleOut,
>      IIf(Buy==True,True,False)));
>
>
> SetPositionSize(IIf(Buy==True OR Buy==sigScaleIn,25,
>                IIf(Buy==sigScaleOut,50,False)),
>                IIf(Buy==True OR Buy==sigScaleIn,spsPercentOfEquity,
>                IIf(Buy==sigScaleOut,spsPercentOfPosition,False)));
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxxx> wrote:
> >
> > It might be in the way your code is for the scale-outs. I did a test
> > myself and it sold 50% of the current holding at each scale out. I
> > also tried with 25% SetPositionSize( 25, spsPercentOfPosition * ( Buy
> > == sigScaleOut ) ); and it sold 25% of the curent holding at each
> > scaleout signal
> > I just used the example code and changed the Sell to a buy=scaleout to
> > test how it worked
> >
> > /*
> > Example 4: partial exit (scaling out) on profit target stops
> >
> > Example of code that exits 50% on first profit target, 50% on next
> > profit target and everything at trailing stop:
> > */
> > Buy = Cross( MA( C, 10 ), MA( C, 50 ) );
> > Sell = 0;
> >
> > // the system will exit
> > // 50% of position if FIRST PROFIT TARGET stop is hit
> > // 50% of position is SECOND PROFIT TARGET stop is hit
> > // 100% of position if TRAILING STOP is hit
> >
> > FirstProfitTarget = 10; // profit
> > SecondProfitTarget = 20; // in percent
> > TrailingStop = 10; // also in percent
> >
> > priceatbuy=0;
> > highsincebuy = 0;
> >
> > exit = 0;
> >
> > for( i = 0; i < BarCount; i++ )
> > {
> >    if( priceatbuy == 0 AND Buy[ i ] )
> >     {
> >        priceatbuy = BuyPrice[ i ];
> >     }
> >    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;
> >        }
> >       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;
> >         Buy[ i ] = sigScaleOut;
> > //         Sell[ i ] = exit + 1; // mark appropriate exit code
> >          exit = 0;
> >          priceatbuy = 0; // reset price
> >          highsincebuy = 0;
> >        }
> >     }
> > }
> >
> > SetPositionSize( 50, spsPercentOfEquity );
> > SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );
> > // scale out 50% of position
> >
> >
> >
> > --
> > Cheers
> > Graham
> > AB-Write >< Professional AFL Writing Service
> > Yes, I write AFL code to your requirements
> > http://e-wire.net.au/~eb_kavan/ab_write.htm
> >
> >
> >
> > On 12/19/05, dweilmuenster95125 <dweilmuenster95125@xxxx> wrote:
> > > My Backtest is Long Only, based on Weekly Charts.
> > >
> > > The only two statements in my AFL code regarding Position Size are:
> > >
> > > SetPositionSize (100/3,spsPercentOfEquity);
> > > SetPositionSize(50, IIf( Buy == sigScaleOut, spsPercentOfPosition,
> > > spsNoChange ) );
> > >
> > > Execution of the scaling out gives unpredictable results.  An example
> > > below shows that the first scaleout was OK  (110 out of 220 open
> > > shares of IBM scaled out on 11/5/2004).  However, the next scale out
> > > on  11/12/2004 (the next weekly bar) scales out 210 shares, when
> > > there are only 110 shares in the position, leaving the account short
> > > by 100 shares.
> > >
> > > Any thoughts as to what may be going wrong?
> > >
> > > I have lots of other examples where the scale out size is not 50% of
> > > the current position.  Am happy to share more of the code, but
> > > thought this might be enough to generate some ideas.
> > >
> > >
> > > Thanks,
> > > David
> > > ------------------------------------------------


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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 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/

<*> 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/