Three_Color_v1

Author: Copyright � 2005, MetaQuotes Software Corp.
Three_Color_v1

This custom indicator for MetaTrader is designed to provide a visual representation of market trends by displaying three distinct colored lines on your trading chart. Rather than showing a single continuous line, it segments the price action into different phases, using Red, Green, and Blue colors to highlight specific periods.

How the Logic Works

The script functions by analyzing a Moving Average (a common tool used to smooth out price fluctuations) and applying it across three separate "layers" or categories. It processes historical data in blocks to determine which color should be visible at any given point in time:

  • Phase 1 (Red): The indicator identifies specific sections of the chart where the first data set is active. During these periods, only the Red line is rendered, while the other two colors are hidden.
  • Phase 2 (Green): The script then identifies separate sections where the second data set takes priority. In these areas, the Green line appears, and the Red and Blue lines are removed.
  • Phase 3 (Blue): Finally, it identifies sections for the third data set. Here, the Blue line becomes visible, and the other two colors remain hidden.

Visual Behavior

Instead of all three colors overlapping constantly, the indicator "switches" them on and off based on the chronological position of the price bars. This creates a segmented visual effect where you can see the market transition from one state to another.

To make these transitions easier to track, the script includes a dynamic width adjustment. It automatically cycles the thickness of the lines, making it easier for the user to distinguish between different trend segments as they progress across the trading history.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Three_Color_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                  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