SHI_SilverTrendColourBars
Download scriptThis tool is designed as a visual aid for traders using the MetaTrader platform. It works by analyzing price action and overlaying colored bars on your chart to help highlight specific market trends based on historical price extremes.
How the Logic Works
The script functions by looking back at a specific number of past candles (determined by the user's settings) and identifying the "High" and "Low" price points within a moving window. It essentially creates a dynamic range for every point on the chart.
For every candle, the tool performs the following logic:
- Range Detection: It identifies the highest price reached and the lowest price reached over a set period of time.
- Trend Comparison: It then compares the current closing price of that candle against those historical highs and lows.
- Color Coding:
- If the price is trading significantly near the bottom of that identified range (based on a user-defined percentage offset), it signals one trend (represented in Blue).
- If the price is trading significantly near the top of that identified range, it signals the opposite trend (represented in Red).
Key Features for the User
- Visual Clarity: The tool converts complex price data into a simple "histogram" style display. This allows traders to see at a glance whether the market is leaning toward the upper or lower bounds of its recent range.
- Customizable Sensitivity: You can adjust the "Period" (how far back the script looks to find highs and lows) and the "Offset" (how close to the extreme the price must be to trigger a color change). This allows you to tune the indicator to be either very sensitive or more conservative.
- Performance Optimization: The logic includes built-in safeguards to ensure the script only calculates what is necessary on your screen, helping to maintain smooth performance on your trading terminal without unnecessary processing of old data.
Important Note for Setup
To view this indicator correctly, it should be placed in the "Foreground Chart" setting within your platform's menu. This ensures that the colored bars appear clearly over the price action rather than being hidden behind other chart elements.
//+------------------------------------------------------------------+
//| SHI_SilverTrendColourBars.mq4 |
//| Copyright © 2003, VIAC.RU, OlegVS, GOODMAN, 2005 Shurka |
//| shforex@narod.ru |
//| |
//| |
//| Ïèøó ïðîãðàììû íà çàêàç |
//+------------------------------------------------------------------+
/*
ÂÀÆÍÎ!!! Äëÿ êîððåêòíîãî îòîáðàæåíèÿ èíäèêàòîðà âûêëþ÷èòå â ìåíþ
"Ãðàôèêè" ("Charts") ïóíêò "Ãðàôèê ñâåðõó" ("Foreground Chart")
èíà÷å áàðû áóäóò îòîáðàæàòüñÿ ïîâåðõ èíäèêàòîðà çàñëîíÿÿ èõ.
*/
#property copyright "Copyright © 2005, Shurka"
#property link "http://shforex.narod.ru"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- Âõîäíûå ïàðàìåòðû
extern int AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int Otstup=30;//Îòñòóï.
extern double Per=9;//Ïåðèîä.
int SH,NB;
double 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_SilverTrendColourBars");
SetIndexStyle(0,DRAW_HISTOGRAM,0,1);
SetIndexStyle(1,DRAW_HISTOGRAM,0,1);
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=0;SH<NB;SH++)//Ïðî÷¸ñûâàåì ãðàôèê îò 0 äî NB
{
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) {BufU[SH]=High[SH]; BufD[SH]=Low[SH];}
if (Close[SH]>SHMax-(SHMax-SHMin)*Otstup/100) {BufD[SH]=High[SH]; BufU[SH]=Low[SH];}
}
return(0);
}
Comments