The need is close order,
first close-> max value, second close--> min value,
than we have new reduced orders list and the same rule for remaining list:
first close-> max value, second close--> min value,
than again, again and again...
The aim to obtain real max relative drawdown. For example:
I assume that I have opened 5 orders as following;
first is 100 usd, second is 80 usd, third is -200 usd, fourth is -50 usd, and fifth is -10 usd
The need is to close following orders respectively: 100 usd, -200 usd, 80 usd, -50 usd, and -10 usd.
By this way, I want to achive a real max relative drawdown for trader who opens nt only one order at the same time.
Hello,
I am trying to write a code which closes orders by rule. However, I could not get a success.
The need is close order,
first close-> max value, second close--> min value,
than we have new reduced orders list and the same rule for remaining list:
first close-> max value, second close--> min value,
than again, again and again...
The aim to obtain real max relative drawdown.
For example:
I assume that I have opened 5 orders as following;
first is 100 usd, second is 80 usd, third is -200 usd, fourth is -50 usd, and fifth is -10 usd
The need is to close following orders respectively: 100 usd, -200 usd, 80 usd, -50 usd, and -10 usd.
By this way, I want to achive a real max relative drawdown for trader who opens nt only one order at the same time.
Best, Murat Y.
Hello,
I hope it helps you.
<Moderator's Note: the following code is MQL5 and will not work in MQL4>
//+------------------------------------------------------------------+ //| Prueba.mq5 | //| Simón Del Vecchio | //| https://www.mql5.com/es/users/simondelvecchio | //+------------------------------------------------------------------+ #property copyright "Simón Del Vecchio" #property link "https://www.mql5.com/es/users/simondelvecchio" #property version "1.00" //+------------------------------------------------------------------+ //| Includes | //+------------------------------------------------------------------+ #include <Trade\SymbolInfo.mqh> #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\AccountInfo.mqh> //+------------------------------------------------------------------+ //| Objetos | //+------------------------------------------------------------------+ CSymbolInfo Info; CTrade Trade; CPositionInfo Posicion; CAccountInfo Cuenta; //+------------------------------------------------------------------+ //| Inputs | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Variables globales | //+------------------------------------------------------------------+ string Recorrido = "Even"; //+------------------------------------------------------------------+ //| Función de inicialización del EA | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { for(int i = PositionsTotal() - 1; i >= 0; i--) { ClosePositions(); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ClosePositions() { double MaxActual = 0; double MinActual = 0; ulong Ticket = 0; for(int i = PositionsTotal() - 1; i >= 0; i--) { Posicion.SelectByIndex(i); //In even we look for the maxima and in odd we look for the minima if(Recorrido == "Even" && Posicion.Profit() > MaxActual) { MaxActual = Posicion.Profit(); Ticket = Posicion.Ticket(); } else if(Recorrido == "Odd" && Posicion.Profit() < MinActual) { MinActual = Posicion.Profit(); Ticket = Posicion.Ticket(); } } Trade.PositionClose(Ticket, -1); if(Recorrido == "Even") Recorrido = "Odd"; else Recorrido = "Even"; } //+------------------------------------------------------------------+
Thank you, Antonio Simon! A very great code...
For the aim, it works to get real max relative drawdown.
I will use it. Best.
You have posted your topic in the MQL4 and MT4 section.
Yet you seem to think that MQL5 code is useful to you!
Please confirm whether your code is MQL4 or MQL5. If you have posted in the wrong section, I will move your topic.
You have posted your topic in the MQL4 and MT4 section.
Yet you seem to think that MQL5 code is useful to you!
Please confirm whether your code is MQL4 or MQL5. If you have posted in the wrong section, I will move your topic.
Right topic! I just understood the idea.
string Recorrido = "Even";
Void OnTick()
{
for(int i = OrdersTotal() - 1; i >= 0; i--) _trade.ClosePositions();
}
void Trade::ClosePositions()
{
double MaxActual = 0;
double MinActual = 0;
ulong Ticket = 0;
int slippage=0;
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
//In even we look for the maxima and in odd we look for the minima
if(Recorrido == "Even" && OrderProfit()> MaxActual )
{
MaxActual = OrderProfit();
Ticket = OrderTicket();
}
else
{
if(Recorrido == "Odd" && OrderProfit()< MinActual )
{
MinActual = OrderProfit();
Ticket = OrderTicket();
}
}
}
OrderClose(Ticket,OrderLots(),OrderClosePrice(),slippage,clrAliceBlue);
if(Recorrido == "Even") Recorrido = "Odd";
else Recorrido = "Even";
}
In your first screenshot, you will see "Forum" in the bar at the top.
Click on that and the window will open with all the forum sections.
In other words, the people who want to help in the forum, should not click on the links on the first page but enter through other links! That way we will be aware of the category in which we are helping. Something is wrong. I'll keep that in mind for the next one.
You can also go to the top of a page and hover your mouse over the bent arrow at the top left. The category will pop up.
- 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,
I am trying to write a code which closes orders by rule. However, I could not get a success.
The need is close order,
first close-> max value, second close--> min value,
than we have new reduced orders list and the same rule for remaining list:
first close-> max value, second close--> min value,
than again, again and again...
The aim to obtain real max relative drawdown.
For example:
I assume that I have opened 5 orders as following;
first is 100 usd, second is 80 usd, third is -200 usd, fourth is -50 usd, and fifth is -10 usd
The need is to close following orders respectively: 100 usd, -200 usd, 80 usd, -50 usd, and -10 usd.
By this way, I want to achive a real max relative drawdown for trader who opens nt only one order at the same time.
Best, Murat Y.