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

[amibroker] Re: about the scale out function


  • Date: Thu, 18 Feb 2010 22:11:36 -0000
  • From: "uman3344" <tan_flamshun818@xxxxxxxxxxx>
  • Subject: [amibroker] Re: about the scale out function

PureBytes Links

Trading Reference Links


--- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@xxx> wrote:
>
> hi,
> 
> if the element in the sell is not zero it is considered true and a sell will take place. I think what is meant in the comment is the type of exit.
> 
> see help for Applystop, these are the exits used. They do the same thing, exit the position, but by giving them a number you know what type of stop you are dealing with, rgds, Ed
> 
> 
> 1 - regular exit
> 2 - max. loss
> 3 - profit target
> 4 - trailing
> 5 - n-bar stop
> 6 - ruin stop 
> 
> 
> 
> 
> From: uman3344 
> Sent: Monday, February 15, 2010 6:17 AM
> To: amibroker@xxxxxxxxxxxxxxx 
> Subject: [amibroker] about the scale out function
> 
> 
>   
> From the amibroker guideline, it gives an example of the scaleout code. Can anyone please explain this code for me "Sell[ i ] = exit + 1;". Although commented, I don't quite understand the meaning of "// mark appropriate exit code". As far as I know, the sell function is executed according to either 1(true) or 0(false). How does this code work to only sell when the exit is => 2 which is when secondprofit target (exit code=2) and trailing stop (exit code=3) are crossed.  
> 
> 
> 
> ----------------------------------------------------------------------------------------------------
> 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; 
>          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
>

Thanks for the helpful replies.



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

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

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/