sigscaleout only applies to Buy, you should not use Sell for this
See the help files - Tutorial - Amibroker Formula Language -
Pyramidding/scaling


--
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://www.aflwriting.com


On 25/11/06, tradinghumble <[EMAIL PROTECTED]> wrote:

I'm trying to develop a system with the following rules:

- Future (position size 2 contracts)
- Buy on cross over of two emas
- Sell on cross over of two emas
- Sell or Cover 1 contract when parabolic sar points in the contrary
direction
- Sell all contracts when get a signal on the contrary direction

I can't figure out the scale out method...
the code is based on a system I found in the AFL library:

Any help is appreciated.

/*-------------------------------------
        Trade
-------------------------------------*/
TradeFlag=TimeNum()>070300 AND TimeNum()<151000; //TradeFlag=1;
CloseFlag=TimeNum()>=154000; //CloseFlag=0;

// conditions
SAR_long = TradeFlag AND Cross(ShortMA, LongMA);
SAR_short = TradeFlag AND Cross(LongMA, ShortMA);

parabSARacc = Param("SAR Acceleration", 0.02, 0, 1, 0.001 );
parabSARaccm = Param("SAR Max. acceleration", 0.2, 0, 1, 0.001 );
parabSAR =      SAR( parabSARacc , parabSARaccm );

parabSAR_sell = parabSAR > H;   // time to sell long position
parabSAR_cover= parabSAR < L; // time to cover short position

// initialize storage array
SAR_plot = 0;
Buy = Short = Sell = Cover = 0;

PositionSize = 2; /* 2 contracts */
SetPositionSize(PositionSize,spsShares);
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );
// scale out 50% of position


// initialize position
longpos = 0;
shortpos = 0;
exit = 0;  // states 1=first target hit, 2=final exit

//
for (i = 0; i < BarCount; i++) {

        if (longpos == 0 AND shortpos == 0) {   // no positions, check
signals...

                if (SAR_short[ i ]) {  // is short
                        Short[ i ] = 1;
                        ShortPrice[ i ] = C[ i ];
                        shortpos = 1;
                        exit = 0;
                } else if (SAR_long[ i ]) {
                        Buy[ i ] = 1;
                        BuyPrice[ i ] = C[ i ];
                        longpos = 1;
                        exit = 0;
                }

        } else if (longpos == 1 AND shortpos == 0) { // we are long

                // signal to close partial? (EXIT = 1)?
                if (parabSAR_sell[ i ] ) { // do we a Parabolic SAR sell?
                        Buy [ i ] = sigScaleOut;
                        Sell[ i ] = 1;   // yes, sell position
                        SellPrice[ i ] = C[ i ];
                        exit = 1;
                        longpos = 1;
                }

                // signal to final close? (EXIT = 2)
                if (SAR_short[ i ] ) { // do we have a xo to go short OR a
Parabolic
SAR sell?
                        Buy [ i ] = 0;
                        Sell[ i ] = 1;   // yes, sell position
                        SellPrice[ i ] = C[ i ];
                        exit = 2;                       // final close
                        longpos = 0;
                }

                // check if we need to reverse
                if (longpos = 0 AND SAR_short[ i ] ) {          // do we
have a xo to go long?
                        Short[ i ] = 1;
                        ShortPrice[ i ] = C[ i ];
                        shortpos = 1;
                        exit = 0;
                }

        } else if (longpos == 0 AND shortpos == 1) { // we are short

                // signal to close partial? (EXIT = 1)?
                if (parabSAR_cover [ i ] ) {            // do we a
Parabolic SAR cover?
                        Cover[ i ] = sigScaleOut;               // yes,
cover partial
                        CoverPrice[ i ] = C[ i ];
                        exit = 1;
                        shortpos = 1;
                }

                // signal to final close? (EXIT = 2)
                if (SAR_long[ i ]) {            // do we have a xo to go
long?
                        Sell [ i ] = 0;
                        Cover[ i ] = 1;         // yes, cover position
                        CoverPrice[ i ] = C[ i ];
                        exit = 2;                               // final
close
                        shortpos = 0;
                }

                // check if we need to reverse
                if (shortpos = 0 AND SAR_long[ i ] ) {          // do we
have a xo to go long?
                        Buy[ i ] = 1;
                        BuyPrice[ i ] = C[ i ];
                        longpos = 1;
                        exit = 0;
                }
        }
}




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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

Yahoo! Groups Links




Reply via email to