adaptivecybercycle_cloud_htf

Download script
Author: Copyright � 2015, Nikolay Kositsin

This script functions as a high-level visual analysis tool designed to display multi-timeframe market data on your trading chart. Its primary purpose is to provide a "Higher Timeframe" (HTF) perspective, allowing you to see broader market trends without having to constantly switch between different timeframes.

Core Logic and Functionality

1. Multi-Timeframe Synchronization The core logic of this script relies on its ability to "reach out" and pull data from a different timeframe than the one you are currently viewing. For example, if you are looking at a 15-minute chart, the script can be configured to fetch data from a 4-hour chart. It ensures that the information remains synchronized with the current time on your screen.

2. The "Cloud" Visual Representation Instead of showing simple lines, the script renders data as a colored "cloud" (or ribbon). This is achieved by tracking two separate values simultaneously:

  • Upper Bound: Represents one side of the market cycle/trend.
  • Lower Bound: Represents the opposite side. The space between these two values is filled with color, making it easy to visualize the strength and direction of the trend at a glance.

3. Data Mapping & Alignment Because different timeframes have different numbers of candles (bars), the script performs a specialized calculation to ensure the data aligns correctly:

  • It checks the specific timestamps of your current chart against the timestamps of the higher timeframe.
  • When it identifies a match, it "plucks" the relevant values from the higher timeframe and places them onto your current chart.
  • If there is no new data available for a specific moment on your current chart (because the higher timeframe hasn't updated yet), the script intelligently carries over the last known values to ensure the cloud remains continuous and smooth.

4. Adaptive Filtering The script includes an "Alpha" coefficient, which allows it to smooth out market noise. This helps in identifying the underlying cycle of the market rather than reacting to every minor price fluctuation, providing a cleaner signal for the trader.

Key Features for the User

  • Visual Clarity: By using a filling cloud, it provides an immediate sense of market sentiment—the thickness and color of the cloud indicate the "space" and momentum of the current trend.
  • Automated Perspective: It eliminates the need to manually jump between windows to see the "big picture," keeping the higher timeframe context visible at all times.
  • Safety Checks: The script includes built-in logic to ensure it only runs on compatible timeframes, preventing errors that might occur if you try to pull data from a timeframe that is smaller than your current view.
Price Data Components
11 Views
0 Downloads
0 Favorites
adaptivecybercycle_cloud_htf
//+------------------------------------------------------------------+ 
//|                                 AdaptiveCyberCycle_Cloud_HTF.mq5 | 
//|                               Copyright © 2015, Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2015, Nikolay Kositsin"
#property link "farria@mail.redcom.ru"
//--- íîìåð âåðñèè èíäèêàòîðà
#property version   "1.60"
#property description "AdaptiveCyberCycle ñ âîçìîæíîñòüþ èçìåíåíèÿ òàéìôðåéìà âî âõîäíûõ ïàðàìåòðàõ"
//--- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
#property indicator_separate_window
//--- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ 2
#property indicator_buffers 2 
//--- èñïîëüçîâàíî îäíî ãðàôè÷åñêîå ïîñòðîåíèå
#property indicator_plots   1
//+----------------------------------------------+
//|  îáúÿâëåíèå êîíñòàíò                         |
//+----------------------------------------------+
#define RESET 0                              // Êîíñòàíòà äëÿ âîçâðàòà òåðìèíàëó êîìàíäû íà ïåðåñ÷åò èíäèêàòîðà
#define INDICATOR_NAME "AdaptiveCyberCycle"  // Êîíñòàíòà äëÿ èìåíè èíäèêàòîðà
#define SIZE 1                               // Êîíñòàíòà äëÿ êîëè÷åñòâà âûçîâîâ ôóíêöèè CountIndicator êîäå
//+----------------------------------------------+
//|  Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 1            |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà â âèäå öâåòíîãî îáëàêà
#property indicator_type1   DRAW_FILLING
//--- â êà÷åñòâå öâåòîâ èíäèêàòîðà èñïîëüçîâàíû
#property indicator_color1  clrChartreuse,clrDeepPink
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label1  "Signal HTF"
//+----------------------------------------------+
//| Ïàðàìåòðû îòîáðàæåíèÿ ãîðèçîíòàëüíûõ óðîâíåé |
//+----------------------------------------------+
#property indicator_level1 0.0
#property indicator_levelcolor clrGray
#property indicator_levelstyle STYLE_DASHDOTDOT
//+----------------------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà                 |
//+----------------------------------------------+ 
input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4;  // Ïåðèîä ãðàôèêà èíäèêàòîðà (òàéìôðåéì)
input double Alpha=0.07;                    // Êîýôôèöèåíò èíäèêàòîðà 
input int Shift=0;                          // Ñäâèã èíäèêàòîðà ïî ãîðèçîíòàëè â áàðàõ
//+----------------------------------------------+
//--- îáúÿâëåíèå äèíàìè÷åñêèõ ìàññèâîâ, êîòîðûå â äàëüíåéøåì
//--- áóäóò èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
double UpIndBuffer[];
double DnIndBuffer[];
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
int min_rates_total;
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ äëÿ õåíäëîâ èíäèêàòîðîâ
int Ind_Handle;
//+------------------------------------------------------------------+
//| Ïîëó÷åíèå òàéìôðåéìà â âèäå ñòðîêè                               |
//+------------------------------------------------------------------+
string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
  {return(StringSubstr(EnumToString(timeframe),7,-1));}
//+------------------------------------------------------------------+    
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+  
int OnInit()
  {
//--- ïðîâåðêà ïåðèîäîâ ãðàôèêîâ íà êîððåêòíîñòü
   if(!TimeFramesCheck(INDICATOR_NAME,TimeFrame)) return(INIT_FAILED);
//--- èíèöèàëèçàöèÿ ïåðåìåííûõ 
   min_rates_total=2;
//--- ïîëó÷åíèå õåíäëà èíäèêàòîðà AdaptiveCyberCycle
   Ind_Handle=iCustom(Symbol(),TimeFrame,"AdaptiveCyberCycle",Alpha,0);
   if(Ind_Handle==INVALID_HANDLE)
     {
      Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà AdaptiveCyberCycle");
      return(INIT_FAILED);
     }
//--- èíèöèàëèçàöèÿ èíäèêàòîðíûõ áóôåðîâ
   IndInit(0,UpIndBuffer,INDICATOR_DATA);
   IndInit(1,DnIndBuffer,INDICATOR_DATA);
//--- èíèöèàëèçàöèÿ èíäèêàòîðîâ
   PlotInit(0,0.0,0,Shift);
//--- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
   string shortname;
   StringConcatenate(shortname,INDICATOR_NAME,"(",GetStringTimeframe(TimeFrame),")");
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- çàâåðøåíèå èíèöèàëèçàöèè
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+  
//| Custom 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);
   if(BarsCalculated(Ind_Handle)<Bars(Symbol(),TimeFrame)) return(prev_calculated);
//--- èíäåêñàöèÿ ýëåìåíòîâ â ìàññèâàõ êàê â òàéìñåðèÿõ  
   ArraySetAsSeries(time,true);
//---
   if(!CountIndicator(0,NULL,TimeFrame,Ind_Handle,0,UpIndBuffer,1,DnIndBuffer,time,rates_total,prev_calculated,min_rates_total))
      return(RESET);
//---     
   return(rates_total);
  }
//---
//+------------------------------------------------------------------+
//| Èíèöèàëèçàöèÿ èíäèêàòîðíîãî áóôåðà                               |
//+------------------------------------------------------------------+    
void IndInit(int Number,double &Buffer[],ENUM_INDEXBUFFER_TYPE Type)
  {
//--- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(Number,Buffer,Type);
//--- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðå êàê â òàéìñåðèè
   ArraySetAsSeries(Buffer,true);
//---
  }
//+------------------------------------------------------------------+
//| Èíèöèàëèçàöèÿ èíäèêàòîðà                                         |
//+------------------------------------------------------------------+    
void PlotInit(int Number,double Empty_Value,int Draw_Begin,int nShift)
  {
//--- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(Number,PLOT_DRAW_BEGIN,Draw_Begin);
//--- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   PlotIndexSetDouble(Number,PLOT_EMPTY_VALUE,Empty_Value);
//--- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà ïî ãîðèçîíòàëè íà Shift
   PlotIndexSetInteger(Number,PLOT_SHIFT,nShift);
//---
  }
//+------------------------------------------------------------------+
//| CountLine                                                        |
//+------------------------------------------------------------------+
bool CountIndicator(uint     Numb,            // Íîìåð ôóíêöèè CountLine ïî ñïèñêó â êîäå èíäèêàòîðà (ñòàðòîâûé íîìåð - 0)
                    string   Symb,            // Ñèìâîë ãðàôèêà
                    ENUM_TIMEFRAMES TFrame,   // Ïåðèîä ãðàôèêà
                    int      IndHandle,       // Õåíäë îáðàáàòûâàåìîãî èíäèêàòîðà
                    uint     UpBuffNumb,      // Íîìåð âåðõíåãî áóôåðà îáðàáàòûâàåìîãî èíäèêàòîðà äëÿ îáëàêà
                    double&  UpIndBuf[],      // Ïðèåìíûé âåðõíèé áóôåð èíäèêàòîðà äëÿ îáëàêà
                    uint     DnBuffNumb,      // Íîìåð íèæíåãî áóôåðà îáðàáàòûâàåìîãî èíäèêàòîðà äëÿ îáëàêà
                    double&  DnIndBuf[],      // Ïðèåìíûé íèæíèé áóôåð èíäèêàòîðà äëÿ îáëàêà
                    const datetime& iTime[],  // Òàéìñåðèÿ âðåìåíè
                    const int Rates_Total,    // êîëè÷åñòâî èñòîðèè â áàðàõ íà òåêóùåì òèêå
                    const int Prev_Calculated,// êîëè÷åñòâî èñòîðèè â áàðàõ íà ïðåäûäóùåì òèêå
                    const int Min_Rates_Total)// ìèíèìàëüíîå êîëè÷åñòâî èñòîðèè â áàðàõ äëÿ ðàñ÷åòà
  {
//---
   static int LastCountBar[SIZE];
   datetime IndTime[1];
   int limit;
//--- ðàñ÷åòû íåîáõîäèìîãî êîëè÷åñòâà êîïèðóåìûõ äàííûõ
//--- è ñòàðòîâîãî íîìåðà limit äëÿ öèêëà ïåðåñ÷åòà áàðîâ
   if(Prev_Calculated>Rates_Total || Prev_Calculated<=0)// ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷åòà èíäèêàòîðà
     {
      limit=Rates_Total-Min_Rates_Total-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà âñåõ áàðîâ
      LastCountBar[Numb]=limit;
     }
   else limit=LastCountBar[Numb]+Rates_Total-Prev_Calculated; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà íîâûõ áàðîâ 
//--- îñíîâíîé öèêë ðàñ÷åòà èíäèêàòîðà
   for(int bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      //--- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâ IndTime
      if(CopyTime(Symbol(),TFrame,iTime[bar],1,IndTime)<=0) return(RESET);
      //---
      if(iTime[bar]>=IndTime[0] && iTime[bar+1]<IndTime[0])
        {
         LastCountBar[Numb]=bar;
         double UpArr[1],DnArr[1];
         //--- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâû
         if(CopyBuffer(IndHandle,UpBuffNumb,iTime[bar],1,UpArr)<=0) return(RESET);
         if(CopyBuffer(IndHandle,DnBuffNumb,iTime[bar],1,DnArr)<=0) return(RESET);
         //---
         UpIndBuf[bar]=UpArr[0];
         DnIndBuf[bar]=DnArr[0];
        }
      else
        {
         UpIndBuf[bar]=UpIndBuf[bar+1];
         DnIndBuf[bar]=DnIndBuf[bar+1];
        }
     }
//---     
   return(true);
  }
//+------------------------------------------------------------------+
//| TimeFramesCheck()                                                |
//+------------------------------------------------------------------+    
bool TimeFramesCheck(string IndName,
                     ENUM_TIMEFRAMES TFrame) // Ïåðèîä ãðàôèêà èíäèêàòîðà (òàéìôðåéì)
  {
//--- ïðîâåðêà ïåðèîäîâ ãðàôèêîâ íà êîððåêòíîñòü
   if(TFrame<Period() && TFrame!=PERIOD_CURRENT)
     {
      Print("Ïåðèîä ãðàôèêà äëÿ èíäèêàòîðà "+IndName+" íå ìîæåò áûòü ìåíüøå ïåðèîäà òåêóùåãî ãðàôèêà!");
      Print("Ñëåäóåò èçìåíèòü âõîäíûå ïàðàìåòðû èíäèêàòîðà!");
      return(RESET);
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+

Comments