[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 226

 
gince:

Please.

The problem with logic - I can't think of one.

Really, you have a problem with logic. You start putting pending orders as many as you like, then you want to delete all of them after one of them opens, and then you get surprised that all new ones are deleted. Then keep thinking about what should happen after the next pending order is triggered. The algorithm will depend on that.
 
Roger:
Indeed, you have a problem with logic. First you allow pending orders as much as you like, then you want to delete all of them after the opening of one of them, and then you are surprised that all new pending orders are deleted. Then keep thinking about what should happen after the next pending order is triggered. The algorithm will depend on that.

Thank you for correcting my thoughts, I'm already stuck.

After the first pending order (let's say baillimit) more pending orders may be placed in the same direction, but how do we delete all of the buy positions and orders when the signal appears in the opposite direction (let's say selimit)?

 

Good evening! Excuse me, I would like to get back to an unresolved issue.

if (!Pishem&&PozyProstavleny){SaveArray(FileBuy, Buy); SaveArray(FileSell, Sell); Pishem=1;}

'Buy' - incompatible types D:\TeleTRADE\experts/experts/clean.mq4 (102, 53)

'Sell' - incompatible types D:\TeleTRADE\experts\clearlist.mq4 (102, 79)

//записать

void SaveArray(string File, double &a[])
{
    int h = FileOpen(File, FILE_BIN|FILE_WRITE);
    if(h>0)
    {
      int sz = ArraySize(a); 
      FileWriteArray(h,a,0,sz);
      FileClose(h);
    }
}

//прочитать

void OpenArray(string File, double &a[], int sz)
{
    int h = FileOpen(File, FILE_BIN|FILE_READ);
    if(h>0)
    {
      ArrayResize(a,sz);
      FileReadArray(h,a,0,sz);
      FileClose(h);
    }
}
 
 
Because then the dialogue didn't really work out...
 
int Buy[];int Sell[];       string FileBuy="FileBuy.csv",FileSell="FileSell.csv";         

 
Hello. Could you please tell me how to write a global variable bool e.g. bool=uroven_1=false; how to write this in a global variable so that it has a new value after a terminal restart, thanks.
 
laveosa:
Hello. Could you please tell me how to write a global variable bool e.g. bool=uroven_1=false; how to write this in a global variable so it has a new value after a terminal restart, thanks.


https://book.mql4.com/ru/variables/globals
 
Roger:


The logic is correct - there should be as many position numbers in orders as there are orders, once one is closed, all the others are recalculated. Try this construction

Response.

Hello.
Unfortunately, the above described construction does not give us the required result. I would like to give you the code of the program and the tester journal entries.
Respectfully. Shurkin
March 18, 2013.

Код программы.

//+------------------------------------------------------------------+
//|                                                     Poligon1.mq4 |
//|                                            21 февраля 2013 года. |
//|Тестирование оператора цикла for.                                 |
//+------------------------------------------------------------------+
#property copyright "21 февраля 2013 года."
#property link      ""
//+------------------------------------------------------------------+
//|Объявленные переменные                                            |
//+------------------------------------------------------------------+
int Mn=357;//Magic number
int i;//Показатель счётчика итераций
double PriTP;//TP серии
int Tick;//Счётчик тиков
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----Установка серии ордеров
OrderSend(Symbol(),OP_BUY,0.5,Ask,0,NormalizeDouble(Bid-35*Point,Digits),
NormalizeDouble(Ask+35*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUY,1,Ask,0,NormalizeDouble(Bid-25*Point,Digits),
NormalizeDouble(Ask+25*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUY,1.5,Ask,0,NormalizeDouble(Bid-15*Point,Digits),
NormalizeDouble(Ask+15*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUY,2.5,Ask,0,NormalizeDouble(Bid-15*Point,Digits),
NormalizeDouble(Ask+15*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUY,3.5,Ask,0,NormalizeDouble(Bid-15*Point,Digits),
NormalizeDouble(Ask+15*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUYLIMIT,1,NormalizeDouble(Ask-15*Point,Digits),0,
NormalizeDouble(Bid-40*Point,Digits),NormalizeDouble(Ask+25*Point,Digits),
NULL,Mn,0,CLR_NONE);//OP_BUYLIMIT
OrderSend(Symbol(),OP_SELLSTOP,3,NormalizeDouble(Ask-30*Point,Digits),0,
NormalizeDouble(Bid+15*Point,Digits),NormalizeDouble(Ask-75*Point,Digits),
NULL,Mn,0,CLR_NONE);//OP_SELLSTOP
//----
   PriTP=Bid;//PriTP
   Print("Кс0:"," OrdersTotal=",OrdersTotal());//Сообщение
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   Tick++;//Tick
//   Print("Кс0:"," Tick=",Tick);//Сообщение
//----
//   for(i=0;i<OrdersTotal();i++)//Инициализация цикла
//   for(i=OrdersTotal()-1; i>=0; i--)//
   for(i=0, int k=0; i<OrdersTotal();i++,k++)//
   {
   Print("Кс1:"," Tick=",Tick," i=",i," k=",k);//Сообщение
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)//Выбор ордера i
    {
   if(OrderSymbol()==Symbol())//Символ
     {
   if(OrderMagicNumber()==Mn)//Идентификационное число
      {
   if(OrderType()==OP_BUY && OrderTakeProfit()>PriTP)//Тип операции текущего выбранного ордера
       {
   OrderClose(OrderTicket(),OrderLots(),Bid,0,CLR_NONE);//Закрытие позиции
   k--;//Зачем сначала прибавлять и тут же убавлять ???
       }//Закрыто if(OrderType()==OP_BUY && OrderTakeProfit()>PriTP)
      }//Закрыто if(OrderMagicNumber()==Mn)
     }//Закрыто if(OrderSymbol()==Symbol()
    }//Закрыто if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
   }//Закрыто for(i=0;i<OrdersTotal();i++)
//----
   return(0);
  }
//+------------------------------------------------------------------+
Записи в журнале тестера.
2013.03.18 09:42:48 2013.02.11 12:16  Poligon1 EURUSD,M15: Кс1: Tick=5 i=1 k=1
2013.03.18 09:42:48 2013.02.11 12:16  Poligon1 EURUSD,M15: Кс1: Tick=5 i=0 k=0
2013.03.18 09:42:24 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=4 i=1 k=1
2013.03.18 09:42:24 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=4 i=0 k=0
2013.03.18 09:42:00 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=3 i=1 k=0
2013.03.18 09:42:00 2013.02.11 12:15  Poligon1 EURUSD,M15: close #4 buy 2.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 at price 1.3393
2013.03.18 09:42:00 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=3 i=0 k=0
2013.03.18 09:41:36 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=2 i=2 k=1
2013.03.18 09:41:36 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=2 i=1 k=0
2013.03.18 09:41:36 2013.02.11 12:15  Poligon1 EURUSD,M15: close #2 buy 1.00 EURUSD at 1.3397 sl: 1.3370 tp: 1.3422 at price 1.3394
2013.03.18 09:41:36 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=2 i=0 k=0
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=1 i=3 k=0
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: close #5 buy 3.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 at price 1.3395
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=1 i=2 k=0
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: close #3 buy 1.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 at price 1.3395
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=1 i=1 k=0
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: close #1 buy 0.50 EURUSD at 1.3397 sl: 1.3360 tp: 1.3432 at price 1.3395
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс1: Tick=1 i=0 k=0
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: Кс0: OrdersTotal=7
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: open #7 sell stop 3.00 EURUSD at 1.3367 sl: 1.3410 tp: 1.3322 ok
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: open #6 buy limit 1.00 EURUSD at 1.3382 sl: 1.3355 tp: 1.3422 ok
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: open #5 buy 3.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 ok
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: open #4 buy 2.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 ok
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: open #3 buy 1.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 ok
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: open #2 buy 1.00 EURUSD at 1.3397 sl: 1.3370 tp: 1.3422 ok
2013.03.18 09:41:12 2013.02.11 12:15  Poligon1 EURUSD,M15: open #1 buy 0.50 EURUSD at 1.3397 sl: 1.3360 tp: 1.3432 ok
2013.03.18 09:41:12 Poligon1 test started
2013.03.18 09:40:59 Poligon1: loaded successfully

 
barok2:

When testing the WOC0.1.2 Expert Advisor in the MT4 tester (application to MT4 from Forex Club), order labels on the chart are above the prices, i.e. deals were executed at the prices which did not occur. Is this a tester glitch? Can it be corrected in some way?

http://s017.radikal.ru/i405/1303/61/959038aaf1a9.jpg

And another thing: in the visualization mode of the tester, the deals are executed, but not without it.


I figured it out on my own. It's because of increased spread (81) on the tester at weekends.
 
Shurkin:
That's because you copied my example wrong. Look carefully where is the i and where is the k.
Reason: