SHI_SilverTrendSig_003

Download script
Author: Copyright � 2005-07, Shurka
SHI_SilverTrendSig_003

The SHI_SilverTrendSig is a technical analysis indicator designed for the MetaTrader 4 platform. Its primary purpose is to provide visual "buy" and "sell" signals on a price chart by identifying specific price action patterns and momentum shifts.

Core Logic Overview

The script operates by analyzing historical price data (High, Low, and Close prices) over a user-defined period to determine when the market is reaching an extreme point or showing a potential trend reversal. Instead of using standard moving averages, it focuses on the relationship between the current price and the boundaries established over a specific window of time.

Key Technical Components

The logic can be broken down into three main stages:

1. Price Range Analysis The indicator looks back at a specific number of previous bars (defined by the "Period" setting). During this lookback, it identifies two critical values:

  • The highest price reached in that period.
  • The lowest price reached in that period.

This establishes a "trading zone," allowing the script to understand the recent volatility and range of the asset.

2. Momentum Calculation (The "R" Factor) The script performs a unique calculation to determine the current "weight" or momentum of the price movement. It calculates a weighted average of the differences between Highs and Lows over the most recent candles. This helps the indicator understand not just where the price is, but how aggressively it is moving toward its target.

3. Signal Triggering The script then compares the current closing price against the established highs and lows using a customizable "Offset" percentage:

  • Sell Signal: If the current closing price drops significantly toward the bottom of the recent range (relative to the volatility calculated), the script triggers a "Sell" signal.
  • Buy Signal: If the current closing price rises significantly toward the top of the recent range, it triggers a "Buy" signal.

Visual Customization

To make the tool user-friendly for different trading styles, the script includes a variety of visual presets. It allows users to choose between different types of on-screen arrows (e.g., thick, thin, hollow, round, or diagonal). This ensures that the signals are clearly visible and distinct from other chart elements.

Summary for the User

Essentially, this indicator acts as an "oversold/overbought" alert system with a momentum twist. It waits for the price to push into extreme territory relative to its recent history; once that threshold is breached, it places an arrow on the chart to notify the trader of a potential trend shift.

Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
SHI_SilverTrendSig_003
//+------------------------------------------------------------------+
//|                                           SHI_SilverTrendSig.mq4 |
//|          Copyright © 2003, VIAC.RU, OlegVS, GOODMAN, 2005 Shurka |
//|                                                 shforex@narod.ru |
//|                                                                  |
//|                                                                  |
//| Ïèøó ïðîãðàììû íà çàêàç                                          |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005-07, Shurka"
#property link      "http://shforex.narod.ru"

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

//---- Âõîäíûå ïàðàìåòðû
extern int     AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int     Otstup=30;//Îòñòóï.
extern double  Per=9;//Ïåðèîä.
extern string note4 = "Arrow Type";
extern string note5 = "0=Thick, 1=Thin, 2=Hollow, 3=Round";
extern string note6 = "4=Fractal, 5=Diagonal Thin";
extern string note7 = "6=Diagonal Thick, 7=Diagonal Hollow";
extern string note8 = "8=Thumb, 9=Finger";
extern int ArrowType=3;

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");

   if (ArrowType == 0) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 233);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 234);
   }
   else if (ArrowType == 1) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 225);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 226);
   }
   else if (ArrowType == 2) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 241);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 242);
   }
   else if (ArrowType == 3) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 221);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 222);
   }
   else if (ArrowType == 4) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 217);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 218);
   }
   else if (ArrowType == 5) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 228);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 230);
   }
   else if (ArrowType == 6) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 236);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 238);
   }
   else if (ArrowType == 7) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 246);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 248);
   }
   else if (ArrowType == 8) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 67);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 68);
   }
   else if (ArrowType == 9) {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 71);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 72);
   }

   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