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

[amibroker] Re: sigScaleOut Problem



PureBytes Links

Trading Reference Links

Tomasz, I'll wait for your response via the support channel.

I didn't mean to create double work.  Just thought that some other 
user might have run into this and had an easy solution.

Regards,
David



--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxxx> 
wrote:
>
> David,
> 
> As I wrote you in response to support e-mail, scaling out / 
position size part of the formula is
> the reason of the problem.
> 
> I will further check the code you have supplied and provide you 
with the resolution
> over support channel within few days.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "dweilmuenster95125" <dweilmuenster95125@xxxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Monday, December 19, 2005 8:11 AM
> Subject: [amibroker] Re: sigScaleOut Problem
> 
> 
> 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
> > > ------------------------------------------------
> > >
> > >
> > >
> > >
> > >
> > > Date    Information
> > > .
> > > 8/20/2004
> > >        Entry signals(score):
> > >        Exit signals:
> > >        0 Open Positions: , Equity: 57406.1, Cash: 57406.1
> > > 8/27/2004
> > >        Entry signals(score):IBM=Buy(14.4218),
> > >        Exit signals:
> > >        Enter Long, IBM, Price: 85.23, Shares: 220, Commission: 
2.2,
> > > Rank: 14.4218, Equity 57401.7, Margin Loan: 0, Fx rate: 1
> > >        1 Open Positions: , IBM (+220), Equity: 57359.8, Cash: 
38675.2
> > > 9/3/2004
> > >        Entry signals(score):
> > >        Exit signals:
> > >        1 Open Positions: , IBM (+220), Equity: 57260.8, Cash: 
38697.2
> > > .
> > > 10/29/2004
> > >        Entry signals(score):
> > >        Exit signals:
> > >        1 Open Positions: , IBM (+220), Equity: 58615.8, Cash: 
38873
> > > 11/5/2004
> > >        Entry signals(score):
> > >        Exit signals:IBM=Scale-Out,
> > >        Scale-Out Long IBM, Price 89.33, Shares 110, Fx Rate 1, 
Total
> > > Shares Hold 110, Exited 110, Avg. Price Entry 85.23, Exit 
89.33, Avg
> > > Fx. Rate Entry 1, Exit 1
> > >        1 Open Positions: , IBM (+110), Equity: 58985.6, Cash: 
48725.9
> > > 11/12/2004
> > >        Entry signals(score):
> > >        Exit signals:IBM=Scale-Out,
> > >        Scale-Out Long IBM, Price 92.5, Shares 210, Fx Rate 1, 
Total
> > > Shares Hold -100, Exited 320, Avg. Price Entry 85.23, Exit 
91.4103,
> > > Avg Fx. Rate Entry 1, Exit 1
> > >        1 Open Positions: , IBM (-100), Equity: 58656.4, Cash: 
68187.4
> > > .
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > 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
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> 
> 
> 
> 
> 
> 
> 
> 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
>






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