Okay, so I've found a solution.
I was using TRADE_ACTION_DEAL type while sending order in OrderSend(). In documentation on struct MqlTradeResult is written:
and as I used request.deal it retuned 0, so I used request.order to see how it's going to works.
I was using TRADE_ACTION_DEAL type while sending order in OrderSend(). In documentation on struct MqlTradeResult is written:
deal | Deal ticket, if a deal has been performed. It is available for a trade operation of TRADE_ACTION_DEAL type |
and as I used request.deal it retuned 0, so I used request.order to see how it's going to works.
order | Order ticket, if a ticket has been placed. It is available for a trade operation of TRADE_ACTION_PENDING type |
And it does what i want.
I don't know how, because as I said, I'm using TRADE_ACTION_DEAL type, not TRADE_ACTION_PENDING type. On historical data both .deal and .order works, so I couldn't see why it was wrong.
That's part of my code if anyone wants to see how it looks:
bool makeOrder(){ [...] ZeroMemory(request); ZeroMemory(resoult); request.action =TRADE_ACTION_DEAL; request.symbol =Symbol(); request.volume =lot; request.type =type; request.price =price; request.sl =sl; request.tp =tp; request.deviation =0; request.type_filling =ORDER_FILLING_FOK; request.comment =NULL; request.magic =magicNumber; bool res=(OrderSend(request,resoult)); if(res){ orderTicket = resoult.order; readyToOrder = false; printf("set ticket to (request.order): " + orderTicket); } return res; } bool searchForOrders(){ //Looking for active positions by ticket if(PositionsTotal()>0){ if(PositionSelectByTicket(orderTicket)){ printf("Found Existing Position"); return true; } } printf("Order Not Found"); return false; }
I've made it with my own class, that's why it's all in functions if someone is curious.
I hope it helps someone someday.
Bye for now i guess.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello everyone,
I've made a function to look for position by ticket. It just chcecks if it exists.
It works on history data but i doesn't on real time chart.
The way it works is saving ticket in ulong variable orderTicket after OrderSend(request, resoult). Just orderTicket = resoult.deal and then i print them. First raw resoult.deal than orderTicket. Both are equal to 0 so it isn't overflow problem or anything because they are both ulong type.
Than I search on every tick if this position still exists by checking if(PositionsTotal()>0) and than if(PositionSelectByTicket(orderTicket)). If everything is chcecked returns true.
It works in history data where tickets are small (like #2 or #6) but on real time tickets are numbers like #1000000000. I read in a documentation that ulong can handle much bigger numbers so i don't know what is the problem.
I tried to look for opened position by EA's magic nubmer but i coulnd make it work so i did it seleckt by ticket funciton.
Main purpose of this function is to bot make more than 1 position at once
Thanks in advance to enyone who will try to help me to fix it or show me a different way to make it work.