scripts and EA's not working - page 2

 

The EA will not always open both pending buy and sell orders. I am not sure whether it is due to a fast moving market or the code is erroneous (it does compile). The orders are sent when the desired tick volume for the current bar have been reached.


	          
 
patrick007:

The EA will not always open both pending buy and sell orders. I am not sure whether it is due to a fast moving market or the code is erroneous (it does compile). The orders are sent when the desired tick volume for the current bar have been reached.

if (!hasTrade(magicNumber+1)) {
      lastTrade = Time[0];
      price = Bid-(pendingPoints2*Point);
      stopLoss = price + (stopLossPoints * Point);
      takeProfit = price - (takeProfitPoints * Point);
      OrderSend(Symbol(), OP_SELLSTOP, lotSize2, price,3,stopLoss,takeProfit,"Sell Order", magicNumber+1);
      price = Ask+(pendingPoints2*Point);
      takeProfit = price + (takeProfitPoints * Point);
      stopLoss = price - (stopLossPoints * Point);
      OrderSend(Symbol(), OP_BUYSTOP, lotSize2, price,3,stopLoss,takeProfit,"Buy Order", magicNumber+1);
   }
 
patrick007:

The EA will not always open both pending buy and sell orders. I am not sure whether it is due to a fast moving market or the code is erroneous (it does compile). The orders are sent when the desired tick volume for the current bar have been reached.

So why not find out why and fix the issue ?    why aren't you checking the return value from your OrderSend() calls ?  if they fail you can then Print() the error and any variables that will help determine the problem,  for example, Bid, Ask, Open price, SL, TP, etc.

This will help:   What are Function return values ? How do I use them ?

 
You also need to ensure that the trades you are trying to place comply with this:  Requirements and Limitations in Making Trades      do they ?
 
patrick007:

Thanks for your reply. According to the experts journal in the terminal, it says invalid lots amount for OrderSend function. Doesn't make sense when the margin is there to open the order and it opened the pending sell but not the pending buy.

Check the return value from the OrderSend()  if it shows the OrderSend() failed print the Error and relevant variables . . .  including   lotSize2  then you can check that value against  MarketInfo() with  MODE_MINLOT  &  MODE_LOTSTEP       

 

So you get error 131 ?  what does that have to do with margin ?  if it was not enough money wouldn't you expect error 134 ?

Reason: