That's good info.
Below is a short code to illustrate, using a 4-leg, fixed-share
scale-out.
(A picture of the Detailed Log showing the result may be found here
<http://www.codefortraders.com/phpBB3/viewtopic.php?f=60&t=635>   .)

--

/*
    ScaleOut_Simple_01.afl

    Simple illustration of fixed-size scale-out when Trade Delays are set
to 1.

    Per the User's Guide:

    "If your position sizing depends on values found in
buy/sell/short/cover variables *and*
    if you are using non-zero trade delays you need to account for that
in your code. "

*/

//   This OVERRIDES the settings page!
settradedelays( 1, 1, 1, 1 ) ;

Sell = (BarIndex() == -1);
Short = Sell;
Cover = Sell;

// Set bar index for Buy to designate the (barcount - 20th) bar
biBuy = BarCount - 1 - 20 ;

Buy = (BarIndex() == biBuy);

//   Buy 11 shares/contracts as an example
SetPositionSize(11, spsShares);

//   Set Scale-Out signals over the next 4 bars
Buy[biBuy + 1] = sigScaleOut;
Buy[biBuy + 2] = sigScaleOut;
Buy[biBuy + 3] = sigScaleOut;
Buy[biBuy + 4] = sigScaleOut;

//   PositionSize (ps) - Scale-out 3 shares/contracts at a time.
//   In this demo, the final scale-out size exceeds the remaining
position size.
//   The result is the closure of the position.

//   Note: ps needs to be set correctly as of the bar where the position
change (scale-out) is to take place.
//   With Trade Delays of 1, we reference the signal on the prior bar to
set ps on the current bar.
//   Hence, the use of Ref(Buy, -1) below  \/ .
ps = SetPositionSize(3, spsShares * ( Ref(Buy, -1) == sigScaleOut ));


--- In [email protected], "ovtrad...@..." <ovtrad...@...> wrote:
>
>
> For the record, I had to contact support about this and the behavior I
was seeing was due to me using trade delays of 1 (i.e. to trade on
tomorrow's open).  The call to setPositionSize needs to be adjusted to
check Ref(Buy, -1) in this case.
>
> --- In [email protected], "ovtrading@" ovtrading@ wrote:
> >
> > I am trying to do something very simple with scaling out and
following
> > the example in the setPositionSize documentation.  To simplify as
much
> > as possible, I have written a very small strategy which doesn't even
use
> > signals.  I want to start with a full position, and scale out 50%
after
> > some time.  Here's the code:
>
> ...
>

Reply via email to