cm_ind_level_cndl

Download script
Author: Copyright � 2014, cmillion@narod.ru
cm_ind_level_cndl

This script is designed to identify and visualize significant price levels on a trading chart by analyzing historical candle data. It specifically looks for structural patterns where price movements exhibit a consistent direction or "stagnation" over a specific number of periods, marking these as potential support or resistance zones.

Core Logic Overview

The indicator operates by scanning the market history based on two primary user-defined parameters: the Candle Window (how many consecutive bars to analyze) and the History Range (how far back into the past to look).

The logic functions through a continuous scan of historical data, performing the following checks:

1. Identifying Resistance Levels (Upper Bounds)

The script looks for sequences where price activity remains consistently below a specific high point. For every candle in the chosen history range, it evaluates a cluster of nearby candles (the "Candle Window").

  • The Condition: If the highest price reached during that window is lower than or equal to the current reference point, and there are no significant "breakouts" upward within that sequence, the script validates this as a resistance zone.
  • Visualization: Once confirmed, it draws a green horizontal trend line extending from the start of the pattern to the current time.

2. Identifying Support Levels (Lower Bounds)

Simultaneously, the script performs a mirror analysis to find price floors. It looks for sequences where price activity remains consistently above a specific low point.

  • The Condition: If the lowest price reached during the candle window stays at or below the reference low, and no significant downward "breakthroughs" occur within that sequence, it identifies a support zone.
  • Visualization: When these conditions are met, the script draws a red horizontal trend line extending to the current time.

Key Behavioral Characteristics

  • Dynamic Level Tracking: The tool doesn't just mark one point in time; it creates lines that project forward. This allows traders to see how a historically significant price level relates to the current live market price.
  • Automatic Cleanup: To keep the chart clean and prevent technical clutter, the script includes a maintenance routine. When the indicator is removed from the chart or restarted, it automatically deletes the specific trend lines it created, ensuring no "ghost" lines remain.
  • Visual Priority: The script handles object creation by ensuring that new data points update existing lines rather than stacking multiple overlapping lines on top of one another, providing a clean, readable interface for the user.

In essence, this tool automates the process of finding "price memory"—identifying areas where the market has historically struggled to move past (resistance) or fall below (support) over a specific period of time.

12 Views
0 Downloads
0 Favorites
cm_ind_level_cndl
//+------------------------------------------------------------------+
//|                                            cm_ind_level_cndl.mq4 |
//|                                Copyright 2014, cmillion@narod.ru |
//|                                               http://cmillion.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, cmillion@narod.ru"
#property link      "http://cmillion.ru"
#property description "Level"
#property strict

#property indicator_chart_window

input int Candles=5; //ñêîëüêî ñâå÷åé çàöåïèëà öåíà
input int History=50; //íà êàêîì ïðîìåæóòêå èùåì
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(!ObjectFind("UP1")) ObjectDelete(0,"UP1");
   if(!ObjectFind("DN1")) ObjectDelete(0,"DN1");
   if(!ObjectFind("UP")) ObjectDelete(0,"UP");
   if(!ObjectFind("DN")) ObjectDelete(0,"DN");
  }
//+------------------------------------------------------------------+
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 j=0,i=0; i<History; i++)
     {
      double H = High[i];
      double L = MathMax(Open[i],Close[i]);
      bool YES=true;
      for(j=i; j<i+Candles; j++)
        {
         if(High[j]<L || MathMax(Open[j],Close[j])>H) {YES=false;break;}
         if(H>High[j]) H=High[j];
         if(L<MathMax(Open[j],Close[j])) L=MathMax(Open[j],Close[j]);
        }
      if(YES)
        {
         TrendCreate(0,"UP",0,Time[j],H,Time[i],H,clrGreen,STYLE_SOLID,5);
         TrendCreate(0,"UP1",0,Time[j],H,Time[0],H,clrGreen);
        }

      H = MathMin(Open[i],Close[i]);
      L = Low[i];
      YES=true;
      for(j=i; j<i+Candles; j++)
        {
         if(MathMin(Open[j],Close[j])<L || Low[j]>H) {YES=false;break;}
         if(H>MathMin(Open[j],Close[j])) H=MathMin(Open[j],Close[j]);
         if(L<Low[j]) L=Low[j];
        }
      if(YES)
        {
         TrendCreate(0,"DN",0,Time[j],L,Time[i],L,clrRed,STYLE_SOLID,5);
         TrendCreate(0,"DN1",0,Time[j],L,Time[0],L,clrRed);
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
bool TrendCreate(const long            chart_ID=0,        // ID ãðàôèêà
                 const string          name="TrendLine",  // èìÿ ëèíèè
                 const int             sub_window=0,      // íîìåð ïîäîêíà
                 datetime              time1=0,           // âðåìÿ ïåðâîé òî÷êè
                 double                price1=0,          // öåíà ïåðâîé òî÷êè
                 datetime              time2=0,           // âðåìÿ âòîðîé òî÷êè
                 double                price2=0,          // öåíà âòîðîé òî÷êè
                 const color           clr=clrRed,        // öâåò ëèíèè
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // ñòèëü ëèíèè
                 const int             width=1,           // òîëùèíà ëèíèè
                 const bool            back=false,        // íà çàäíåì ïëàíå
                 const bool            selection=false,   // âûäåëèòü äëÿ ïåðåìåùåíèé
                 const bool            ray_left=false,    // ïðîäîëæåíèå ëèíèè âëåâî
                 const bool            ray_right=false,   // ïðîäîëæåíèå ëèíèè âïðàâî
                 const bool            hidden=true,       // ñêðûò â ñïèñêå îáúåêòîâ
                 const long            z_order=0)         // ïðèîðèòåò íà íàæàòèå ìûøüþ
  {
   if(!ObjectFind(name)) ObjectDelete(chart_ID,name);
   ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_LEFT,ray_left);
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   return(true);
  }
//+------------------------------------------------------------------+

Comments