Hi all,

Been plugging away and its slowly coming together.Thanks to many,I 
have a thorough understanding of Exrem() and am starting to get the 
hang of basic looping..

I have been working with the example in the users manual on page 142 
and adding my own code and will be moving on to optimisation next.

I was successful in adding a maxstop loss of 8% to the loop.I have 
verified the results.That is not a problem..

what is giving me a problem is the trailing stop that was coded by 
Amibroker on pg 142 of the manual.I cant verify the results in AA to 
the exit signals.In my full code below,I have 

Trailingstop=20//in percent;

I would assume that if the current low is <= .8* highsinsebuy,the 
trailing stop would be activated.With that said,if my highsince 
entry =100,wouldnt 80 be the price that the trailstop is 
activated??? For some odd reason,I am getting trailing stops and 
executions down 6%.Am I not understanding the definition of trailing 
stop??Keep in mind that my max stop =8%,so that is not the issue...


if(Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy ) 
     

      { 
         // trailing stop hit - exit  
         exit = 3;    
         SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 
0.01 ) * highsincebuy ); 
       } 

I also attempted to code in a trailing stop only if my first profit 
target was reached.Exit=1 was my first profit target of 20%.I dont 
believe the code below works as planned.


if(exit==1 AND Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * 
highsincebuy ) 


I set up optimasations for the stops,but will save that for a later 
time..Any help deeply appreciated!!!Full code below


    




---------------------------------------------------------------------
                 //My version of code
Buytemp = Cross(Close,MA(Close,5));  // my code change
Selltemp =Cross(MA(Close,200),Close); // my code change

Buy=Buytemp;
Sell=Selltemp;
Buy=ExRem(Buy,Sell); // my code change

Sell=ExRem(Sell,Buy);// my code change

Filter=1; //exploration


AddColumn(BuyTemp,"All Buy Signals");//exploration

AddColumn(Buy,"BUY SIGNAL");//exploration

AddColumn(SellTemp,"All Sell Signals");//exploration

AddColumn(Sell,"SELL SIGNAL");//exploration


// 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 
// 100% of position if MAXSTOP is hit

FirstProfitTarget = 20; // profit 
SecondProfitTarget = 40; // in percent 
TrailingStop = 20; // also in percent 
Maxstop=8;//also in percent

 
//Optimize("FirstProfitTarget", 20, 5, 50, 5); 
//Optimize("SecondProfitTarget ", 15, 25,70,5);
//Optimize("TrailingStop", 15,6,50,2);
//Optimize("maxstop",8,2,22,1);  


priceatbuy=0;
highsincebuy = 0;
//Lowsincebuy=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 ) 
     // if(exit==1 AND Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * 
highsincebuy ) 
      // added "exitl ==1 and" to have a floor for trailing stop

       { 
         // trailing stop hit - exit  
         exit = 3;    
         SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 
0.01 ) * highsincebuy ); 
       } 

     if (Low[i]<=(1-Maxstop*.01)*priceatbuy)
        {
        exit = 4;
         SellPrice[i]=Min(Open[i],(1-Maxstop*.01)*priceatbuy);
         //My attempt to code in a Max stop loss-appears to work as 
coded
       }

      if( exit >= 2 ) 
       { 
         Buy[ i ] = 0; 
         Sell[ i ] = exit + 1; // mark appropriate exit code 
         exit = 0; 
         priceatbuy = 0; // reset price 
         highsincebuy = 0;
         Lowsincebuy=0; 
       } 
    } 
  } 

SetPositionSize( 5, spsPercentOfEquity ); 
SetPositionSize( 50, spsPercentOfPosition * ( Buy == 
sigScaleOut ) ); // scale out 50% of position








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 other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to