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

[amibroker] setpositionsize, etc.



PureBytes Links

Trading Reference Links

Hi,

I posted a question yesterday or th day before, and maybe it was lost in all the emails, or whatever.  So I post it again.  If I can only understand this I am sure I can go a long way.  Thanks!

* * *

I tried to build a simple system with a first profit target of 10% and a scaling of position, followed by a sell signal issued by specific indicators.   The following code is dumb enough; it's only an example I gave myself to try to learn

SetOption("UseCustomBacktestProc", False);
//
SetOption("MaxOpenPositions", 3 );
SetOption("InitialEquity", 100000 );
SetOption("AllowPositionShrinking", True );
SetOption ("AllowSameBarExit", False);
SetOption ("ActivateStopsImmediately", False);
SetOption ("MinShares", 100);
SetOption ("MinPosValue", 5000);
SetOption ("PriceBoundChecking", True);
SetOption ("CommissionMode", 2);
SetOption ("CommissionAmount", 25);
SetOption ("AccountMargin", 100);
SetOption ("ReverseSignalForcesExit", True);
SetOption ("UsePrevBarEquityForPosSizing", True);
SetOption ("PortfolioReportMode", 0);

Buy = RSI (14)<30
AND EMA (ADX (14),10)<20;


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;

CloseEMA = EMA(C,50);
RSI14= RSI (14);

    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;//Réduit position de %.
                }
            if   
                ( exit == 1 
                AND
                    (Close[i]<CloseEma[i-1]
                    OR
                    RSI14[i]>75
                    )
           

                )
               
                {
                    // second profit target hit - exit
                    exit = 2;
                    SellPrice[ i ] = Open[ i ];
                }
            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 p rice
                    highsincebuy = 0;
                }
        }
    }
SetPositionSize( 50, spsPercentOfEquity );
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut )
); // scale out 50% of position///

Short=0;
Cover=0;


Ok; first I am not sure if my code makes sense.  Because I tried to modify the spspercentofposition (green) and whatever the number I put there it changed nothing to the backtesting.  I tried 20, 50, 70  (assuming it should be a scaling out of 20%, 50% or 70%) and it changed nothing.  So I guess something is wrong.

Second, I am not sure about the utility of "sellprice" (blue).  Does it actually replace the "sell" command?  I assumed so, but I am not sure about this.  When I write       SellPrice[ i ] = Open[ i ]; does it actually mean that it will sell on the open?  Simply?

The yellow part is what I added to the code.  But ideally, here is what I am trying to do: a system that would secure 33% of a position by scaling out after a 10-20% gain, and then selling everything when indicator is reached OR if the price goes down more than x% below the price at which there was the scaling out.   I think I would need another variable, maybe a "sellprice2" or something to set the new stop-loss.

I don't know if my question is clear, but I think that if I can understand this part I can make it on my own... at least for some days! ;-P

Thanks,

Louis

__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___