Questions from Beginners MQL5 MT5 MetaTrader 5 - page 605

 
Alexander Antoshkin:

Hello Vladimir.

I must have phrased my question incorrectly.

I don't need a subwindow, the indicator should be placed on the price chart as a standard chart

I regard it as an example, and try to understand .

I want the indicator mounted on the chart to have its number, so that the necessary number of copies can be created on the chart using the "Add" button ..... I want to delete one selected by the "cross" button ........ (I don't want to describe them yet))

When an indicator should be added to the main chart window

sub_window

[in] Chart subwindow number.0 means main chart window. To add an indicator to a new window, the parameter must be one more than the index of the last existing window, i.e. equal toCHART_WINDOWS_TOTAL. If the parameter value exceedsCHART_WINDOWS_TOTAL, a new window will not be created, the indicator will not be added.

You cannot add the indicator to OnInit() - since the expert has not yet been formed at this stage. But the function - OnTick() is a sign of complete working of the Expert Advisor.

//+------------------------------------------------------------------+
//|                                                         0000.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

input int MA_Period=21;
input int MA_Shift=0;
input ENUM_MA_METHOD MA_Method=MODE_SMA;
//--- variables
int MA_handle=INVALID_HANDLE;
bool first_start=false;
//+------------------------------------------------------------------+ 
//| Expert initialization function                                   | 
//+------------------------------------------------------------------+ 
int OnInit()
  {
   Print(__FUNCTION__,", first_start = ",first_start);
   MA_handle=iCustom(NULL,0,"Examples\\Custom Moving Average",MA_Period,MA_Shift,MA_Method,PRICE_CLOSE);
   if(MA_handle==INVALID_HANDLE)
      return(INIT_FAILED);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(!first_start)
     {
      if(AddIndicator()) //попробуем добавить индикатор на график 
         first_start=true;
     }
  }
//+------------------------------------------------------------------+ 
//| Функция проверки и добавления индикатора на график               | 
//+------------------------------------------------------------------+ 
bool AddIndicator()
  {
//--- сбросим код ошибки 
   ResetLastError();
//--- накладываем индикатор на график   
   int subwindow=0;
   PrintFormat("Добавляем индикатор на окно %d графика",subwindow);
   if(!ChartIndicatorAdd(0,subwindow,MA_handle))
     {
      PrintFormat("Не удалось добавить индикатор  на окно %d графика. Код ошибки  %d",
                  subwindow,GetLastError());
     }
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
And rewrite the AddIndicator() function so that it returns false at unsuccessful attempt to add an indicator.
 
Alexander Antoshkin:

Hello Vladimir.

I must have phrased my question incorrectly.

I don't need a subwindow, the indicator should be placed on the price chart as a standard chart

I regard it as an example, and try to understand .

I want the indicator mounted on the chart to have its own number, so that the necessary number of copies can be created on the chart using the "Add" button ..... I want to delete one selected with the "cross" button ........ (there are a lot of fantasies and I don't want to describe them yet))

The indicator can have a name, if you like numbers, let it be a number. However, the number will not be a number but a text. Do you want a custom control panel that allows you to add any indicator number from one or more?
 
Can you tell me how to filter by day number and separately by week number in a month? Inside the day I have done this:


bool TimeStart=false;

int hour=12;


//--Фильтр по ремени открытия бара внутри дня

if (TimeStart==true)

{      

      datetime  Open_timePos=iTime(_Symbol,0,0);

      MqlDateTime str1; 

      TimeToStruct(Open_timePos,str1);

      str1.hour=hour;

      str1.min=0;

      str1.sec=0;


      datetime start_time=StructToTime(str1);

      if (start_time>iTime(_Symbol,0,0))

      {

            BuyPrIMA=false;

            SellPrIMA=false;      

      

      } 

 

 

 
-Aleks-:
Can you tell me how to filter by day number and separately by week number in a month? Inside the day I have done this:

int НомерДНЯвМесяце=TimeDay(iTime(_Symbol,0,0));

int НомерДняНедели=TimeDayOfWeek(iTime(_Symbol,0,0)); int НомерНеделиВмесяце=NormalizeDouble(НомерДНЯвМесяце/7,0);

 
new-rena:
He asks about the week of the month
 
pako:
He's asking about the week of the month

I've made all three options there. Which one does he want to use as a base, please?

This one?

int НомерНеделиВмесяце=NormalizeDouble(НомерДНЯвМесяце/7,0);
 
new-rena:
I did all three options there. Please specify.

There are five to six weeks in the month, today is the fourth week of the month

str.day day of the month

str.day_of_week day

 
new-rena:
Thank you.
 
pako:
There are four five weeks in a month, today is the fourth week of the month
I see. So he wants to account for weeks of this nature on the 29th of the previous month (Monday, for example) and up to the 31st of the current month (Monday too, for example). It is more than a month. It is not logical to count such weeks. If it isn't, then the week won't be a whole week. Nope, no point....
 
new-rena:

I've made all three options there. Which one does he want to use as a base, please?

This one?

That won't do.
Reason: