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

[amibroker] Bitten the bullet on loops



PureBytes Links

Trading Reference Links

OK....after all this time trying to avoid loops I've now decided to tackle them. But I'm still unsure of how to go about it. Can someone look over this code please and point out where I'm amiss, as the results are not what I expected. Code is self explanatory.....I think
 
spread = 0.0003;

Buy = Buycond1;

BuyPrice = ValueWhen(Buy,O) + spread;

SellProfit = BuyPrice + 0.0030 ;// Take Profit @ this level

SellLoss = BuyPrice - 0.0015;// Stoploss @ this level

Sella = Cross( H,SellProfit); //Sell when 30 pip in profit from entry price

Sellb = Cross(SellLoss,L) ; //Sell when 15 pip loss from entry price

SellPrice = IIf( Sella, SellProfit, IIf(Sellb,SellLoss,Null));//Sellprice depends on which condition was met

priceatbuy=0;

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

{

if( priceatbuy == 0 && Buy[ i ] )

priceatbuy = BuyPrice[ i ];

if( priceatbuy > 0 && Sella[i] == 1)

{

Sell[ i ] = 1;

SellPrice[ i ] == SellProfit;

priceatbuy = 0;

}

if( priceatbuy > 0 && Sellb[i] == 1)

{

Sell[ i ] = 1;

SellPrice[ i ] == SellLoss;

priceatbuy = 0;

}

 

else

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





YAHOO! GROUPS LINKS