Author: Copyright � 2007, Heaven
Beginner

This tool is designed as a visual technical indicator for the MetaTrader trading platform. Its primary purpose is to analyze price movements on a chart and provide clear visual cues—in the form of blue and red arrows—to help identify potential trend shifts or entry points.

Core Logic Overview

The script functions by scanning historical price data to identify specific "exhaustion" points where the price moves significantly far from its recent established range. It doesn't just look at the current price; it calculates a weighted relationship between high and low price points over a set period to determine the volatility of the market.

Key Components of the Analysis:

  • Volatility Calculation: The script looks at a specific window of previous candles (defined by the "Period" setting). It calculates a dynamic range based on the difference between the highest highs and lowest lows within that timeframe.
  • Distance Measurement: Rather than triggering a signal every time the price moves, the logic uses a "Margin" or "Offset" system. It measures how far the current closing price has deviated from the recent high or low extremes.
  • Trend Filtering (State Awareness): To prevent the chart from becoming cluttered with constant overlapping signals, the script possesses a "memory" of the last signal it provided. It is designed to alternate between upward and downward signals; for instance, it will prioritize showing an upward signal only if the previous significant move was downward, and vice versa.

Visual Output

  • Buy Signals (Blue Arrows): These appear when the price drops significantly below a calculated threshold relative to its recent highs. This suggests that the downward momentum may be overextended.
  • Sell Signals (Red Arrows): These appear when the price rises significantly above a calculated threshold relative to its recent lows, suggesting that the upward momentum may be reaching a peak.

User Customization

The tool allows for three main manual adjustments to fine-tune its sensitivity:

  1. Lookback Limit: Determines how much historical data the script should analyze at once.
  2. Offset/Margin: Controls how "far" the price must stretch before an arrow is drawn (higher values result in fewer, more conservative signals).
  3. Period: Adjusts the timeframe used to calculate the recent highs and lows, allowing the user to switch between identifying short-term fluctuations or longer-term trends.
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Beginner
//+------------------------------------------------------------------+
//|                                           Beginner.mq4 |
//|          Copyright © 2007 |
//|                                                                  |
//|                                                                  |
//|                                                                  |
//| Ïèøó ïðîãðàììû íà çàêàç                                          |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Heaven"
#property link      "http://Beginner.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#define  SH_BUY   1
#define  SH_SELL  -1

//---- Âõîäíûå ïàðàìåòðû
extern int     AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int     Otstup=30;//Îòñòóï.
extern double  Per=9;//Ïåðèîä.
int            SH,NB,i,UD;
double         R,SHMax,SHMin;
double         BufD[];
double         BufU[];
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè                                            |
//+------------------------------------------------------------------+
int init()
{
   // NB çàïèñûâàåì êîëè÷åñòâî áàðîâ äëÿ êîòîðûõ ñ÷èòàåì èíäèêàòîð
   if (Bars<AllBars+Per || AllBars==0) NB=Bars-Per; else NB=AllBars;
   IndicatorBuffers(2);
   IndicatorShortName("SHI_SilverTrendSig");
   SetIndexStyle(0,DRAW_ARROW,0,1);
   SetIndexStyle(1,DRAW_ARROW,0,1);
   SetIndexArrow(0,159);
   SetIndexArrow(1,159);
   SetIndexBuffer(0,BufU);
   SetIndexBuffer(1,BufD);
   SetIndexDrawBegin(0,Bars-NB);//Èíäèêàòîð áóäåòîòîáðàæàòüñÿ òîëüêî äëÿ NB áàðîâ
   SetIndexDrawBegin(1,Bars-NB);
   ArrayInitialize(BufD,0.0);//Çàáü¸ì îáà áóôåðà íîëèêàìè. Èíà÷å áóäåò ìóñîð ïðè ñìåíå òàéìôðåéìà.
   ArrayInitialize(BufU,0.0);
   return(0);
}
//+------------------------------------------------------------------+
//| Ôóíêöèÿ äåèíèöèàëèçàöèè                                          |
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
}
//+------------------------------------------------------------------+
//| Ñîáñíà èíäèêàòîð                                                 |
//+------------------------------------------------------------------+
int start()
{
   int CB=IndicatorCounted();
   /* Òóò âîò òà ñàìàÿ îïòèìèçàöèîííàÿ ôèøêà.  ÿçûê ââåäåíà ôóíêöèÿ, êîòîðàÿ âîçâðàùàåò êîëè÷åñòâî
   ïîñ÷èòàííûõ áàðîâ, ïðè÷¸ì î÷åíü õèòðî. Ïðè ïåðâîì âûçîâå èíäèêàòîðà ýòî 0, âñ¸ ïîíÿòíî, åù¸ íè÷åãî
   íå ñ÷èòàëîñü, à çàòåì âûäà¸ò êîëè÷åñòâî îáñ÷èòàííûõ áàðîâ ìèíóñ îäèí. Ò.å. åñëè âñåãî áàðîâ 100,
   òî ôóíêöèÿ âåðí¸ò 99. ß ââ¸ë òàêîé êîä, âûøå ó ìåíÿ îïðåäåëÿëàñü NB - êîë-âî áàðîâ ïîäëåæàùèõ
   îáñ÷¸òó.  ïðèíöèïå ýòîò ïàðàìåòð ìîæíî è âûêèíóòü, îäíàêî äëÿ òåõ êòî â òàíêå (I80286) ìîæíî
   è îñòàâèòü. Òàê âîò, çäåñü, ïðè ïåðâîì âûçîâå NB îñòà¸òñÿ ïðåæíåé, à ïðè ïîñëåäóþùèõ óìåíüøàåòñÿ
   äî ïîñëåäíåãî áàðà, ò.å. 1 èëè 2, íó èëè ñêîëüêî òàì îñòàëîñü ïîñ÷èòàòü*/
   if(CB<0) return(-1); else if(NB>Bars-CB) NB=Bars-CB;
   for (SH=1;SH<NB;SH++)//Ïðî÷¸ñûâàåì ãðàôèê îò 1 äî NB
   {
      for (R=0,i=SH;i<SH+10;i++) {R+=(10+SH-i)*(High[i]-Low[i]);}      R/=55;

      SHMax = High[Highest(NULL,0,MODE_HIGH,Per,SH)];
      SHMin = Low[Lowest(NULL,0,MODE_LOW,Per,SH)];
      if (Close[SH]<SHMin+(SHMax-SHMin)*Otstup/100 && UD!=SH_SELL) { BufU[SH]=Low[SH]-R*0.5; UD=SH_SELL; }
      if (Close[SH]>SHMax-(SHMax-SHMin)*Otstup/100 && UD!=SH_BUY) { BufD[SH]=High[SH]+R*0.5; UD=SH_BUY; }
   }
   return(0);
}

Comments