Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1030

 
Sabit Dosaev:
Simple question. The owl doesn't compile. There is an error at the end of the code. + __FUNCSIG__
+ ": "+Market_Err_To_Str(errIndex)
+ "; order ticket = " + (string)OrderTicket()
+ "; order type = " + (string)OrderType()
+ "; order Stop Loss = " + DoubleToStr(OrderStopLoss(), Digits())
+ "; new Stop Loss = " + DoubleToStr(newStopLoss, Digits())
+ "; Bid = " + DoubleToStr(Bid, Digits())
+ "; Ask = " + DoubleToStr(Ask, Digits())
);
}
}
lastSetNonlosTryTime = TimeLocal();
}


Throws a compile-time error. Please help if you can. Thank you!

Insert the code correctly:


И... it's not clear from the piece of code what your error is. The code should be reproducible.

 
string LastComm(int a_magic_0)
  {
   int l_hist_total_4 = OrdersHistoryTotal();
   int l_datetime_8 = 0;
   int l_datetime_12 = 0;
   string ls_ret_16 = "0";
   for(int l_pos_24 = 0; l_pos_24 < l_hist_total_4; l_pos_24++)
     {
      OrderSelect(l_pos_24, SELECT_BY_POS, MODE_HISTORY);
      l_datetime_8 = OrderCloseTime();
      if(l_datetime_8 > l_datetime_12 && OrderMagicNumber() == a_magic_0)
        {
         l_datetime_12 = l_datetime_8;
         ls_ret_16 = OrderComment();
        }
     }
   return (ls_ret_16);
  }

@Artyom Trishkin

How can I convert this function to MQL5 from MQL4?

 

Good afternoon to all.

Could you please tell me where to insert the function IsConnected () to determine the state of communication?

If I insert it within OnTick() function, then there is always connection (i.e. there is tick arrival, so there is connection, no tick arrival (due to its absence or absence of connection) means there is no call to OnTick() and respectively to function defining connection state IsConnected ())) On this it is useless to insert IsConnected () in frameworks OnTick () (how many times I did not switch off the Internet, all the same it does not write in a file about absence of communication)

For this reason the question where correctly to insert the IsConnected () function or what are the other ways to determine the connection status (only for MT4)

Thank you!

 
Roni Iron:

Good afternoon to all.

Could you please tell me where to insert function IsConnected () to determine communication status?

If I insert it within OnTick() function, then there is always connection (i.e. there is tick arrival, so there is connection, no tick arrival (due to its absence or absence of connection) means there is no call to OnTick() and respectively to function defining connection state IsConnected ())) On this it is useless to insert IsConnected () in frameworks OnTick () (how many times I did not switch off the Internet, all the same it does not write in a file about absence of communication)

For this reason the question where correctly to insert the IsConnected () function or what are the other ways to determine the connection status (only for MT4)

Thank you!

OnTimer()

Документация по MQL5: Обработка событий / OnTimer
Документация по MQL5: Обработка событий / OnTimer
  • www.mql5.com
//|                                               OnTimer_Sample.mq5 | //|                        Copyright 2018, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | //| Expert initialization function                                   |...
 
Roman Shiredchenko:

you have a confusion of variables and functions, if it's a function, try it this way:

ALT + S for the code

Thank you

Roman Shiredchenko:

you have confusion about variables and functions, if it's a function, try this:

ALT + S

Yes it is a function.

Thank you, but it gives an error for some reason

'}' - not all control paths return a value

although I seem to have checked everything correctly both in my code and in an empty template.

ALT + S - thank you, I will take it into account

 
wolder1:

Thank you

Yes it's a function.

Thanks, but for some reason it gives an error

'}' - not all control paths return a value

Although the brackets seem to be correct, both in my code and in the empty template.

ALT + S - thank you, I'll take it into account.

A good question contains the answer (C)

 
wolder1:

Thank you

Yes it's a function.

Thank you, but for some reason it gives an error

'}' - not all control paths return a value

Although I checked everything correctly with brackets both in my code and in an empty template.

ALT + S - thank you.

The function double should return a value, not if the function is void .

