Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 450

 
Vitek2010:
I'm looking for a script that closes all orders by lot size, all meaning all (and not choosing by magic number, low low, etc.), so all orders would be closed and could be filtered by lot size only.
So the usefulness of such filtration is obvious only to you. :)))
 
Vitek2010:
I'm looking for a script that closes all orders by lot size, all of them (and not with the right to select the number of magicians, low lowes etc.) to close all orders at all pairs and only the lot size can filter them.
There must be some. Do a kodobase search with a script filter.
 

why trades are opened and closed at prices that do not exist.... how to fix this and how to improve modelling quality

 
Zver4991:

why trades are opened and closed at prices that do not exist....

At prices that do not exist... The price chart is based on Bid, and the Ask price is also involved when opening or closing trades.
 

Has anyone reworked the EA from the https://book.mql4.com/ru/samples/expert tutorial so that it opens and closes an unlimited number of orders? I can't get it to work. I can open several deals, but I cannot close them all at reversal. It closes one order and immediately opens the opposite one. I really need it. I have already learnt MQL4, but I am not familiar with arrays and functions of orders.

 
fozi:
There must be some of these here. Do a search on kodobase with a filter on scripts.

Excuse me, for those who are not very bright, where is this? on which resource and what to type into the search engine. or give me a link.
 
Vitek2010:

Sorry, for the not-so-smart, where is this? on what resource and what to type into the search engine. or give me a link straight away.

Not exactly by lot, but maybe you can adapt it
 
pu6ka:
At prices that are not visible... The price is plotted at Bid, and when opening or closing trades, the Ask price is also involved.


i.e. they are absolutely real and the test results may be considered correct? ...... how to view all prices
 
Zver4991:

so they are absolutely real and the test results can be considered correct? ...... how do i make all prices visible
Yes, Ask prices are not visible, but they are :)
In the visualizer, you can press pause and select "Show Ask Line" in the chart properties and continue testing. The price chart in MT4 is normally plotted by Bid.
 
//+------------------------------------------------------------------+
//| delete and/or close an order, filtered by volume |
//---------------------------------------------------------------------
#property show_inputs
//--------------------------------------------------------------------
extern double MinLot = 0.01; //minimal lot which is to be deleted/closed
extern double MaxLot = 0.1; //maximal lot that is deleted/bypassed
extern bool Buy = false; //delete/close direction of buy orders
extern bool Sell = false; //delete/close direction of sell orders
extern bool pending = true; //delete pending orders
extern bool market = true; //close market positions
extern int slippage = 2; //slippage of price at closing of market positions
//--------------------------------------------------------------------
int start()
{
double SL,TP;
string txt=StringConcatenate("Script remove or close order, start ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
RefreshRates();

bool error=true;
int Error,OT,Ticket,nn;
double OOP,OL;
while(true)
{
for (int j = OrdersTotal()-1; j >= 0; j--)
{
if (OrderSelect(j, SELECT_BY_POS))
{
if ((OrderSymbol() == Symbol())
{
OL = OrderLots();
if (OL<MinLot || OL>MaxLot) continue;
OT = OrderType();
if (!market && OT<2) continue;
if (!pending && OT>1) continue;
Ticket = OrderTicket();
OOP = OrderOpenPrice();
if (OT==OP_BUY)
{
error=OrderClose(Ticket,OrderLots(),NormalizeDouble(Bid,Digits),slippage,Red);
if (error) txt = StringConcatenate(txt,"\nClosed BUY Order",Ticket);
else txt = StringConcatenate(txt,"\nClosing error ",GetLastError());
}
if (OT==OP_SELL)
{
error=OrderClose(Ticket,OrderLots(),NormalizeDouble(Ask,Digits),slippage,Blue);
if (error) txt = StringConcatenate(txt, "SELL order closed",Ticket;)
else txt = StringConcatenate(txt,"\nError ",GetLastError()," close ",Ticket);
}
if (OT>1)
{
error=OrderDelete(Ticket);
if (error) txt = StringConcatenate(txt,"\nOrderDeleted ",StrOrdersType(OT)," ",Ticket);
else txt = StringConcatenate(txt,"\nError ",GetLastError()," removal ",StrOrdersType(OT)," ",Ticket);
}
if (!error)
{
Error = GetLastError();
if (Error<2) continue;
if (Error==129)
{ Comment("Incorrect price ",TimeToStr(TimeCurrent(),TIME_SECONDS));
Sleep(5000);
RefreshRates();
continue;
}
if (Error==146)
{
j++;
if (IsTradeContextBusy()) Sleep(2000);
continue;
}
Comment("Error ",Error," closing order N ",OrderTicket(),
",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
}
}
}
int n=0;
for (j = 0; j < OrdersTotal(); j++)
{
if (OrderSelect(j, SELECT_BY_POS))
{
if (OrderSymbol() == Symbol())
{
OL = OrderLots();
if (OL<MinLot || OL>MaxLot) continue;
OT = OrderType();
if (!market && OT<2) continue;
if (!pending && OT>1) continue;
n++;
}
}
}
if (n==0) break;
nn++;
if (nn>10) {Comment("Failed to close all trades, there is still ",n);break;}
Sleep(1000);
RefreshRates();
}
Comment(txt,"\nScript has finished its work ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
return(0);
}
//--------------------------------------------------------------------
string StrOrdersType(int t)
{
if (t==OP_BUY) return("Buy");
if (t==OP_SELL) return("Sell");
if (t==OP_BUYLIMIT) return("BuyLimit");
if (t==OP_SELLLIMIT) return("SellLimit");
if (t==OP_BUYSTOP) return("BuyStop");
if (t==OP_SELLSTOP) return("SellStop");
}

//--------------------------------------------------------------------

What should I add or change in the script to close all open orders for all pairs by lot size.

Reason: