Problem Opening Trade

 

Hi,

I have come across a problem when trying to open trade right away after closing a trade. However, i can see in logs telling trade did open but actual trade is not open. Here is my code for the condition;


// Close Trade when market is not moving upward from its current candle start and reverses
            if(Close_buf[0]<Open_buf[1])
            {
               if(m_Trade.PositionClose(my_symbol))
               {
                  last_profit=0;
                  Print("Trade Closed and I am here");
                  m_Trade.Sell(1,my_symbol); 
               }
               
            }  


I doubt there is timing delay between closing and opening of trade which does not allow to open new trade (SELL position in above case) right after closing the trade. Please help me on this. 

 
Mohammad Arif Shariati:

I have come across a problem when trying to open trade right away after closing a trade. However, i can see in logs telling trade did open but actual trade is not open. Here is my code for the condition;

I doubt there is timing delay between closing and opening of trade which does not allow to open new trade (SELL position in above case) right after closing the trade. Please help me on this. 

From your code I don't see how any position can be opened at price 0 (default) (based on https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradesell). Also, you should check the returned error code, if any.

But, from your code alone, nobody knows exactly if your m_Trade is MQL5's CTrade anyway... 

So if you need more specific help, show more of your codes... best if others can run it on their own terminal to diagnose it.

Documentation on MQL5: Standard Library / Trade Classes / CTrade / Sell
Documentation on MQL5: Standard Library / Trade Classes / CTrade / Sell
  • www.mql5.com
Successful completion of the Sell(...) method does not always mean successful execution of the trade operation. It is necessary to check the result of trade request (trade server return code) using ResultRetcode() and value returned by ResultDeal().
Reason: