rvmGann_sv7

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
rvmGann_sv7

This script is a specialized technical analysis indicator designed to identify and visualize significant price extremes—specifically "highs" and "lows"—on a trading chart. It uses a sophisticated logic system to determine which price points represent true structural turning points rather than just minor fluctuations in market noise.

Core Logic and Behavior

The primary objective of this script is to filter through every price movement to isolate key structural peaks and valleys. It achieves this through three main logical layers:

1. Dynamic Range Tracking The script constantly monitors the current "active" high and low for a specific price range. It compares every new price bar against these stored values. If a new high or low is reached that exceeds the previous boundaries, the script updates its internal memory to reflect this new extreme. This ensures that the indicator is always aware of the most significant price levels reached during the current market move.

2. Trend and Sentiment Analysis (Sequential Logic) One of the most unique aspects of this script is its ability to determine the "intent" behind a price move. It doesn't just look at where the price is; it analyzes how the price moved to get there. By examining several factors—such as the relationship between opening prices, closing prices, and high/low values—the script assigns a directional bias. It attempts to differentiate between a standard retracement and a genuine shift in market momentum.

3. ZigZag Filtering and Confirmation The script incorporates logic similar to a "ZigZag" indicator but with extra confirmation layers. Instead of drawing a line for every tiny move, it waits for specific conditions to be met:

  • Sequence Validation: It tracks the sequence of highs and lows to ensure they are occurring in a logical order.
  • Threshold Requirements: It uses an input parameter (the "tendency" setting) to decide how much price movement is required before a new significant point is officially recognized and drawn on the chart.
  • State Management: The script maintains an internal state of whether it is currently looking for a new high or a new low. Once a significant move in one direction is confirmed, it switches its focus to identifying the opposite extreme.

Visual Representation

On the trading platform, this logic translates into two distinct visual elements:

  • Primary Peaks and Valleys: These are the structural points where the price has made a major turn. They are connected to provide a clear visual "skeleton" of the market's primary trend.
  • Dynamic Updates: The script is designed to update in real-time. As new data comes in, it constantly recalculates whether the current high or low is being broken, potentially refining the points on the chart as more information becomes available.

Summary for the User

In simple terms, this tool acts like an automated "map maker" for price action. It ignores the "jitter" of daily trading and instead identifies the major landmarks where the market has shifted direction. By using complex proximity checks and trend sequence logic, it provides a cleaner view of the market structure, helping traders see the significant historical highs and lows more clearly than they would by looking at raw price alone.

Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
12 Views
0 Downloads
0 Favorites
rvmGann_sv7
//+------------------------------------------------------------------+
//|                                                  rvmGann_sv7.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 DeepSkyBlue
#property indicator_color2 DeepSkyBlue
#property indicator_color3 DeepSkyBlue
#property indicator_color4 DeepSkyBlue
#property indicator_color5 DeepSkyBlue
#property indicator_color6 DeepSkyBlue
#property indicator_color7 DeepSkyBlue
#property indicator_color8 DeepSkyBlue
//---- input parameters
extern int GSv_tend=2;
//---- buffers
double Upz[];
double Dnz[];
double sH[];
double sL[];
double aH[];
double aL[];
double fB[];
double lB[];
//----------
double CurH,CurL;
int lb,sp,lbars;
bool draw_up,draw_dn;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_ZIGZAG,STYLE_SOLID);
   SetIndexStyle(1,DRAW_ZIGZAG,STYLE_SOLID);
   SetIndexStyle(2,DRAW_NONE);
   SetIndexStyle(3,DRAW_NONE);
   SetIndexStyle(4,DRAW_NONE);
   SetIndexStyle(5,DRAW_NONE);
   SetIndexStyle(6,DRAW_NONE);
   SetIndexStyle(7,DRAW_NONE);
   SetIndexBuffer(0,Upz);
   SetIndexBuffer(1,Dnz);
   SetIndexBuffer(2,sH);
   SetIndexBuffer(3,sL);
   SetIndexBuffer(4,aH);
   SetIndexBuffer(5,aL);
   SetIndexBuffer(6,fB);
   SetIndexBuffer(7,lB);
   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
   SetIndexEmptyValue(2,0);
   SetIndexEmptyValue(3,0);
   SetIndexEmptyValue(4,-1);
   SetIndexEmptyValue(5,-1);
   SetIndexEmptyValue(6,-1);
   SetIndexEmptyValue(7,-1);
   SetIndexLabel(0,"z1");
   SetIndexLabel(1,"z2");
   SetIndexLabel(2,"sH");
   SetIndexLabel(3,"sL");
   SetIndexLabel(4,"aH");
   SetIndexLabel(5,"aL");
   SetIndexLabel(6,"fB");
   SetIndexLabel(7,"lB");
