multirsitrend_x10

Download script
Author: Copyright � 2015, Nikolay Kositsin

This script is a multi-layered technical analysis tool designed to provide a comprehensive view of market trends by analyzing the Relative Strength Index (RSI) across multiple timeframes simultaneously. Instead of looking at just one chart's momentum, it aggregates data from ten different intervals—ranging from shorter periods like 1-hour charts up to monthly data—into a single, unified visual display.

Core Logic and Functionality

Multi-Timeframe Analysis The primary logic of the script is its ability to "reach out" to other timeframes. While you are viewing your current chart, the tool automatically fetches RSI data from ten different periods (e.g., H1, H2, H3, H4, H6, H8, H12, Daily, Weekly, and Monthly). This allows a trader to see how the "big picture" trend aligns with the immediate price action without having to switch back and forth between different tabs or windows.

Visual Representation (Lines and Arrows) The script generates two distinct types of visual signals for each of the ten timeframes:

  • Signal Lines: These provide a continuous visual path, showing the trajectory of the RSI trend across the different periods.
  • Signal Arrows: These serve as specific markers to highlight where significant movement or status changes occur within those trends.

Dynamic Color Coding To make the data easy to read at a glance, the script uses a dynamic coloring system based on predefined "Overbought" and "Oversold" levels:

  • Standard State: When the RSI is in a neutral zone, the indicators maintain a neutral color (Gray).
  • Overbought Condition: If the RSI exceeds the high threshold (default set at 70), the lines and arrows change to Blue, signaling that the asset may be overextended to the upside.
  • Oversold Condition: If the RSI falls below the low threshold (default set at 30), the lines and arrows change to Red, indicating the asset may be overextended to the downside.

Data Synchronization The script includes internal logic to ensure that data from different timeframes is correctly synchronized with your current chart's timeline. It constantly monitors for new price information; whenever a new candle forms or updated price data arrives, the script recalculates the RSI values for all ten periods to ensure the visual information remains accurate and up-to-date in real-time.

Summary for the User

In essence, this tool acts as a "Trend Dashboard." It takes ten different snapshots of market momentum, identifies whether those markets are currently overbought or oversold using a red/blue color scheme, and plots them all into one window. This allows you to see if the short-term trend is in agreement with the long-term trend, helping to filter out "market noise" and identify stronger, more reliable movements.

Indicators Used
Relative strength index
21 Views
0 Downloads
0 Favorites
multirsitrend_x10
//+---------------------------------------------------------------------+
//|                                               MultiRSITrend_x10.mq5 | 
//|                                  Copyright © 2015, Nikolay Kositsin | 
//|                                 Khabarovsk,   farria@mail.redcom.ru | 
//+---------------------------------------------------------------------+
#property copyright "Copyright © 2015, Nikolay Kositsin"
#property link "farria@mail.redcom.ru"
#property description ""
//--- íîìåð âåðñèè èíäèêàòîðà
#property version   "1.60"
//--- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
#property indicator_separate_window
//--- ôèêñèðîâàííàÿ âûñîòà ïîäîêíà èíäèêàòîðà â ïèêñåëÿõ 
#property indicator_height 150
//--- íèæíåå è âåðõíåå îãðàíè÷åíèÿ øêàëû îòäåëüíîãî îêíà èíäèêàòîðà
#property indicator_maximum +10.9
#property indicator_minimum +0.3
//+----------------------------------------------+
//| Îáúÿâëåíèå êîíñòàíò                          |
//+----------------------------------------------+
#define RESET 0                           // êîíñòàíòà äëÿ âîçâðàòà òåðìèíàëó êîìàíäû íà ïåðåñ÷åò èíäèêàòîðà
#define INDTOTAL 10                       // êîíñòàíòà äëÿ êîëè÷åñòâà îòîáðàæàåìûõ èíäèêàòîðîâ
#define INDICATOR_NAME "RSITrend_x10"     // êîíñòàíòà äëÿ èìåíè èíäèêàòîðà
//+----------------------------------------------+
//--- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ
#property indicator_buffers 40 // INDTOTAL*4
//--- èñïîëüçîâàíî âñåãî ãðàôè÷åñêèõ ïîñòðîåíèé
#property indicator_plots   20 // INDTOTAL*2
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 1             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 1 â âèäå ëèíèè
#property indicator_type1   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color1 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style1  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width1  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label1  "Signal line 1"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 1             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 1 â âèäå çíà÷êà
#property indicator_type2   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color2 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width2  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label2  "Signal Arrow 1"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 2             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 3 â âèäå ëèíèè
#property indicator_type3   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color3 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style3  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width3  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label3  "Signal line 2"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 2             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 2 â âèäå çíà÷êà
#property indicator_type4   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color4 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width4  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label4  "Signal Arrow 2"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 3             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 3 â âèäå ëèíèè
#property indicator_type5   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color5 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style5  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width5  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label5  "Signal line 3"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 3             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 3 â âèäå çíà÷êà
#property indicator_type6   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color6 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width6  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label6  "Signal Arrow 3"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 4             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 4 â âèäå ëèíèè
#property indicator_type7   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color7 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style7  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width7  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label7  "Signal line 4"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 4             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 4 â âèäå çíà÷êà
#property indicator_type8   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color8 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width8  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label8  "Signal Arrow 4"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 5             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 5 â âèäå ëèíèè
#property indicator_type9   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color9 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style9  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width9  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label9  "Signal line 5"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 5             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 5 â âèäå çíà÷êà
#property indicator_type10   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color10 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width10  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label10  "Signal Arrow 5"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 6             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 6 â âèäå ëèíèè
#property indicator_type11   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color11 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style11  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width11  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label11  "Signal line 6"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 6             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 6 â âèäå çíà÷êà
#property indicator_type12   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color12 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width12  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label12  "Signal Arrow 6"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 7             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 7 â âèäå ëèíèè
#property indicator_type13   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color13 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style13  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width13  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label13  "Signal line 7"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 7             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 7 â âèäå çíà÷êà
#property indicator_type14   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color14 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width14  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label14  "Signal Arrow 7"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 8             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 8 â âèäå ëèíèè
#property indicator_type15   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color15 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style15  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width15  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label15  "Signal line 8"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 8             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 8 â âèäå çíà÷êà
#property indicator_type16   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color16 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width16  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label16  "Signal Arrow 8"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 9             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 9 â âèäå ëèíèè
#property indicator_type17   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color17 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style17  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width17  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label17  "Signal line 9"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 9             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 9 â âèäå çíà÷êà
#property indicator_type18   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color18 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width18  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label18  "Signal Arrow 9"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 10            |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 10 â âèäå ëèíèè
#property indicator_type19   DRAW_COLOR_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color19 clrRed,clrGray,clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - øòðèõ
#property indicator_style19  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width19  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label19  "Signal line 10"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 10            |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà 10 â âèäå çíà÷êà
#property indicator_type20   DRAW_COLOR_ARROW
//--- â êà÷åñòâå öâåòà çíà÷êà èñïîëüçîâàí
#property indicator_color20 clrRed,clrGray,clrDodgerBlue
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width20  5
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label20  "Signal Arrow 10"
//+----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà                 |
//+----------------------------------------------+
input ENUM_TIMEFRAMES TimeFrame0=PERIOD_H1;           // Ïåðèîä ãðàôèêà 1
input ENUM_TIMEFRAMES TimeFrame1=PERIOD_H2;           // Ïåðèîä ãðàôèêà 2
input ENUM_TIMEFRAMES TimeFrame2=PERIOD_H3;           // Ïåðèîä ãðàôèêà 3
input ENUM_TIMEFRAMES TimeFrame3=PERIOD_H4;           // Ïåðèîä ãðàôèêà 4
input ENUM_TIMEFRAMES TimeFrame4=PERIOD_H6;           // Ïåðèîä ãðàôèêà 5
input ENUM_TIMEFRAMES TimeFrame5=PERIOD_H8;           // Ïåðèîä ãðàôèêà 6
input ENUM_TIMEFRAMES TimeFrame6=PERIOD_H12;          // Ïåðèîä ãðàôèêà 7
input ENUM_TIMEFRAMES TimeFrame7=PERIOD_D1;           // Ïåðèîä ãðàôèêà 8
input ENUM_TIMEFRAMES TimeFrame8=PERIOD_W1;           // Ïåðèîä ãðàôèêà 9
input ENUM_TIMEFRAMES TimeFrame9=PERIOD_MN1;          // Ïåðèîä ãðàôèêà 10
//---- ïàðàìåòðû RSI
input int   RSIPeriod=14;
input ENUM_APPLIED_PRICE   RSIPrice=PRICE_CLOSE;
input uint UpLevel=70;                                // Óðîâåíü ïåðåêóïëåííîñòè
input uint DnLevel=30;                                // Óðîâåíü ïåðåïðîäàííîñòè
//+----------------------------------------------+
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
int min_rates_total;
//+------------------------------------------------------------------+
//| Ïîëó÷åíèå òàéìôðåéìà â âèäå ñòðîêè                               |
//+------------------------------------------------------------------+
string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
  {return(StringSubstr(EnumToString(timeframe),7,-1));}
//+------------------------------------------------------------------+
//| Êëàññ èíäèêàòîðíûõ áóôåðîâ                                       |
//+------------------------------------------------------------------+  
class CIndBuffers
  {
public:
   double            m_ArrBuffer[];
   double            m_ColorArrBuffer[];
   double            m_LineBuffer[];
   double            m_ColorLineBuffer[];
   int               m_Handle;
   ENUM_TIMEFRAMES   m_TimeFrame;
  };
//--- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå â äàëüíåéøåì
//--- áóäóò èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
CIndBuffers Ind[INDTOTAL];
//+------------------------------------------------------------------+   
//| RSITrend_x10 indicator initialization function                   | 
//+------------------------------------------------------------------+ 
bool IndInit(uint Number)
  {
//--- ïðîâåðêà ïåðèîäîâ ãðàôèêîâ íà êîððåêòíîñòü
   if(Ind[Number].m_TimeFrame<Period() && Ind[Number].m_TimeFrame!=PERIOD_CURRENT)
     {
      Print("IndInit(",Number,"): Ïåðèîä ãðàôèêà äëÿ èíäèêàòîðà RSITrend_x10 íå ìîæåò áûòü ìåíüøå ïåðèîäà òåêóùåãî ãðàôèêà");
      return(false);
     }
//---- ïîëó÷åíèå õåíäëîâ èíäèêàòîðîâ  
   Ind[Number].m_Handle=iRSI(NULL,Ind[Number].m_TimeFrame,RSIPeriod,RSIPrice);
//---
   if(Ind[Number].m_Handle==INVALID_HANDLE)
     {
      Print("IndInit(",Number,"): Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà RSI");
      return(false);
     }
   uint BIndex=Number*4+0;
   uint PIndex=Number*2+0;
   InitTsIndBuffer(BIndex,PIndex,Ind[Number].m_LineBuffer,EMPTY_VALUE,min_rates_total);
   InitTsIndColorBuffer(BIndex+1,Ind[Number].m_ColorLineBuffer,min_rates_total);
   InitTsIndArrBuffer(BIndex+2,PIndex+1,Ind[Number].m_ArrBuffer,EMPTY_VALUE,min_rates_total);
   InitTsIndColorBuffer(BIndex+3,Ind[Number].m_ColorArrBuffer,min_rates_total);
//----   
   string tmf=GetStringTimeframe(Ind[Number].m_TimeFrame);
   PlotIndexSetString(PIndex+0,PLOT_LABEL,INDICATOR_NAME+"("+tmf+")");
   PlotIndexSetString(PIndex+1,PLOT_LABEL,INDICATOR_NAME+"Arr("+tmf+")");
//--- çàâåðøåíèå èíèöèàëèçàöèè
   return(true);
  }
//+------------------------------------------------------------------+
//| Èíèöèàëèçàöèÿ èíäèêàòîðíîãî áóôåðà òàéìñåðèè                     |
//+------------------------------------------------------------------+  
void InitTsIndBuffer(uint Number,uint Plot,double &IndBuffer[],double Empty_Value,uint Draw_Begin)
  {
//--- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(Number,IndBuffer,INDICATOR_DATA);
//--- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(Plot,PLOT_DRAW_BEGIN,Draw_Begin);
//--- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   PlotIndexSetDouble(Plot,PLOT_EMPTY_VALUE,Empty_Value);
//--- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
   ArraySetAsSeries(IndBuffer,true);
  }
//+------------------------------------------------------------------+
//| Èíèöèàëèçàöèÿ èíäèêàòîðíîãî áóôåðà òàéìñåðèè                     |
//+------------------------------------------------------------------+  
void InitTsIndArrBuffer(uint Number,uint Plot,double &IndBuffer[],double Empty_Value,uint Draw_Begin)
  {
//--- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(Number,IndBuffer,INDICATOR_DATA);
//--- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(Plot,PLOT_DRAW_BEGIN,Draw_Begin);
//--- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   PlotIndexSetDouble(Plot,PLOT_EMPTY_VALUE,Empty_Value);
//--- âûáîð ñèìâîëà äëÿ îòðèñîâêè
   PlotIndexSetInteger(Plot,PLOT_ARROW,159);
//--- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
   ArraySetAsSeries(IndBuffer,true);
  }
//+------------------------------------------------------------------+
//| Èíèöèàëèçàöèÿ èíäèêàòîðíîãî áóôåðà öâåòà òàéìñåðèè               |
//+------------------------------------------------------------------+  
void InitTsIndColorBuffer(uint Number,double &IndColorBuffer[],uint Draw_Begin)
  {
//--- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â öâåòîâîé èíäåêñíûé áóôåð   
   SetIndexBuffer(Number,IndColorBuffer,INDICATOR_COLOR_INDEX);
//--- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
   ArraySetAsSeries(IndColorBuffer,true);
  }
