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

[amibroker] Converting Long Scale Out to Short Scale Out



PureBytes Links

Trading Reference Links

Would someone please be so kind as to convert this example of a long scale out, given in the help file, into a short scale out? I have spent several hours already trying to get it to work. I even used _TRACE() debugging to find out exactly what is going on in the loop. I came up with what I thought was the correct long to short conversion but for some reason when I try implementing this for a short entry it misses some, but not all, of the entry signals. Why miss some but not all? I have no idea. It's way beyond me at this stage and I sure hope one of you has the answer.
Thanks
  Pete  :-)
Here it is straight out of the help file. This is the long entry version, what I need is a short entry version.

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



__._,_.___


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

*********************
TO GET TECHNICAL 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

__,_._,___