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

 

Guys, I have a function OnTimer() which should be executed at the beginning of each day and at certain result of execution EA should go to sleep. If I set time of next execution for function OnTimer() to the beginning of next day and after it the EA will go to sleep till the same moment (-1 second for example), the time counter will still be running and function will be executed after coming out of sleep after 1 second?


P. S. Another slightly worrying question, how could the documentation be written in such a cheesy style? I mean code spaces and staging of brackets, I've never seen anyone except "schoolchildren on programming labs" and guys who write in mql produce something like this

for(int x=0;x<10;x++)

{

}


The site corrects itself somehow, about parentheses I mean that parentheses are placed with tabulation, i.e. we cannot trace vertically intuitively where a parenthesis goes.

 
ukrop1203:

Guys, I have a function OnTimer() which should be executed at the beginning of each day and at certain result of execution EA should go to sleep. If I set time of next execution for function OnTimer() to the beginning of next day and after it the EA will go to sleep till the same moment (-1 second for example), the time counter will still be running and function will be executed after coming out of sleep after 1 second?


P. S. Another slightly worrying question, how could the documentation be written in such a cheesy style? I mean code spaces and staging of brackets, I've never seen anyone except "schoolchildren on programming labs" and guys who write in mql produce something like this

for(int x=0;x<10;x++)

{

}


As for parentheses, I mean that parentheses are placed with tabulation, i.e. it is impossible to follow intuitively where a parentheses goes vertically.

You can't trace vertically where the parenthesis goes, so you won't be able to see where it goes. You may put it to sleep for 5 minutes and put Print in OnTimer every 10 seconds. This will answer your question. Why go to sleep if you can simply change the key that determines the mode of the main algorithm in any other functions?

 

Hi all!


QUESTION on MT5. The text marks (numbers) are put as a thin grey bar. The dots are a control buffer to visualise the MT5 bloopers in my head....


Compared with Documentation for OBJ_TEXT, seems to be the same....

//| Вывод текстовой метки с размером интервала "тела" свечи          |
//+------------------------------------------------------------------+
void LabText(const long  chart_ID=0,
             string      name="Text", 
             string      text="text", // ТЕКСТ ДЛЯ ВЫВОДА НА ГРАФИК
             datetime    time=0, 
             double      price=0,
             int         fontsizes=0,
             color       clr=0)
  {
  if(ObjectFind(chart_ID,name)!=0)
     {
   ObjectCreate(chart_ID,name,OBJ_TEXT,0,0,0);
   ObjectSetInteger(chart_ID,name,OBJPROP_TIME,time);
   ObjectSetDouble(chart_ID,name,OBJPROP_PRICE,price);
//--- установим угол наклона текста 
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,0.0); 
//--- установим способ привязки 
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,ANCHOR_LEFT); 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
   ObjectSetString(chart_ID,name,OBJPROP_FONT,"Arial");
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,fontsizes);
//--- скроем (true) или отобразим (false) имя графического объекта в списке объектов 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,true);
     }
  }

********************** В КОДЕ *********************************
    

    double  LW=iLow(NULL,PERIOD_H1,i);  //   ЦИКЛ I

                        *********** 

   LabText(0,"NAME  ("+string(i)+")",DoubleToString(bbull[i],0),iTime(NULL,PERIOD_H1,i),
              LW-(8*_Point),12,clrWhite);
   ExtLineBuffer1[i]=iHigh(NULL,PERIOD_H1,i);


 
kopeyka2:

Hi all!


QUESTION on MT5. The text marks (numbers) are put as a thin grey bar. The dots are a control buffer to visualise the MT5 bloopers in my head....


Compared with Documentation for OBJ_TEXT, seems to be the same....


See what you pass in the fontsizes parameter

 
Artyom Trishkin:

See what you pass in the fontsizes parameter

THANK YOU!!! Ihave put infontsizes from global variables. Set it in the void LabText function. It worked...


 

I want to add and delete indicators on the chart with the script, as applying the template deletes all the lines drawn.


#property indicator_label1  "MA8"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1


int indicator_handle;

void OnStart()
  {

   indicator_handle = iMA(0,0,8,0,MODE_EMA,PRICE_CLOSE);

   Print(indicator_handle);

   //ChartIndicatorAdd(0,0,indicator_handle);

   
  }

I get reply

2019.01.24 19:14:53.633 add_ind (EURJPY,H1) cannot load indicator 'Moving Average' [4302]

2019.01.24 19:14:53.633 add_ind (EURJPY,H1) -1


Code compiles without errors though.


 
psyman:

I want to add and delete indicators on the chart with the script, as applying the template deletes all the lines drawn.


I get reply

2019.01.24 19:14:53.633 add_ind (EURJPY,H1) cannot load indicator 'Moving Average' [4302]

2019.01.24 19:14:53.633 add_ind (EURJPY,H1) -1


Although code compiles without errors.


ERR_MARKET_NOT_SELECTED

4302

Symbol not selected in MarketWatch


Why do you put 0 instead of the symbol name? If you want the current one, you have to write NULL, or its name, for example "EURUSD".

iMA

Returns moving average indicator handle. Only one buffer.

intiMA(
string symbol, // symbol name
ENUM_TIMEFRAMESperiod, // period
int ma_period, // averaging period
int ma_shift, // indicator horizontal shift
ENUM_MA_METHODma_method, // type of smoothing
ENUM_APPLIED_PRICE applied_price // price type or handle
);

Parameters

symbol

[in] Symbol name of the instrument which data will be used to calculate the indicator. NULL means current symbol.

period

[in] Period value can be one of the values of ENUM_TIMEFRAMES enumeration, 0 means current timeframe.

ma_period

[in] Averaging period for moving average calculation.

ma_shift

[in] Shift of indicator relative to the price chart.

ma_method

[in] Averaging method. Can be any of values of ENUM_MA_METHOD.

applied_price

[in] Price used. Can be any of the price constants of ENUM_APPLIED_PRICE or a handle of another indicator.

Returned value

Returns handle of specified technical indicator, in case of failure returns INVALID_HANDLE. The IndicatorRelease() function is used to free the computer's memory from an indicator that is no longer in use.

 
hello, could you please tell me how to make an array of MA handles return normal prices, I mean the way they should, 5 decimal places, not 8
int OnInit()
  {
 ima1_handle        = iMA (Symbol(),0,14,0,MODE_EMA,PRICE_CLOSE);
 ima2_handle        =  iMA (Symbol(),0,64,0,MODE_EMA,PRICE_CLOSE);               //хендл
 Stoch_handle       = iStochastic (Symbol(),0,20,15,15,MODE_EMA,STO_CLOSECLOSE);//хендл
 ATR_handle         = iATR        (Symbol(),0,21);                              //хендл

   if(Digits==3 || Digits==5)
     {
      Slippage*=10;
      TrailingStop *= 10;
      TrailingStep *= 10;
     }
   return(0);
  }
void OnDeinit(const int reason)
  {

  }

void OnTick()
  { 
    double ima1_massiv [];                                          //динамический массив для быстрой машки
    ArraySetAsSeries(ima1_massiv, true);   
    int ima_count1 = CopyBuffer(ima1_handle,0,0,2,ima1_massiv);    //скопировал данные из 2х буферов быстрой машки
    //double ima1_normal = NormalizeDouble(ima1_massiv[0], Digits);
    string ima1_massiv_str0 = DoubleToString (ima1_massiv[0]);
    string ima1_massiv_str1 = DoubleToString (ima1_massiv[1]);
    printf ("сегодня = "+ ima1_massiv_str0 + " вчера = "+ ima1_massiv_str1);  
    
  }    
mt5 language
 
Sergey Lobzankin:
Hello, could you please tell me how to make an array of MA handles return normal prices, I mean the way they should, 5 digits after the decimal point and not 8
if(Digits==3 || Digits==5)
     {
      Slippage*=10;
      TrailingStop *= 10;
      TrailingStep *= 10;
     }
   return(0);

cool)

double normalMA=NormalizeDouble(MA,_Digits);    
 

Hello, could you please tell me how to make an array of MA handles return normal prices, I mean the way they should, 5 digits after the decimal point and not 8

mt5 language

DoubleToStr in mt5, there is noDoubleToString(); but it does not help
DoubleToStr - Преобразование данных - Справочник MQL4
DoubleToStr - Преобразование данных - Справочник MQL4
  • docs.mql4.com
DoubleToStr - Преобразование данных - Справочник MQL4
Reason: