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

 
Zhunko:
It makes sense to declare statics inside functions. The scope is only a function block.


It works the same way:

int a = 10;
int start(){
   Alert(StringConcatenate("st: a = ", a));//st: a = 10
   f1(); Alert(StringConcatenate("f1: a = ", a));//f1: a = 10
   f2(); Alert(StringConcatenate("f2: a = ", a));//f2: a = 10
}
void f1(){
   int a = 11;
   return;
}
void f2(){
   static int a = 12;
   return;
}

In which case will the difference be felt? ALXIMIKS, thanks for the reply too.

 

Hello!

Can you tell me how to install an additional indicator/robot on an mt4 installed on an iphone/ipad? Is it, in principle, possible? With Windows it's elementary simple, but with Apple mobile products it's not so obvious.

Logic says that it is possible. After all, a number of indicators are already preinstalled. But what and where to copy is not clear, the file structure is different. Has anyone has not encountered such a problem?

Thanks in advance.

 

I am making an indicator based on moving averages . The idea is to cut off insignificant movements within specified points. Let's say we set a filter of 50 pips. The indicator is decreasing but the decrease is less than 50 pips, therefore we take yesterday's value of the average and write it down and set its level for the current date. On the next bar we check the difference, the current value minus the value we have recorded, if the total does not exceed 50 pips, we set the level that is stored in the static variable to the current value. If the value exceeds it, the value becomes the current value, i.e. similar to a moving average with a shift of zero.I have tried different variations, but so far I have not found the right solution.

For the sake of simplicity I am attaching the code for drawing only the declines. The problem is that the indicator draws on the rise. And the main one is that when I run it in the tester I can visually see the indicator changing, while there is no exit outside the filter. I assume that somewhere the value of the recorded "MA_otshet" value is lost.

#property indicator_chart_window
#property indicator_buffers 1
#property  indicator_color1 Red 
//--- input parameters
//--- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexBuffer(0,ExtMapBuffer1);
   IndicatorDigits(Digits+1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int counted_bars=IndicatorCounted(),                      
    limit;
    double
    raznica,raznica_static,MA_0_t,MA_1_t;
   static double MA_otshet;  //здесь хранится запись значения MA_otshet
   
   for(int i=0;i<Bars;i++)
   {  
      MA_0_t=iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE,i+0);  
      MA_1_t=iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE,i+1); 
      raznica=MA_0_t-MA_1_t; //разница между сегодня и вчера по скользящей средней
      raznica_static=MA_0_t-MA_otshet; //разница между сегодня и MA_otshet

      if(raznica > -0.005 && raznica <= 0) // если raznica не превышает заданное число 
          {
          MA_otshet=MA_1_t; // записываем значение MA_otshet
          }
      if(raznica_static > - 0.005 && raznica_static <= 0) //если raznica_static не превышает заданное число
          {
          ExtMapBuffer1[i]=MA_otshet;  // то рисуем значение индикатора, как записанный MA_otshet
          }
      if(raznica_static < - 0.005) // если raznica превышает заданное число
          {
          ExtMapBuffer1[i]=MA_0_t; // то рисуем значение по текущей цене
          }
   } 
   return(0);
  }
//+------------------------------------------------------------------+
 

Good afternoon. Please help.

I need all orders to be closed at 23 55 and on Friday trading ends at 22 00, so there is a problem with the trade

i found in the tutorial script in the time section help please add the parameter number of the day, ie Friday orders were closed at 21 55 and on normal days at 23 55 or can share the link if there are ready-made solutions

//--------------------------------------------------------------------
// timeevents.mq4
// Предназначен для использования в качестве примера в учебнике MQL4.
//--------------------------------------------------------------- 1 --
extern double Time_Cls=16.10;          // Время закрытия ордеров
bool Flag_Time=false;                  // Флаг, сообщения ещё не было 
//--------------------------------------------------------------- 2 --
int start()                            // Спец. функция start
  {
   int    Cur_Hour=Hour();             // Серверное время в часах
   double Cur_Min =Minute();           // Серверное время в минутах
   double Cur_time=Cur_Hour + Cur_Min100; // Текущее время
   Alert(Cur_time);
   if (Cur_time>=Time_Cls)             // Если наступило время события
      Executor();                      //.. то выполняем задуманное
   return;                             // Выход из start()
  }
