Three_Color
Download scriptThis script is designed as a visual charting tool that organizes price movement data into three distinct colored lines: Red, Green, and Blue. Rather than showing a single continuous trend line, the logic works by segmenting the price history into specific repeating patterns or "zones."
How the Logic Works
The indicator processes the chart's history by looking at groups of bars. It uses a moving average calculation—a standard method for smoothing out price fluctuations—as the foundation for all three lines. However, instead of displaying this average constantly, it applies a selective visibility logic based on where those averages fall in a sequence:
- The Red Line: This is triggered to appear during specific early segments of a cycle. It highlights data points at fixed intervals, appearing and disappearing to mark specific phases of the price action.
- The Green Line: This line activates during the middle segments of the cycles. By clearing the other colors, it ensures that only this trend is visible during these specific periods, allowing for a clear distinction between different market "phases."
- The Blue Line: This line takes over during the final segments of the cycles. It follows the same smoothing logic as the others but is only rendered to be visible at the conclusion of the designated sequence.
Key Visual Behavior
- Sequential Progression: The script is designed so that the colors do not overlap in a messy way. When one color is "active," the others are hidden (set to an empty value). This creates a clean, step-by-step visual progression where the market moves from Red to Green to Blue.
- Rhythmic Patterning: The logic uses a mathematical offset (jumping by 30 bars at a time) to ensure these transitions happen consistently across the chart. This helps traders identify repeating rhythms in price behavior.
- Dynamic Line Thickness: There is an underlying mechanism that adjusts the visual "weight" or thickness of the lines as the indicator updates, ensuring the markings remain clear and consistent with the overall chart layout.
In summary, this tool acts as a visual "pacer." It breaks down complex price movements into three distinct, color-coded zones, helping you see the recurring cycles of the market in a simplified, organized manner.
//+------------------------------------------------------------------+
//| three_color.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 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Blue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,ExtMapBuffer3);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,j,shift;
static int width=1;
//----
for(i=0; i<Bars-21; i+=30)
{
for(j=0,shift=i; j<11; j++,shift++)
{
ExtMapBuffer1[shift]=iMA(NULL,0,13,MODE_SMA,0,PRICE_CLOSE,shift);
if(j>0 && j<10)
{
ExtMapBuffer2[shift]=EMPTY_VALUE;
ExtMapBuffer3[shift]=EMPTY_VALUE;
}
}
}
//----
for(i=10; i<Bars-11; i+=30)
{
for(j=0,shift=i; j<11; j++,shift++)
{
ExtMapBuffer2[shift]=iMA(NULL,0,13,MODE_SMA,0,PRICE_CLOSE,shift);
if(j>0 && j<10)
{
ExtMapBuffer1[shift]=EMPTY_VALUE;
ExtMapBuffer3[shift]=EMPTY_VALUE;
}
}
}
//----
for(i=20; i<Bars-1; i+=30)
{
for(j=0,shift=i; j<11; j++,shift++)
{
ExtMapBuffer3[shift]=iMA(NULL,0,13,MODE_SMA,0,PRICE_CLOSE,shift);
if(j>0 && j<10)
{
ExtMapBuffer1[shift]=EMPTY_VALUE;
ExtMapBuffer2[shift]=EMPTY_VALUE;
}
}
}
//----
if(width>10) width=1;
else width++;
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,width);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,width);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,width);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments