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

[amibroker] Re: AFL looping question!



PureBytes Links

Trading Reference Links

Thanks for your efforts Ed. It is indeed simpler to use the Equity 
and Flip(Buy,Sell) method! Though occasionally I am having some 
trouble with  ValueWhen( Buy, Close ,1)  if the Buy condition is met 
again after the initial entry signal. Are there other ways to refer 
to the Entry Price without having this issue?

Regards,
Adrian

--- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@xxx> 
wrote:
>
> hi,
> 
> this indeed can be done without using loops but if you want to use 
loops it would look like (see also chart). But this can be done 
without using loops,
> 
> rgds, ed
> 
> 
> 
> 
> Buy = Cross(C,EMA(C,50)); 
> Sell = 0; 
> 
> BuyPrice = Open; 
> sellPricelevel = Null; 
> BuyAdjusted = 0; 
> 
> for( i = 0; i < BarCount; i++ ) 
> { 
> 
>    if( Buy[ i ] ) 
>    { 
> 
>       BuyAdjusted[ i ] = 1; 
>       sellPriceLevel[ i ] = BuyPrice[ i ] * 1.2; 
> 
>       for ( j = i + 1; j < BarCount; j++ ) 
>       { 
>        
>          sellPriceLevel[ j ] = BuyPrice[ i ] * 1.2; 
>           
>          if (H[ j ] >  sellPriceLevel[ j ]) 
>          { 
>           
>             Sell[ j ] = 1; 
>             SellPrice[ j ] = Max(O[ j ],sellPriceLevel[ j ]); 
>              
>             i = j; 
>             break; 
>           
>          } else if (j == BarCount - 1) { 
>                    
>             i = BarCount; 
>                    
>          }    
>        
>       } 
>        
>    } 
>     
> } 
> 
> Buy = BuyAdjusted; 
> 
> SetBarsRequired(10000,10000); 
> SetChartOptions(0, chartShowDates); 
> Plot(C,"C",colorWhite,64); 
> PlotShapes(IIf(Buy,shapeUpTriangle,0),colorWhite, layer = 0, 
yposition = BuyPrice, offset = 0 ); 
> PlotShapes(IIf(Sell,shapeDownTriangle,0),colorOrange, layer = 0, 
yposition = SellPrice, offset = 0 ); 
> 
> Plot(sellPriceLevel,"sell Level",colorBlue,styleThick); 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>   ----- Original Message ----- 
>   From: tayamaan 
>   To: amibroker@xxxxxxxxxxxxxxx 
>   Sent: Monday, June 30, 2008 10:16 AM
>   Subject: [amibroker] Re: AFL looping question!
> 
> 
>   Hi Ed, the loop is just a simple profit target stop for testing 
other 
>   parts of my systems and a reference to the Entry Price.
> 
>   Once changing the "Close[ i ] > priceatbuy * 1.2" expression and 
>   basically making it a stop, things go wrong. Or is it my logic? 
LOL 
> 
>   Am not too familiar with looping and try to understand why this 
>   doesn't work.
> 
>   Thanks
> 
>   --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@> 
>   wrote:
>   >
>   > hi,
>   > 
>   > could you explain what you try to do? 1 error I see is that 
>   priceatbuy in the loop also needs to be handled as an element, 
like 
>   priceatbuy[ i ], but then still I can't figure out what you are 
>   trying to do,
>   > 
>   > rgds, Ed
>   > 
>   > 
>   > 
>   > 
>   > ----- Original Message ----- 
>   > From: tayamaan 
>   > To: amibroker@xxxxxxxxxxxxxxx 
>   > Sent: Monday, June 30, 2008 9:30 AM
>   > Subject: [amibroker] AFL looping question!
>   > 
>   > 
>   > Hello all,I couldn't be more pleased with all the Amibroker
>   > improvements lately, I am still often amazed what this 
fantastic 
>   piece
>   > of software is capable of.
>   > 
>   > I am going wrong somewhere with the loop sample below when 
>   changing
>   > the expression: Close[ i ] > priceatbuy * 1.2 ) into: Close[ 
i ] <
>   > priceatbuy * 0.8 )
>   > 
>   > First expression works fine, with the second one things go 
wrong 
>   and I
>   > can't figure what! Can someone send me in the right direction 
pls.
>   > 
>   > Are there any other ways to refer to the Entry Price other than
>   > Valuewhen and Equity Flip(Buy,Sell)?
>   > 
>   > Cheers,
>   > Adrian
>   > 
>   > Buy = Cross(C,EMA(C,50));
>   > Sell = 0;
>   > 
>   > priceatbuy = 0;
>   > 
>   > for( i = 1; i < BarCount; i++ ) 
>   > { 
>   > if( priceatbuy == 0 AND Buy[ i ] ) 
>   > { 
>   > priceatbuy = BuyPrice[ i ];
>   > } 
>   > else Buy[ i ] = 0;
>   > 
>   > if( priceatbuy > 0 AND Close[ i ] > priceatbuy * 1.2 )
>   > {
>   > Sell[ i ] = 1;
>   > priceatbuy = 0;
>   > }
>   > }
>   >
>



------------------------------------

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
Yahoo! Groups Links

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

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

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