//----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int cb,index,limit,ai,i;
//---- 
   if( !counted_bars<0 )
   {
      index=Bars-1;
      if( index-counted_bars<2 )
      {
         limit=0;
      }
      else
      {
         limit=index-counted_bars-1;
      }
   }
   else
   {
      Alert("Ñáîé ðàñ÷åòà èíäèêàòîðà rvmGSv_mt");
      return(-1);
   }
//----
for( cb=limit; cb>=0; cb-- )
{
   ai=index-cb;
   if( lbars!=Bars && lb==ai )
   {
      lbars=Bars;
      continue;
   }
   if( lb!=ai )
   {
      lb=ai;
      if( Upz[cb+1]>0 || Dnz[cb+1]>0 )
      {
         aH[cb]=High[cb+1];
         aL[cb]=Low[cb+1];
      }
      else
      {
         if( High[cb+1]<=aH[cb+1] && Low[cb+1]>=aL[cb+1] )
         {
            aH[cb]=aH[cb+1];
            aL[cb]=aL[cb+1];
            sH[cb]=sH[cb+1];
            sL[cb]=sL[cb+1];
         }
         else
         {
            if( High[cb+1]>aH[cb+1] )
            {
               aH[cb]=High[cb+1];
            }
            else
            {
               aH[cb]=aH[cb+1];
            }
            if( aL[cb+1]>0 )
            {
               if( Low[cb+1]<aL[cb+1] )
               {
                  aL[cb]=Low[cb+1];
               }
               else
               {
                  aL[cb]=aL[cb+1];
               }
            }
            else
            {
               aL[cb]=Low[cb+1];
            }
         }
      }
      if( draw_up!=0 )
      {
         if( fB[cb+1]==1 )
         {
            sH[cb]=sH[cb+1]+1;
            if( lB[cb+1]==0 )
            {
               sH[cb]=0;
               sL[cb]=1;
            }
         }
         else
         {
            if( fB[cb+1]==0 )
            {
               sL[cb]=sL[cb+1]+1;
               if( lB[cb+1]==1 )
               {
                  sH[cb]=1;
                  sL[cb]=0;
               }
            }
         }
      }
      else
      {
         if( draw_dn!=0 )
         {
            if( fB[cb+1]==0 )
            {
               sL[cb]=sL[cb+1]+1;
               if( lB[cb+1]==1 )
               {
                  sH[cb]=1;
                  sL[cb]=0;
               }
            }
            else
            {
               if( fB[cb+1]==1 )
               {
                  sH[cb]=sH[cb+1]+1;
                  if( lB[cb+1]==0 )
                  {
                     sH[cb]=0;
                     sL[cb]=1;
                  }
               }
            }
         }
         else
         {
            if( fB[cb+1]==1 )
            {
               sH[cb]=sH[cb+1]+1;
               sL[cb]=sL[cb+1];
               if( lB[cb+1]==0 )
               {
                  sL[cb]++;
               }
            }
            else
            {
               if( fB[cb+1]==0 )
               {
                  sH[cb]=sH[cb+1];
                  sL[cb]=sL[cb+1]+1;
                  if( lB[cb+1]==1 )
                  {
                     sH[cb]++;
                  }
               }
            }
         }
      }
      //îáíóëÿåì
      CurH=0;
      CurL=Low[cb];
   }
   //Print(TimeToStr(Time[cb])," ",CurH," ",CurL);
   if( High[cb]<=aH[cb] && Low[cb]>=aL[cb] )
   {
      continue;
   }
   if( High[cb]<=CurH && Low[cb]>=CurL )
   {
      continue;
   }
   if( High[cb]>CurH ) CurH=High[cb];
   if( Low[cb] <CurL ) CurL=Low[cb];
   Extr_seq(cb);
   if( draw_up!=0 )
   {
      if( fB[cb]==1 )
      {
         if( sp!=ai )
         {
            Upz[index-sp]=0;
            sp=ai;
         }
         Upz[cb]=High[cb];
         if( lB[cb]==0 && (sL[cb]+1)>=GSv_tend && GSv_tend<2 )
         {
            Dnz[cb]=Low[cb];
            draw_up=0;
            draw_dn=1;
         }
      }
      else
      {
         if( fB[cb]==0 )
         {
            if( (sL[cb]+1)>=GSv_tend )
            {
               Dnz[cb]=Low[cb];
               sp=ai;
               draw_up=0;
               draw_dn=1;
               if( lB[cb]==1 && (sH[cb]+1)>=GSv_tend )
               {
                  Upz[cb]=High[cb];
                  draw_up=1;
                  draw_dn=0;
               }
            }
            else
            {
               if( lB[cb]==1 )
               {
                  Upz[index-sp]=0;
                  sp=ai;
                  Upz[cb]=High[cb];
               }
            }
         }
      }
   }
   else
   {
      if( draw_dn!=0 )
      {
         if( fB[cb]==1 )
         {
            if( (sH[cb]+1)>=GSv_tend )
            {
               Upz[cb]=High[cb];
               sp=ai;
               draw_up=1;
               draw_dn=0;
               if( lB[cb]==0 && (sL[cb]+1)>=GSv_tend )
               {
                  Dnz[cb]=Low[cb];
                  draw_up=0;
                  draw_dn=1;
               }
            }
            else
            {
               if( lB[cb]==0 )
               {
                  Dnz[index-sp]=0;
                  sp=ai;
                  Dnz[cb]=Low[cb];
               }
            }
         }
         else
         {
            if( fB[cb]==0 )
            {
               if( sp!=ai )
               {
                  Dnz[index-sp]=0;
                  sp=ai;
               }
               Dnz[cb]=Low[cb];
               if( lB[cb]==1 && (sH[cb]+1)>=GSv_tend && GSv_tend<2 )
               {
                  Upz[cb]=High[cb];
                  draw_up=1;
                  draw_dn=0;
               }
            }
         }
      }
      else
      {
         if( fB[cb]==1 && (sH[cb]+1)>=GSv_tend )
         {
            Dnz[index]=Low[index];
            Upz[cb]=High[cb];
            draw_up=1;
            sp=ai;
            if( lB[cb]==0 && (sL[cb]+1)>=GSv_tend )
            {
               Dnz[cb]=Low[cb];
               draw_up=0;
               draw_dn=1;
            }
         }
         else
         {
            if( fB[cb]==0 && (sL[cb]+1)>=GSv_tend )
            {
               Upz[index]=High[index];
               Dnz[cb]=Low[cb];
               draw_dn=1;
               sp=ai;
               if( lB[cb]==1 && (sH[cb]+1)>=GSv_tend )
               {
                  Upz[cb]=High[cb];
                  draw_up=1;
                  draw_dn=0;
               }
            }
         }
      }
   }
}
//----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Ôóíêöèÿ îïðåäåëÿåò ïîñëåäîâàòåëüíîñòü ïîÿâëåíèÿ ýêñòðåìóìîâ      |
//+------------------------------------------------------------------+
void Extr_seq(int curb)
  {
//---- 
   if( fB[curb]<0 )
   {
      //åñëè áàð ïðîñ÷èòûâàåòñÿ ïî èñòîðèè è îí ñðàçó âíåøíèé
      if( High[curb]>aH[curb] && Low[curb]<aL[curb] )
      {
         //åñëè òåêóùèé êëîç áëèæå ê àêòèâíîìó ëîó
         if( MathAbs(Close[curb]-aL[curb])<MathAbs(Close[curb]-aH[curb]) )
         {
            fB[curb]=1;
            lB[curb]=0;
         }
         else //èíà÷å åñëè òåêóùèé êëîç áëèæå ê àêòèâíîìó ëîó
         {
            //åñëè òåêóùèé êëîç áëèæå ê àêòèâíîìó õàþ
            if( MathAbs(Close[curb]-aL[curb])>MathAbs(Close[curb]-aH[curb]) )
            {
               fB[curb]=0;
               lB[curb]=1;
            }
            else //èíà÷å åñëè òåêóùèé êëîç áëèæå ê àêòèâíîìó õàþ
            {
               //åñëè òåêóùèé îïåí áëèæå ê àêòèâíîìó õàþ
               if( MathAbs(Open[curb]-aH[curb])<MathAbs(Open[curb]-aL[curb]) )
               {
                  fB[curb]=1;
                  lB[curb]=0;
               }
               else //èíà÷å åñëè òåêóùèé îïåí áëèæå ê àêòèâíîìó õàþ
               {
                  //åñëè òåêóùèé îïåí áëèæå ê àêòèâíîìó ëîó
                  if( MathAbs(Open[curb]-aH[curb])>MathAbs(Open[curb]-aL[curb]) )
                  {
                     fB[curb]=0;
                     lB[curb]=1;
                  }
                  else //èíà÷å åñëè òåêóùèé îïåí áëèæå ê àêòèâíîìó ëîó
                  {
                     //åñëè òåêóùèé êëîç áëèæå ê òåêóùåìó õàþ
                     if( MathAbs(Close[curb]-High[curb])<MathAbs(Close[curb]-Low[curb]) )
                     {
                        fB[curb]=0;
                        lB[curb]=1;
                     }
                     else //èíà÷å åñëè òåêóùèé êëîç áëèæå ê òåêóùåìó õàþ
                     {
                        //åñëè òåêóùé êëîç áëèæå ê òåêóùåìó ëîó
                        if( MathAbs(Close[curb]-High[curb])>MathAbs(Close[curb]-Low[curb]) )
                        {
                           fB[curb]=1;
                           lB[curb]=0;
                        }
                        else //èíà÷å åñëè òåêóùé êëîç áëèæå ê òåêóùåìó ëîó
                        {
                           //åñëè òåêóùèé îïåí áëèæå ê òåêóùåìó õàþ
                           if( MathAbs(Open[curb]-High[curb])<MathAbs(Open[curb]-Low[curb]) )
                           {
                              fB[curb]=1;
                              lB[curb]=0;
                           }
                           else
                           {
                              fB[curb]=0;
                              lB[curb]=1;
                           }
                        }
                     }
                  }
               }
            }
         }
      }
      else
      {
         if( High[curb]>aH[curb] )
         {
            fB[curb]=1;
         }
         else
         {
            fB[curb]=0;
         }
      }
   }
   else
   {
      //åñëè òåêóùàÿ öåíà ðàâíà ìàêñèìóìó íà áàðå èëè íåò ìèíèìóìà è ïðè ýòîì ìàêñèìóì-íîâûé
      if( (Low[curb]>=aL[curb] || Close[curb]==High[curb] ) && High[curb]>aH[curb] )
      {
         lB[curb]=1;
      }
      else //èíà÷å åñëè öåíà ðàâíà ìàêñèìóìó íà áàðå
      {
         //åñëè öåíà ðàâíà ìèíèìóìó íà áàðå èëè íåò íîâîãî ìàêñèìóìà è ïðè ýòîì ìèíèìóì - íîâûé
         if( (High[curb]<=aH[curb] || Close[curb]==Low[curb]) && Low[curb]<aL[curb] )
         {
            lB[curb]=0;
         }
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments