I am using metatrader 5 and am currently developing an EA for the platform. I hope you guys can help me out with a small problem.
I am using the below code to check if there is a trade placed in my expert advisor and if there is what kind of trade is it (BUY/SELL).
Further, I use the value of Buy_opened/Sell_Opened to send an order in the respective opposite direction (i.e. to close an open trade).
I use the following code to close an open position :
//Buy Order Exit
//Sell Order Exit
The problem is that when first block is executed Buy_Opened and Sell_Opened become false, after that suppose a sell order is placed and hence sell_opened becomes true now when it enters if(Sell_Opened) in the second block, it executes a buy order in opposite direction,therefore, closing the previous opened trade...Now no trades are opened...Now when First Block is executed again it does not set the values of BUY_OPENED and SELL_OPENED to false instead it sets the value of Buy_Opened(the last order that was used to close the previous order) as true. Can anyone help me with amateur problem of mine? Thank you in advance.
Forum on trading, automated trading systems and testing trading strategies
Please use the SRC button when you post code. Thank you.
This time, I edited it for you.
It's impossible to help you without a complete view of your problem. Can you post the full code related to order sending ?
Can you post the logs ?