I could be wrong, but is closing a position supposed to immediately change the balance? Is something else at play, like the settlement period?
I’ve been trading for awhile. I’ve used several different brokers over the years. I’ve never experienced a time when my account wasn’t changed immediately after closing a position.
Right
now I don't have a broker, so I'm just using a default MT5 demo account. I'm also back testing an EA, so do you know if there's something I'm
missing, like a function call to update the balance?
Right now I don't have a broker, so I'm just using a
default MT5 demo
account. I'm also back testing an EA, so do you know if there's something I'm missing, like a function call to update the
balance?
This is what is happening in my journal log:
conditions met to close short position
Short position closed
New positions closed, 0 open positions remain
Equity = 295.7 Margin = 218.98 Balance = 300
This is what is happening in my journal log:
conditions met to close short position
Short position closed
New positions closed, 0 open positions remain
Equity = 295.7 Margin = 218.98 Balance = 300
Are you sure 0 position remains ? Sending a request to close doesn't mean the position is already closed.
if((Short_Position_Exit_1 || Short_Position_Exit_2) && positionStatus==2) { Print("conditions met to close short position"); //ZeroMemory(mrequest); //ZeroMemory(mresult); mrequest.action=TRADE_ACTION_CLOSE_BY; // type of trade operation mrequest.price=NormalizeDouble(latest_price.ask,_Digits); //mrequest.sl=NormalizeDouble(latest_price.ask+STP*_Point,_Digits); // mrequest.tp=NormalizeDouble(latest_price.bid-TKP*_Point,_Digits); //Print("Attempmted stop value: ",NormalizeDouble(latest_price.bid+STP*_Point,_Digits)); mrequest.symbol=_Symbol; //mrequest.volume=Lot; mrequest.magic=EA_Magic; mrequest.type=ORDER_TYPE_CLOSE_BY; //mrequest.type_filling=ORDER_FILLING_FOK; //mrequest.deviation=100; OrderSend(mrequest,mresult); Print("Short position closed"); Print("New positions closed",PositionsTotal()); positionStatus=0; Print("Equity = ",currentSymbol.Equity(),"FreeMargin = ",currentSymbol.FreeMargin(),"Balance =",currentSymbol.Balance()); }
You are right, I am having difficulty closing my positions. It is saying I have an invalid request.
Use CTrade if you can't manage to work with OrderSend() directly.
#include <Trade\Trade.mqh> #include <Trade\AccountInfo.mqh> #include <Object.mqh> CTrade trade; code... trade.PositionClose(Symbol());
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use