Hello,

This MS code:

result = (C>HautP AND C>BasP,5, If(C<BasP,0,PREV)) 


can be translated to:

result = 0;

for( i = 1; i < BarCount; i++ )
{
  prev = result[ i - 1];
  result[ i ] = IIF( C[ i ] > HautP[ i ] AND C[ i ] > BasP[ i ], 5, IIF( C[ i ] 
< BasP[ i ], 0, prev ) );
}

Although loop version is longer, it will execute 100 faster than in Metastock, 
because
MS PREV is extremely inefficient.

Best regards,
Tomasz Janeczko
amibroker.com
  ----- Original Message ----- 
  From: Yves 
  To: [email protected] 
  Sent: Saturday, October 24, 2009 6:45 AM
  Subject: [amibroker] PREV of MS in AmiBroker





  I'm try to translate this formula(Metastock) in Amibroker(AB)

  (C>HautP AND C>BasP,5, If(C<BasP,0,PREV)) 

  A guy from AB said to use the loop.

  I'm use a formula on site Internet of AB(Percentage Trail Stop)

  Why when I'm use my Formula, I'm obtain :

  Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean 
type. You can not use array here, please use [] (array subscript operator) to 
access array elements

  And when I'm use the formula Percentage Trail Stop, 

  I don't obtain ERROR 6 ?????????????

  WHY ???????

  Thank

  YLTech

        Percentage Trail Stop
       My Formula
       
        StopLevel =Param("Percentage Trail Stop",0.05, 0.01, 0.6, 0.01 );

        LK=50;

        FF=10;

        A1= IIf( L> Ref(HHV( Close,LK),-5), 1, 0); 

        A2= Sum( A1, LK ) ;

        A3= IIf(C>0, FF, 0); 

        Buy = Cross(A2,A3);

        Sell = 0;

        trailARRAY = Null;

        trailstop = 0;

        for( i = 1; i < BarCount; i++ )

        {

        if( trailstop == 0 AND Buy[ i ] ) 

        { 

        trailstop = High[ i ] * (1-stoplevel);

        }

        else Buy[ i ] = 0; // remove excess buy signals

        if( trailstop > 0 )

        { 

        trailstop = Max( High[ i ] * (1-stoplevel), trailstop );

        trailARRAY[ i ] = trailstop;

        }

        if( trailstop > 0 AND Low[ i ] < trailstop )

        {

        Sell[ i ] = 1;

        SellPrice[ i ] = trailstop;

        trailstop=0;

        }

        }

        PlotShapes(Buy*shapeUpArrow,colorBlue,0,Low);

        PlotShapes(Sell*shapeDownArrow,colorRed,0,High);

        Plot( Close,"Price",colorBlack,styleBar);

        Plot( trailARRAY,"trailing stop level", colorRed );
       _SECTION_BEGIN("Cr.HautP.");

        TimeFrameSet( inDaily ); // switch now to Daily 

        HautP= Ref(H,-1) ;

        BasP= Ref(L,-1) ;

        TimeFrameRestore(); // restore time frame to original

        StopLevel = BasP ;

        Buy = Cross(C,HautP) ;

        Sell = 0 ;

        trailARRAY = Null;

        trailstop = 0;

        for( i = 1; i < BarCount; i++ )

        {

        if( trailstop == 0 AND Buy[ i ] ) 

        { 

        trailstop = HautP ;

        }

        else Buy[ i ] = 0; // remove excess buy signals

        if( trailstop > 0 )

        { 

        trailstop = Max( HautP, trailstop );

        trailARRAY[ i ] = trailstop;

        }

        if( trailstop > 0 AND Low[ i ] < trailstop )

        {

        Sell[ i ] = 1;

        SellPrice[ i ] = trailstop;

        trailstop=0;

        }

        }

        PlotShapes(Buy*shapeUpArrow,colorBlue,0,Low);

        PlotShapes(Sell*shapeDownArrow,colorRed,0,High);

        Plot( Close,"Price",colorBlack,styleBar);

        Plot( trailARRAY,"trailing stop level", colorRed );

        _SECTION_END();
       





  Merci
   
  YLTech ( Yves L. )
   
  Le présent message et les documents qui y sont joints sont réservés 
exclusivement au destinataire indiqué. Il est strictement interdit d'en 
utiliser ou d'en divulguer le contenu. Si vous recevez le présent message par 
erreur, veuillez le détruire S.V.P. et nous en aviser immédiatement afin que 
nous puissions corriger nos dossiers. Merci.
   
  This message and the attached documents may contain privileged or 
confidential information that are intended to the addressee only. Any 
unauthorized disclosure is strictly prohibited. If you happen to receive this 
message by error, please delete it and notify us immediately so that we may 
correct our internal records. Thank you.
   
  [email protected]




  

Reply via email to