Help code prevent buy and sell orders ea

 

I created small bollinger bands. How to prevent buy orders when the price on it.

if((Close[0]!=iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_UPPER,0))&&(Close[0]!=iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_LOWER,0))

     {

        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA",MagicNumber,0,Blue);

     }

       ....

it does not work

 

Please use the </> button to insert your code.


 
Nhựt Phạm:

I created small bollinger bands. How to prevent buy orders when the price on it.

       ....

it does not work

Do you mean that you don't want send buy order when the price closes between upper and lower Bollinger Bands lines? If  I'm right you should change your condition in this way:

if((Close[0]>iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_UPPER,0))&&(Close[0]<iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_LOWER,0)))
 
  1. Nhựt Phạm: I created small bollinger bands. How to prevent buy orders when the price on it.
    if((Close[0]!=iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_UPPER,0))&&(Close[0]!=iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_LOWER,0))
    

    it does not work

    1. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless.
    2. Doubles are rarely equal. Understand the links in:
                The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum
    3. You want inside or outside, not on.

  2. Petr Nosek: Do you mean that you don't want send buy order when the price closes between upper and lower Bollinger Bands lines? If  I'm right you should change your condition in this way:
    if((Close[0]>iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_UPPER,0))&&(Close[0]<iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_LOWER,0)))

    Sorry Petr, price will never be above the upper band and below the lower band at the same time.

  3. Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read and verify it. Write self-documenting code:

    double upper = iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_UPPER,0);
    double lower = iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_LOWER,0);
    bool   isAbove   = Bid > upper;
    bool   isBelow   = Bid < lower;
    bool   isInside  = !isAbove && !isBelow;
    bool   isOutside =  isAbove ||  isBelow;


 
whroeder1:

    Sorry Petr, price will never be above the upper band and below the lower band at the same time.

LOL Thank you for your notice. You are absolutely right and it was my fault. The code should be:

if((Close[0]>iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_UPPER,0))||(Close[0]<iBands(NULL,0,200,0.15,0,PRICE_CLOSE,MODE_LOWER,0)))
Reason: