Thanks Prashanth. The following mod to your code is what I want, but there seems to be a problem with the parts after the ANDs. I should be able to use "AND" instead of "OR" since the exit price can be 10 pips above the entry price simultaneous to one of the MAs being above or below the other.
Sells and Covers are not occurring with the below formula. But I don't see the flaw in the logic. I tried replacing the "10" with "0.0010" and that still does not work. In my EUR-USD Symbol info I have it set to Round Lot size =1, Tick size = 0.0001, Point Value = 100000 SlowMA = MA(C,20); FastMA = MA(C,5); Plot(SlowMA, "myMA1", colorBlue); Plot(FastMA, "myMA2", colorGreen); Buy = FastMA > SlowMA ; Sell = FastMA < SlowMA AND SellPrice > (BuyPrice + 10); Short = FastMA < SlowMA; Cover = FastMA > SlowMA AND CoverPrice < (ShortPrice - 10); --- In [email protected], "Prashanth" <[EMAIL PROTECTED]> wrote: > > I am not sure you require loops to do what you are looking for. > > SlowMA = MA(C,20); > > FastMA = MA(C,5); > > Buy = FastMA > SlowMA ; > > Sell = Cross(SlowMA , FastMA) OR SellPrice > (BuyPrice + 10); > > Short = FastMA < SlowMA; > > Cover = Cross(FastMA, SlowMA) OR CoverPrice < (ShortPrice - 10); > > Instead of AND, I have used OR since both Crossover and Price being above 10 pips cannot happen simultaneously. > > Cheers > > Prashanth > > > ----- Original Message ----- > From: ozzyapeman > To: [email protected] > Sent: Friday, July 11, 2008 3:09 AM > Subject: [amibroker] Re: Help on Debugging this If-Else Loop > > > Still toying around with this and still can't get it to work. I just can't seem to figure out how to specify the current price. Thought that the ValueWhen function might be able to help. > > All I'm trying to achieve is this very simple test system, for Forex Intraday: > > > 1. Buy Long position when the fast MA is above the slow MA > 2. Sell the Long position when the fast MA falls below the slow MA, AND the current price is at least 10 pips higher than the original entry price. > > 3. Enter Short position when fast MA is below the slow MA > 4. Sell the Short position when the fast MA rises above the slow MA, AND the current price is at least 10 pips lower than the original entry price. > > Code below. Anyone? > > > > > Buy = (myMA1 > MyMA2); > Short = (myMA1 < MyMA2); > > PriceAtBuy = 0; > PriceAtShort = 0; > > > for( i = 0; i < BarCount; i++ ) > { > if( PriceAtBuy == 0 AND Buy[ i ] ) > { > PriceAtBuy = Buy[ i ]; > ValueAtBuy = ValueWhen(Buy[i]>0,C,1); > } > > if( PriceAtShort == 0 AND Short[ i ] ) > { > PriceAtShort = ShortPrice[ i ]; > ValueAtShort = ValueWhen(Short[i]>0,C,1); > } > > > if( > (myMA1[i] < MyMA2[i]) AND (PriceAtBuy > 0) AND (C[i] > (ValueAtBuy[i] + 0.0010)) > ) > { > Sell[ i ] = 1; > PriceAtBuy = 0; > > } > else > Sell[ i ] = 0; > > > if( > (myMA1[i] > MyMA2[i]) AND (PriceAtShort > 0) AND (C[i] < (ValueAtShort[i] - 0.0010)) > ) > { > Cover[ i ] = 1; > PriceAtShort = 0; > } > else > Cover[ i ] = 0; > > > } >
