SHI_SilverTrendColourBars_v1
Download scriptThis tool is designed to provide a visual representation of market trends by highlighting specific price action on your trading chart. Instead of standard candles, it uses a dual-colored histogram system to help traders identify the prevailing momentum between "Up" and "Down" movements.
Core Logic Overview
The script analyzes historical price data over a user-defined period to determine whether the current market sentiment is bullish or bearish. It does this by calculating the highest and lowest price points within a specific window of time (the "Period"). By establishing these boundaries, the tool can measure where the current closing price sits relative to that recent range.
How it Identifies Trends
The logic operates based on a "buffer" or "threshold" system:
- Trend Detection: The script looks at the distance between the highest high and the lowest low of the selected period.
- Dynamic Coloring:
- If the price closes significantly toward the lower end of that range (based on a percentage you can set), the tool marks the bars to reflect a downward bias.
- Conversely, if the price closes significantly toward the upper end of that range, it marks the bars to reflect an upward bias.
- Visual Output: These findings are rendered as histograms directly on your chart. The colors (typically Blue and Red) shift automatically as the price action moves between these high and low extremes, providing a clear visual cue of the current trend direction.
Key Features for the User
- Customizable Sensitivity: You can adjust the "Period" to change how much historical data the tool considers when deciding on a trend, and the "Offset" (Otstup) allows you to control how sensitive the color changes are to price fluctuations.
- Data Management: The script includes an optimization feature that ensures it only calculates data for the amount of history you actually want to see. This keeps the chart running smoothly without unnecessary processing of ancient data.
- Clean Integration: It is designed to sit on the main chart window, providing a clean visual overlay that simplifies the interpretation of market structure at a glance.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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