//--------------------------------------------------------------- 3 --
int Executor()                         // Пользовательская функция
  {
   if (Flag_Time==false)               // Если ещё не было сообщения..
     {                                 // .. то сообщаем (1 раз)
      Alert("Время важных новостей. Закройте ордера.");
      Flag_Time=true;                  // Теперь сообщение уже было
     }
   return;                             // Выход из польз. функции
  }

//--------------------------------------------------------------- 4 --

 
r772ra:
Easy!!!


Thanks. But do you have a clue. I only need 1 day's worth of information. That is to display the profit information for the last working day

Variables are declared. It doesn't work. It's all zeros.

for (p=0; p<OrdersHistoryTotal(); p++) {

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {

if (StrToTime(TimeToStr(TimeCurrent(), TIME_DATE))<OrderCloseTime() && (OrderType()==OP_BUY || OrderType()==OP_SELL) )

p0+=OrderProfit()+OrderCommission()+OrderSwap();

}

}

double r0=p0*100/AccountBalance();

 
Zolotai:


Thanks. But, uh, can you give me a hint? I only need 1 day. That is, to display the profit information for the last working day

Variables are declared. It doesn't work. It's all null.

for (p=0; p<OrdersHistoryTotal(); p++) {

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {

if (StrToTime(TimeToStr(TimeCurrent(), TIME_DATE))<OrderCloseTime() && (OrderType()==OP_BUY || OrderType()==OP_SELL) )

p0+=OrderProfit()+OrderCommission()+OrderSwap();

}

}

double r0=p0*100/AccountBalance();


This Expert Advisor has the MM_Light library and the function in it:

//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
//|  Автор : TarasBY, taras_bulba@tut.by                                              |
//+-----------------------------------------------------------------------------------+
//|        Считаем итоги работы по своим ордерам                                      |
//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
double fCalculate_Pribul (int fi_OP = -2,              // тип (BUY\SELL) учитываемых ордеров
                          datetime fdt_TimeBegin = 0,  // момент времени, с которого производим расчёт
                          string fs_Comment = "")      // комментарий ордеров
{
    double   ld_Pribul = 0.0;
    int      history_total = OrdersHistoryTotal();
//----
    for (int li_ORD = 0; li_ORD < history_total; li_ORD++)
    {
        if (!fCheck_MyOrders (li_ORD, fi_OP, MODE_HISTORY)) continue;
        if (fdt_TimeBegin > OrderCloseTime()) continue;
        if (fs_Comment != "") {if (StringFind (OrderComment(), fs_Comment) < 0) continue;}
        ld_Pribul += (OrderProfit() + OrderSwap() + OrderCommission());
    }
//----
    return (ld_Pribul);
}
The principle is easy to understand. In order to calculate the profit/loss for the current day, you need to pass it the value: fCalculate_Pribul (-2, iTime (Symbol(), PERIOD_D1, 0), "").
 
sannin:

Good afternoon. Please help.

I need all orders to be closed at 23 55 and on Friday trading ends at 22 00, so there is a problem with the trade

i found in the tutorial script in the time section help please add the parameter number of the day, ie Friday orders were closed at 21 55 and on normal days at 23 55 or can share the link if there are ready-made solutions

//--------------------------------------------------------------- 4 --

Of course, the code was written on the scratch, but it should work, at least you should understand it

int start() {
switch(DayOfWeek()){// если пятница,суббота, и т.д.
 case 4://пятница
 case 5://суббота на всякий случай
 case 6://воскресенье на всякий случай
             if((Hour()==22 && Minute()>=00) || Hour()>22){
                 //   Выполняем какое то действие  в пятницу после 22:00
             }
             break;
 case 0://понедельник
 case 1://вторник
 case 2://среда
 case 3://четверг
             if(Hour()>23 || (Hour()==23 && Minute()>55)){
                // все остальные действия в нормальные рабочии дни ПОСЛЕ 23:55
             }
              break;
  default:   {//все остальные действия в нормальные рабочии дни до 23:55
  
             }
 }                   
}
 
SetIndexStyle(1,DRAW_LINE,STYLE_DASH,0);
Where does this part specify the thickness of the line? I was even embarrassed. :(
 
Link_x:
Where does this part specify the thickness of the line? I was even embarrassed. :(
The last parameter.
 
Link_x:
Where does this part specify the thickness of the line? I was even embarrassed. :(

Nowhere, for STYLE_DASH there is no thickness greater than normal