Help me with last order price please

 
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.
 
rustammm1979:
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".

 
Where is the code? We cant help if we dont see the problem. Use ALT+S and paste the code, or alternatively use the code button </> and paste your code, we will then take a look and see if we can help you. Do not post generated code created by Chat Gpt or any other generators, we will see its not authentic, and you will not be helped. If we see that you made some effort in coding it yourself, we will help you
 
rustammm1979: Terminal is restarting periodically.

Before anything else, first you need to fix the issue that is causing your terminal to restart periodically.

 
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.
 

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;
   }
}
 
rustammm1979 #:
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

 
rustammm1979 #:

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.