Help code prevent buy and sell orders ea

To add comments, please log in or register
Minh Nhut Pham
19
Minh Nhut Pham  

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

Juvenille Emperor Limited
Moderator
10225
Eleni Anna Branou  

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


Petr Nosek
3023
Petr Nosek  
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)))
William Roeder
20208
William Roeder  
  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;


Petr Nosek
3023
Petr Nosek  
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)))
To add comments, please log in or register