Pending orders not placed when conditions are met - page 2

 

Kenneth Parling:

bool isBearishEngulfing(int current)
{   
    if(  (iClose(_Symbol,0,current    ) < iOpen( _Symbol,0,current    )) 
      && (iClose(_Symbol,0,current + 1) > iOpen( _Symbol,0,current + 1)) 
      && (iOpen( _Symbol,0,current    ) > iClose(_Symbol,0,current + 1)) 
      && (iClose(_Symbol,0,current    ) < iOpen( _Symbol,0,current + 1))
         )
          return true;////??
    return false; ////??     
}

returning both true and false seems odd

Absolutely nothing wrong with the returns.

If it returns true, it won't get to the next return.

 
Jackery:

My code below places sell pending orders when certain candle pattern conditions are met on the H_1 chart. At certain points the condition is met but the pending orders are not placed, as in the encircled portions in https://imgur.com/a/3pNC7M3 . I am not sure what's causing it.


It is good that you are error checking when creating the rectangle.

It is bad that you do no error checking when the OrderSend fails - print out the error and the values of the parameters in the function.

When your code first starts it checks back 300 bars and draws the rectangles. It will also try to open limit orders based on every one of those rectangles. Surely that is not what you want? Only open an order if the bar index is 1.

Once you have done that initial check of the 300 bars, don't repeat it every new bar. Only check for new conditions, then you won't clutter up the log with the errors when trying to create an object that already exists.

Other replies have already told you to check that the current price is below the entry price and that the entry must be a minimum distance from the current price. So implement these checks.