if you have variables defined above in your code, they can be commented out + you had extra spaces here (Bid > = L8b)) - Made an edit:

double lot=0; //, Lots;
//   double L0a3, L2a3, L5a3, L8a3, L0b1, L2b1, L5b1, L8b1, L0a, L2a, L5a, L8a,L0b,L2b,L5b,L8b,L0a1,L2a1,L5a1,L8a1,L0b3,L2b3,L5b3,L8b3;  
double _LOTS()
  {
   double lot=0, Lots;
   double L0a3, L2a3, L5a3, L8a3, L0b1, L2b1, L5b1, L8b1, L0a, L2a, L5a, L8a,L0b,L2b,L5b,L8b,L0a1,L2a1,L5a1,L8a1,L0b3,L2b3,L5b3,L8b3;  
   if((Ask <= L0a3) || (Ask <= L2a3) || (Ask <= L5a3) || (Ask <= L8a3) || (Bid >= L0b1) || (Bid >= L2b1) ||
      (Bid >= L5b1) || (Bid >= L8b1))
      {
       lot=(NormalizeDouble(Lots, 2));
       Print(" lot = ", lot); 
       return(lot);
      }
      
    if((Ask <= L0a) || (Ask <= L2a) || (Ask <= L5a) || (Ask <= L8a) || (Bid >= L0b) || (Bid >= L2b) ||
      (Bid >= L5b) || (Bid >= L8b))
      {
       lot=(NormalizeDouble((Lots*1.5), 2));
       Print(" lot = ", lot); 
       return(lot);
      }
     
    

   if((Ask <= L0a1) || (Ask <= L2a1) || (Ask <= L5a1) || (Ask <= L8a1) || (Bid >= L0b3) ||
      (Bid >= L2b3) || (Bid >= L5b3) || (Bid >= L8b3))      
      {
       lot=(NormalizeDouble((Lots*2.5), 2));
       Print(" lot = ", lot); 
       return(lot);
      }
    return(lot);  
  } 
 

Good morning.

Question. In the tester, at the daylight-side interface (when the next day line passes) the program should have placed a pending order. The pending order that was already there and the price touched it, it got opened but the instruction to open anotherpending order was ignored by the system for some reason. Can this also happen in a real account where the robot instructions are simply ignored and therefore the required action is not performed?


And another question. I am running a Strategy Tester but I was very confused by the fact that it goes a week or so in the visualization and then displays the following message

177564 tick events (447 bars, 7888506 bar states) processed in 0:17:42.694 (total time 0:17:48.217)

177564 tick events (447 bars, 7888506 bar states) processed at 0:17:42.694 (total time 0:17:48.217)

I don't get it, is he too busy to keep testing? Or he is so caring and worried about resources of my computer? I don't see any error messages. It simply terminates itself. Though I've set the date not 7 days, but 7 months. I'd like to see the entire test path from start to finish.

What religion does not allow him to visually test for example a year or several years? And you can visually see how your program worked during the previous year, for example.


And one more question. (Although it may be unanswered)) ) How can it happen that the tester 2 laps working as it should, and just before the above-mentioned inscription on the day just ignores all instructions. How is it possible the program worked correctly for several rounds (opened orders and then closed them), and then, boom, it ignores everything. It opens and closes neither. Is it because of the end of a testing period or there are other reasons?

 

Good afternoon!!!

I need the time of the last closed order.

I've written a function, but it doesn't work correctly.

//+------------------------------------------------------------------+

//| Time of the last order closed |

//+------------------------------------------------------------------+

double Last_Ticets_Close()

{

Last_Ticet = 0;

Last_OrClTime = 0;


for(int i=0; i<OrdersTotal(); i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY ))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)

{

if(Last_Ticet<OrderTicket())

{

Last_Ticet = OrderTicket();

Last_OrClTime = OrderCloseTime();

}

}

}

}

return (Last_Ticet);

}

Can anyone tell me what's wrong.

 
142vs:

Good afternoon!!!

I need the time of the last closed order.

Wrote a f-iio, but it doesn't work correctly.

Can anyone suggest what is wrong.

when searching for a later time , compare times, not tickets