The Iif function does not work in the way that you have used it. Iif only returns a value for each item in the array. You should probably use If ... else flow control statement, which means that you will have to use your own for loop to iterate through the items in your array.
It will probably be something like this: for (i = 0; i < BarCount; i++) { if (hhhh > 1.04 * hy) { ApplyStop( 0, 1, 0, 1, volatile = False, ReEntryDelay = 0 ); } else { ApplyStop( 0, 1, 2, 1, volatile = False, ReEntryDelay = 0 ) } } I'm not expert though, so it would be good of someone more knowledgeable than be can confirm. --- In amibroker@yahoogroups.com, rink <boyri...@...> wrote: > > Hi > i tried to create a stoploss formula but there is something wrong please > correct it > > buy=cross macd, sell =cross signal > initail stoploss is 2% but when prices up 4% stoploss move to breakeven > buyprice > > > *Buy* = Cross( MACD(), Signal() ); > *Sell* = Cross( Signal(), MACD() ); > > rink=(ApplyStop( 0, 1, 0, 1, volatile = False, ReEntryDelay = 0 )); > > rin=(ApplyStop( 0, 1, 2, 1, volatile = False, ReEntryDelay = 0 )); > > Hy=ValueWhen(Buy,C,1); > hhhh=HighestSince( Buy,H,1); > IIf((Hhhh> (1.04*Hy)),rink,rin); >