Как сместить МА по вертикали или как в МА "впихнуть" сумму нескольких ценовых значений - страница 2

 
AnalCum:

Здравствуйте!

Подскажите пожалуйста, как сместить индикатор - линию по оси "y" вверх или вниз на несколько пунктов в MQL5?

Скрин линии ниже, если не затруднит, то скрин линии со смещением.

или такую:


Пожалуйста, вставьте код правильно: Правильно вставляем код на форуме - мне просто не хочется перенабирать Ваш код себе заново вручную. Идеальный вариант - вставьте код правильно и одновременно в сообщение прикрепите индикатор.

 

Добавлено: смените свой ник. Это просто некрасиво. 

 
Vladimir Karputov:
Пожалуйста, вставьте код правильно: Правильно вставляем код на форуме - мне просто не хочется перенабирать Ваш код себе заново вручную. Идеальный вариант - вставьте код правильно и одновременно в сообщение прикрепите индикатор.
//+------------------------------------------------------------------+
//|                                                         Line.mq5 |
//|                                            Copyright 2016, Вован |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Вован"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Line
#property indicator_label1  "Line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- индикаторный буфер
double         LineBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=0;i<rates_total;i++)
     {
      LineBuffer[i]=open[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

Добавлено: смените свой ник. Это просто некрасиво. 
 
Vladimir Karputov:
Добавлено: смените свой ник. Это просто некрасиво. 
Прошу прощения!
 

Вот и все изменения:

//+------------------------------------------------------------------+
//|                                                         Line.mq5 |
//|                                            Copyright 2016, Вован |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Вован"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Line
#property indicator_label1  "Line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- индикаторный буфер
double         LineBuffer[];
//--- input parameter
input ushort InpVerticalOffset=10;
double       ExtVerticalOffset=0.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
//---
   ExtVerticalOffset=InpVerticalOffset*Point(); // tuning
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=0;i<rates_total;i++)
     {
      LineBuffer[i]=open[i]+ExtVerticalOffset;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 Добавлено: смените свой ник и логин. Это просто некрасиво. 

Файлы:
Line.mq5  5 kb
 
Vladimir Karputov:

Вот и все изменения:

//+------------------------------------------------------------------+
//|                                                         Line.mq5 |
//|                                            Copyright 2016, Вован |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Вован"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Line
#property indicator_label1  "Line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- индикаторный буфер
double         LineBuffer[];
//--- input parameter
input ushort InpVerticalOffset=10;
double       ExtVerticalOffset=0.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
//---
   ExtVerticalOffset=InpVerticalOffset*Point(); // tuning
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=0;i<rates_total;i++)
     {
      LineBuffer[i]=open[i]+ExtVerticalOffset;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 Добавлено: смените свой ник и логин. Это просто некрасиво. 

Спасибо огромное!) Ура)
 
Vladimir Karputov:

Вот и все изменения:

//+------------------------------------------------------------------+
//|                                                         Line.mq5 |
//|                                            Copyright 2016, Вован |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Вован"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Line
#property indicator_label1  "Line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- индикаторный буфер
double         LineBuffer[];
//--- input parameter
input ushort InpVerticalOffset=10;
double       ExtVerticalOffset=0.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
//---
   ExtVerticalOffset=InpVerticalOffset*Point(); // tuning
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=0;i<rates_total;i++)
     {
      LineBuffer[i]=open[i]+ExtVerticalOffset;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 Добавлено: смените свой ник и логин. Это просто некрасиво. 

А подскажите пожалуйста, как тут можно менять интервал вместо 10 пунктов 30 или 50?
 
USER:
А подскажите пожалуйста, как тут можно менять интервал вместо 10 пунктов 30 или 50?
//+------------------------------------------------------------------+
//|                                                         Line.mq5 |
//|                                            Copyright 2016, Вован |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Вован"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Line
#property indicator_label1  "Line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- индикаторный буфер
double         LineBuffer[];
//--- input parameter
input ushort InpVerticalOffset=10;  //   <----- здесь
double       ExtVerticalOffset=0.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
//---
   ExtVerticalOffset=InpVerticalOffset*Point(); // tuning
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=0;i<rates_total;i++)
     {
      LineBuffer[i]=open[i]+ExtVerticalOffset;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Alekseu Fedotov:
//+------------------------------------------------------------------+
//|                                                         Line.mq5 |
//|                                            Copyright 2016, Вован |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Вован"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Line
#property indicator_label1  "Line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- индикаторный буфер
double         LineBuffer[];
//--- input parameter
input ushort InpVerticalOffset=10;  //   <----- здесь
double       ExtVerticalOffset=0.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
//---
   ExtVerticalOffset=InpVerticalOffset*Point(); // tuning
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=0;i<rates_total;i++)
     {
      LineBuffer[i]=open[i]+ExtVerticalOffset;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Так пробовал, но почему-то через код не меняется, только через настройки на самом графике.

Все, получилось, надо его удалять с графика, потом заново устанавливать, тогда значения будут те, которые в коде. Спасибо!

 

Доброй ночи!

Не сочтите за назойливость и наглость. Понимаю, что не по теме, но я не программер и очень сложно с "0" разобраться со всем. А здесь, я вижу, очень толковые люди собрались. Не подскажите, как прицепить стрелки к индикатору ниже (2 линии), чтобы стрелки появлялись при касании или пробитии линий используемого индикатора, до закрытия текущей свечи (то есть, касание или пробитие текущей ценой (после open до close) линии индикатора, - стрелка) в MQL5:

//+------------------------------------------------------------------+
//|                                                       2Линии.mq5 |
//|                                            Copyright 2016, Вован |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Вован"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Line1
#property indicator_label1  "Line1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- plot Line2
#property indicator_label2  "Line2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2
//--- input parameters
input ushort   Y=30;
double         ExtY=0.0;
//--- indicator buffers
double         Line1Buffer[];
double         Line2Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Line1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,Line2Buffer,INDICATOR_DATA);
//---
   ExtY=Y*Point(); // tuning
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
      for(int i=0;i<rates_total;i++)
     {
      Line1Buffer[i]=open[i]+ExtY;
      Line2Buffer[i]=open[i]-ExtY;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Причина обращения: