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

 
Vitek, use the SRC button to insert code! Who needs to dig through unreadable scribbles?!
 
pu6ka:
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.

What does the quality of testing depend on and how can it be increased to the maximum?
 
Zver4991:

and what does the quality of testing depend on and how can it be improved towards the maximum?
I honestly don't know. I haven't needed to yet, look it up on the website
 

Dear Professionals.
Could you please tell me how to open a grid of pending orders without using cycles?
If not difficult, please show at least a rough example of such code,
with possibility to change step and lot size of each successive order of the grid.

 
Forexman77:
I put lines

instead ofint Ticket; errors come out:

'=' - left square parenthesis expected for array('=' - Left square bracket, expected for array)

'>' - left square parenthesis expected for array ('=' - Left square bracket expected for array)

'>' - unexpected token('>' - Unexpected token)

')' - assignment expected('' - assignment expected )

'continue' - 'break' or 'continue' used within some loops only )

and a lot more.


So Ticket is still being used somewhere in the old version. We need to clean up the code...
 
1mql:

Dear Professionals.
Could you please tell me how to open a grid of pending orders without using loops?
If it is not difficult, please show at least a rough example of such code,
If you can change step and lot size of each subsequent order in the grid.

Yes, actually, it is the same as in a loop... ...but without the loop. Show us how you open in a loop and explain why you don't want to use loops, because it's unclear what you are trying to achieve.
 
borilunad:
Vitek, use the SRC button to paste the code! Who needs to dig through unreadable scribbles!

//+------------------------------------------------------------------+
//| удаления и/или закрытие ордера, с фильтрацией его по объему |
//---------------------------------------------------------------------
#property show_inputs
//--------------------------------------------------------------------
extern double MinLot = 0.01; //минимальный лот который удаляем/закываем
extern double MaxLot = 0.1; //максимальный лот который удаляем/закываем
extern bool Buy = false; //удалять/закрывать направление buy ордеров
extern bool Sell = false; //удалять/закрывать направление sell ордеров
extern bool pending = true; //удалить отложенные ордера
extern bool market = true ; //закрыть рыночные позиции
extern int slippage = 2; //проскальзывание цены при закрытии рыночных позиций
//--------------------------------------------------------------------
int start()
{
double SL,TP;
string txt=StringConcatenate("Скрипт удаления или закрытие ордера, старт ",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,"\nЗакрыт ордер BUY ",Ticket);
else txt = StringConcatenate(txt,"\nОшибка закрытия ",GetLastError());
}
if (OT==OP_SELL)
{
error=OrderClose(Ticket,OrderLots(),NormalizeDouble(Ask,Digits),slippage,Blue);
if (error) txt = StringConcatenate(txt,"\nЗакрыт ордер SELL ",Ticket);
else txt = StringConcatenate(txt,"\nОшибка ",GetLastError()," закрытия ",Ticket);
}
if (OT>1)
{
error=OrderDelete(Ticket);
if (error) txt = StringConcatenate(txt,"\nУдален ордер ",StrOrdersType(OT)," ",Ticket);
else txt = StringConcatenate(txt,"\nОшибка ",GetLastError()," удаления ",StrOrdersType(OT)," ",Ticket);
}
if (!error)
{
Error = GetLastError();
if (Error<2) continue;
if (Error==129)
{ Comment("Неправильная цена ",TimeToStr(TimeCurrent(),TIME_SECONDS));
Sleep(5000);
RefreshRates();
continue;
}
if (Error==146)
{
j++;
if (IsTradeContextBusy()) Sleep(2000);
continue;
}
Comment("Ошибка ",Error," закрытия ордера 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("Не удалось закрыть все сделки, осталось еще ",n);break;}
Sleep(1000);
RefreshRates();
}
Comment(txt,"\nСкрипт закончил свою работу ",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 to close all open orders on all pairs by lot size.

 
Vitek2010:

What should I add or change to close all open orders on all pairs by lot size.

Below the last extern:
extern int slippage = 2; // price slippage when closing market positions

insert another one:
extern bool total_symb = true; //on all pairs

and on each line:
if ((OrderSymbol() == Symbol())
и
if(OrderSymbol() == Symbol())

replace with this one:
if(OrderSymbol() == Symbol() || total_symb)

Theoretically it should work, check it.

 
Question has arisen, is it possible to write an Expert Advisor or script, which would be to achieve for example a 2% loss on the day would close all transactions?
 
Profitov:
Question has arisen, is it possible to write an Expert Advisor or script, which would be to achieve for example a 2% loss on the day would close all transactions?

It is possible.
Reason: