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

[amibroker] trailing stops and looping



PureBytes Links

Trading Reference Links

Hi all...

Hopefully my last question regarding looping.The last piece of code 
i am trying to implement is having a floor for the trailing stop to 
be activated...The first part of the code is the profit target where 
I sell 50% of the position up 20 percent.I would like to have a 
trailing stop,only if this is true.I would have thought that by 
coding "if = =1" into the loop,that would have done the trick.It 
didnt.Below is the parts of the code that are relevant..Any help 
appreciated,and thank you Terry for helping out
---------------------------------------------------------------------
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(Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy )



 
//Shouldnt this work???
 if(exit==1 AND Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * 
highsincebuy )