--- In [email protected], "Louis Pr�fontaine"
<[EMAIL PROTECTED]> wrote:
If you are using the boolean value (IsInTrade) then you need to reset it
when you exit the trade. See near the end of the formula. Although if
you now understand the buyatprice == 0 then you could revert to the
canned example.
> Moreover, I don't know how to add other selling rules to that (where
to put those rules in the code) and I don't understand
To add different sell logic, you can modify the "AND" portion of the if
statements after if( exit == ...
> the meaning of this part Sell[ i ] = exit + 1; // mark appropriate
exit code
This sets the type of sell signal. It (exit + 1) will be either 3 or 4
which corresponds to hitting a profit target or hitting a trailing stop
(IIRC).
I don't know how other people feel but IMO, you may want to take a look
at some simple intro programming tutorials separate from AB. Between
general programming, array processing, and the specifics of AFL there is
a lot to take in. Of course your mileage may vary.
Tuzo
Buy = RSI (14)<30;
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 = 25; // in percent
TrailingStop = 15; // also in percent
isInTrade = False;
priceatbuy=0;
highsincebuy = 0;
exit = 0;
for( i = 0; i < BarCount; i++ )
{
if ( NOT isInTrade AND Buy[ i ] )
{
isInTrade = True;
priceatbuy = BuyPrice[ i ];
}
if( isInTrade )
{
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;
isInTrade = False; // not in a trade any
more
}
}
}
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut )); //
scale out 50% of position
Short=0;
Cover=0;
///
///
///
///
///