condition fulfilled, but the code doesn't executed?

 

Hi there,

i want to ask simple question, i've been searching through this error for quite a long time

my code is

if(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0)<=Close[0]) // hit upper bollinger or pass
         {
            ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"Open Sell");
            if(ticket<0)
            {
            Alert("OrderSend sell failed with error #",GetLastError());
            return(0);
            }
         }

but when the price hit my lower bollinger, it didn't open any order.

when the price go down further, then the order is opened..i wonder why when it hit my lower bollinger, it didn't open any order as what i coded down. only if it pass far then it would open the position.

can anyone help me?

 
lucif:


but when the price hit my lower bollinger, it didn't open any order.

Your code talks about . . . . // hit upper bollinger or pass
 
RaptorUK:
Your code talks about . . . . // hit upper bollinger or pass

oh, sorry, my mistake...mistype

i mean when it hit or pass the upper bollinger, it should have open a position, but the fact, it doesn't. It should wait until the price pass through far from the upper bollinger then it would open the position


any idea?

 
lucif:

Hi there,

i want to ask simple question, i've been searching through this error for quite a long time

my code is

but when the price hit my lower bollinger, it didn't open any order.

when the price go down further, then the order is opened..i wonder why when it hit my lower bollinger, it didn't open any order as what i coded down. only if it pass far then it would open the position.

can anyone help me?

I think you ment to do this >=. Also, Close[0]? Isn't that the bar you are on which has not closed yet, I think you want Close[1] which should be the same price as Open[0].
if(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0)>=Close[0]) // <--- now it will hit or pass  >= not <=    
         
 
danjp:
I think you ment to do this >=. Also, Close[0]? Isn't that the bar you are on which has not closed yet, I think you want Close[1] which should be the same price as Open[0].

actually what i mean by using Close[0] is because i want to refer to the running price. If i use Close[1] or Open[0], then it would return me the Close price for the previous bar, right?

Also for >=, then the condition would be fullfilled all the time if the price stay under the upper bollinger, is it?

Reason: