- Selecting last order opened
- How to compare for martingale...
- MT5 Account a Order can not Delete ,But use margin, Why ?
Hello. Terminal is restarting periodically. So, LastOrderPrice is loosing. I want that when LastOrderPrice is lost because of restarting terminal and if OpenPosition >0, LastOrderPrice must be equal to the LastTicketPrice. Who can help me? the problem is the last ticket may be either in Open Position or in closed Position. Code must check both lists and must take which one is the last. I don't use here pending orders.
you need to post your code with Code S if you want help. If you do not, then, your only responses will be "We cant see your screen" OR "We cant read your mind", OR, my favorite "Our Crystal balls are Cracked".
Before anything else, first you need to fix the issue that is causing your terminal to restart periodically.
Here, LastOrderPrice=Bid must be altered to the last order Ticket Price, not to Bid, current price. My next formulas are depended on it.
Here, last order price must be found by the last ticket price. question is simple.
#include<Trade\Trade.mqh> CTrade trade; double lastOrderPrice = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); void OnTick() { double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits); if (PositionsTotal() == 0) { trade.Sell(0.01, NULL, Bid, Bid + 20000 * _Point, Bid - 19840 * _Point, NULL); lastOrderPrice = Bid; return; } if (MathAbs(Bid - lastOrderPrice) >= (19840) * _Point) { trade.Sell(0.01, NULL, Bid, Bid + 20000 * _Point, Bid - 19840 * _Point, NULL); lastOrderPrice = Bid; // Update last order price to current Bid return; } if (MathAbs(lastOrderPrice - Ask) >= (19840) * _Point) { trade.Buy(0.01, NULL, Ask, Ask - 20000 * _Point, Ask + 19840 * _Point, NULL); lastOrderPrice = Ask; // Update last order price to current Bid return; } }
this is also good solution. Now, the second detail of my question. Assume, we fix equity when we restart (openposition=0), when equity is => 1% from fixed equity, close all orders, restart. I need this code too. Thanks.
Has anybody answer to this question? If it is so difficult, let me ask another version: CloseBy till BuyPositions=SellPositions: If Equity > Balance+Profit
I use here only TakeProfit. I open many buys and sells by formula. It doesn't matter. But CloseBy must balance Buy and Sell lots when Equity > Balance for Profit
For example, buy closed with TP. sell order to close must be chosen by its TP. Which TP is the farthest, that order must be closed first. You can use either closeBy or close by its TP which is the farthest from MarketPrice
Has anybody answer to this question? If it is so difficult, let me ask another version: CloseBy till BuyPositions=SellPositions: If Equity > Balance+Profit
I use here only TakeProfit. I open many buys and sells by formula. It doesn't matter. But CloseBy must balance Buy and Sell lots when Equity > Balance for Profit
For example, buy closed with TP. sell order to close must be chosen by its TP. Which TP is the farthest, that order must be closed first. You can use either closeBy or close by its TP which is the farthest from MarketPrice
it is not difficult or challenging. This is why you have not recieved a response. I recommend that you look in codebase. There is many eas that list both open and historical trades and then select the most recently opened -- or closed trade. Copy that code and modify that for your needs.
We do not "spoon feed" anyone here.
EDIT: if after you have shown that you have made a further attempt at solving the problem yourself, then, you are more likely to get further help.- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use