//+------------------------------------------------------------------+ 
//| IndOnCalculate                                                   | 
//+------------------------------------------------------------------+ 
bool IndOnCalculate(int Number,int Limit,const datetime &Time[],uint Rates_Total,uint Prev_Calculated)
  {
//--- îáúÿâëåíèå öåëî÷èñëåíííûõ ïåðåìåííûõ
   int limit_;
//--- îáúÿâëåíèå ïåðåìåííûõ ñ ïëàâàþùåé òî÷êîé  
   double Main[1];
   datetime Time_[1],Time0;
   static int LastCountBar[INDTOTAL];
//--- ðàñ÷åòû íåîáõîäèìîãî êîëè÷åñòâà êîïèðóåìûõ äàííûõ
//--- è ñòàðòîâîãî íîìåðà limit äëÿ öèêëà ïåðåñ÷åòà áàðîâ
   if(Prev_Calculated>Rates_Total || Prev_Calculated<=0)// ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷åòà èíäèêàòîðà
     {
      limit_=Limit;
      LastCountBar[Number]=limit_;
     }
   else limit_=int(MathMin(LastCountBar[Number]+Limit,Rates_Total-2)); // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà íîâûõ áàðîâ
//--- îñíîâíîé öèêë ðàñ÷åòà èíäèêàòîðà
   for(int bar=int(limit_); bar>=0 && !IsStopped(); bar--)
     {
      //--- îáíóëèì ñîäåðæèìîå èíäèêàòîðíûõ áóôåðîâ äî ðàñ÷åòà
      Ind[Number].m_ArrBuffer[bar]=EMPTY_VALUE;
      Ind[Number].m_LineBuffer[bar]=Number+1.0;
      Ind[Number].m_ColorArrBuffer[bar]=1;
      Ind[Number].m_ColorLineBuffer[bar]=1;
      Time0=Time[bar];
      //--- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâ
      if(CopyTime(Symbol(),Ind[Number].m_TimeFrame,Time0,1,Time_)<=0) return(RESET);
      //---
      if(Time0>=Time_[0] && Time[bar+1]<Time_[0])
        {
         LastCountBar[Number]=bar;
         //--- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâû
         //---- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâû
         if(CopyBuffer(Ind[Number].m_Handle,MAIN_LINE,Time0,1,Main)<=0) return(RESET);

         if(Main[0]>UpLevel)
           {
            Ind[Number].m_ColorLineBuffer[bar]=2;
            Ind[Number].m_ColorArrBuffer[bar]=2;
           }
         //---
         if(Main[0]<DnLevel)
           {
            Ind[Number].m_ColorLineBuffer[bar]=0;
            Ind[Number].m_ColorArrBuffer[bar]=0;
           }
         //---
         Ind[Number].m_ArrBuffer[bar]=Number+1.0;
        }
      else Ind[Number].m_ColorLineBuffer[bar]=Ind[Number].m_ColorLineBuffer[bar+1];
     }
//--- çàâåðøåíèå ðàñ÷åòà îäíîãî èíäèêàòîðà    
   return(true);
  }
//+------------------------------------------------------------------+   
//| RSITrend_x10 indicator initialization function                   | 
//+------------------------------------------------------------------+ 
int OnInit()
  {
//--- èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
   min_rates_total=int(RSIPeriod)+1;
//--- èíèöèàëèçàöèÿ ïåðåìåííûõ 
   Ind[0].m_TimeFrame=TimeFrame0;
   Ind[1].m_TimeFrame=TimeFrame1;
   Ind[2].m_TimeFrame=TimeFrame2;
   Ind[3].m_TimeFrame=TimeFrame3;
   Ind[4].m_TimeFrame=TimeFrame4;
   Ind[5].m_TimeFrame=TimeFrame5;
   Ind[6].m_TimeFrame=TimeFrame6;
   Ind[7].m_TimeFrame=TimeFrame7;
   Ind[8].m_TimeFrame=TimeFrame8;
   Ind[9].m_TimeFrame=TimeFrame9;
//--- èíèöèàëèçàöèÿ áóôåðîâ èíäèêàòîðîâ
   for(int count=0; count<INDTOTAL; count++) if(!IndInit(count)) return(INIT_FAILED);
//--- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
   IndicatorSetString(INDICATOR_SHORTNAME,"MultiRSITrend_x10");
//--- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- çàâåðøåíèå èíèöèàëèçàöèè
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+ 
//| RSITrend_x10 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[])
  {
//--- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷åòà
   if(rates_total<min_rates_total) return(RESET);
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ
   int limit;
//--- ðàñ÷åò ñòàðòîâîãî íîìåðà limit äëÿ öèêëà ïåðåñ÷åòà áàðîâ
   if(prev_calculated>rates_total || prev_calculated<=0)// ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷åòà èíäèêàòîðà
      limit=rates_total-min_rates_total-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà âñåõ áàðîâ
   else limit=rates_total-prev_calculated; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà íîâûõ áàðîâ 
//--- èíäåêñàöèÿ ýëåìåíòîâ â ìàññèâàõ êàê â òàéìñåðèÿõ  
   ArraySetAsSeries(time,true);
   for(int count=0; count<INDTOTAL; count++) if(!IndOnCalculate(count,limit,time,rates_total,prev_calculated)) return(RESET);
//---   
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments