I don't fully understand your problem.
Look at ...\MQL5\Include\Trade\Trade.mqh
There you can find how to select an open position, to close a position and how positions are closed one by another:
bool PositionCloseBy(const ulong ticket,const ulong ticket_by);
Hello everyone , i wondered if i could get some assistance or suggestions here, Im very new to coding and have been studying it for just 5 weeks
i have wrote a code which works more or less, one problem with it is that sometimes it will enter two open positions. For example it can buy to open a position and if the sell to close order fails the position count still goes to 0 and therefore it will open another buy position.
what can i do to get a confirmation that the sell transaction is confirmed and then reset
the positionCount to 0 after the deal is confirmed and then change the position count to 1 when it has a confirmed buy trade ?
I have shown the points i believe needs changing but what i have coded is just theoretical , is there an option to get the deal confirmation so it only adds or takes away from the poisitioncount ?
Thank you in advance for your assistance :)
Show your codes. We cant read your mind
Sorry i thought i had added the code ,
Basically i have set up the positioncount and that works but what has happened is that it sent the order to sell and it was not successful, but the positioncount resets and it takes a second buy to open order so then it hold to open positions and sort of forgets about the one it missed. I would liek help to fix it so the position count only resets on a confirmation of the sale. :)
{ isBuySignalTriggered = true; // Set the buy signal flag if(isBuySignalTriggered && My_RSI_Value > My_RSI_Value_Index1) { trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Trade_Size_Limit,0,0,0,NULL); trade.ResultRetcode(); trade.ResultDeal(); positionCount++; // Increment position count printf("ACCOUNT_BALANCE = %G",AccountInfoDouble(ACCOUNT_BALANCE)); printf("ACCOUNT_EQUITY = %G",AccountInfoDouble(ACCOUNT_EQUITY)); } } if ((My_RSI_Value > RSI_Upper_Limit) && (positionCount > 0)) { isSellSignalTriggered = true; if(isSellSignalTriggered && My_RSI_Value < My_RSI_Value_Index1) { trade.PositionClose(_Symbol,0); trade.ResultRetcode(); Print("ResultRetcode: ",trade.ResultRetcode()); trade.ResultDeal(); Print("ResultDeal: ", trade.ResultDeal()); positionCount--; // Decrement position count Print("Position Count: ", positionCount); { printf("ACCOUNT_BALANCE = %G",AccountInfoDouble(ACCOUNT_BALANCE)); printf("ACCOUNT_EQUITY = %G",AccountInfoDouble(ACCOUNT_EQUITY)); }
I have actually figured out how to do it now , using the TRADE_RETCODE_DONE :)
Thanks anyway
if (trade.ResultRetcode() == TRADE_RETCODE_DONE) { trade.ResultDeal(); positionCount++; } // Increment position count
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone , i wondered if i could get some assistance or suggestions here, Im very new to coding and have been studying it for just 5 weeks
i have wrote a code which works more or less, one problem with it is that sometimes it will enter two open positions. For example it can buy to open a position and if the sell to close order fails the position count still goes to 0 and therefore it will open another buy position.
what can i do to get a confirmation that the sell transaction is confirmed and then reset
the positionCount to 0 after the deal is confirmed and then change the position count to 1 when it has a confirmed buy trade ?
I have shown the points i believe needs changing but what i have coded is just theoretical , is there an option to get the deal confirmation so it only adds or takes away from the poisitioncount ?
Thank you in advance for your assistance :)