MA_kanal

This script is designed to provide traders with a sophisticated visual overlay on their trading charts. Rather than just showing a single price line, it creates a multi-layered system of "Envelopes" and moving averages that help identify price boundaries, trends, and potential areas of support or resistance.

Here is a breakdown of how the logic works in plain English:

Core Mechanics

The script calculates several different layers based on a Moving Average (MA) calculation. It uses a primary period (set by default to 55) to determine the "average" price over time, and then creates a series of "Envelopes" around that average.

The Envelope System: Think of an envelope as a boundary line that sits at a specific percentage above or below the current average price. This script generates eight distinct lines:

  • Upper Boundaries: It calculates four different upper levels using various multipliers (such as 0.38, 0.62, 1.0, and 1.38). These represent varying degrees of "overextension" to the upside.
  • Lower Boundaries: Similarly, it calculates four lower levels using the same multipliers. These help identify how far the price has dropped relative to its average.

Dynamic Visual Projections

One unique feature of this script is its ability to project these lines into the future. Instead of just showing where the price is, the logic includes a calculation that extends these trend lines forward on the chart. This is intended to give traders a visual sense of where the "boundaries" might be heading based on the current momentum of the market.

Trend Tracking

In addition to the envelopes, the script includes a specific Moving Average tracker (labeled as LB). It compares the current average price against a slightly older average to determine the direction of the trend. This is visualized as a distinct line that helps confirm whether the broader market direction is moving up or down.

Key Features for the User

  • Visual Organization: The script automatically handles the creation and cleanup of these lines on your chart. It places specific labels (like U1, D1, LB, etc.) next to the lines so you can easily distinguish between the different layers.
  • Automatic Cleanup: To keep your chart clean, the script is programmed to remove these objects when they are no longer needed or when certain conditions are met, ensuring the interface doesn't become cluttered with "ghost" lines from previous sessions.
  • Customizable Depth: The user can define how many bars of data the script should analyze (the "NumBar" setting), allowing for a balance between historical depth and chart performance.

In summary, this tool acts as a comprehensive visual map. By displaying multiple "boundary" levels at once, it allows a trader to see not just where the price is moving, but how far it has stretched away from its average—helping to identify when a market might be becoming overbought, oversold, or is following a specific trend.

Indicators Used
Envelopes indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
MA_kanal
//+------------------------------------------------------------------+
//|                                                  Custom MACD.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 8
#property  indicator_color1  Blue
#property  indicator_color2  Black
#property  indicator_color3  DarkGray
#property  indicator_color4  DarkGray
#property  indicator_color5  DarkGray
#property  indicator_color6  DarkGray
#property  indicator_color7  Black
#property  indicator_color8  Red
//---- indicator parameters
extern int Per=55;
extern int NumBar=1000;
//---- indicator buffers
double     Buf1[], Buf2[],Buf3[], Buf4[],Buf5[], Buf6[],Buf7[],Buf8[],ma1,ma2;
int  j=0, n=0;
string  txt[11];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,2);
//   SetIndexDrawBegin(0,draw_begin);
//   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buf1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Buf2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Buf3);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Buf4);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,Buf5);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,Buf6);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,Buf7);
   SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,Buf8);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MA");
   SetIndexLabel(0,"MA");
//---- initialization done
   txt[1]  = "U4";
   txt[2]  = "U3";
   txt[3]  = "U2";
   txt[4]  = "U1";
   txt[5]  = "D1";
   txt[6]  = "D2";
   txt[7]  = "D3";
   txt[8]  = "D4";
   txt[9]  = "LB";

   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() 
{
   ObjectDelete("g1");
   ObjectDelete("g2");
   ObjectDelete("g3");
   ObjectDelete("g4");
   ObjectDelete("g5");
   ObjectDelete("g6");
   ObjectDelete("g7");
   ObjectDelete("g8");
   ObjectDelete("g9");
   
   ObjectDelete("t1");
   ObjectDelete("t2");
   ObjectDelete("t3");
   ObjectDelete("t4");
   ObjectDelete("t5");
   ObjectDelete("t6");
   ObjectDelete("t7");
   ObjectDelete("t8");
   ObjectDelete("t9");

   return(0);
}
//+------------------------------------------------------------------+
int start()
{
  int i;
   if (Minute()<=1)
  {
     ObjectDelete("g1");
   ObjectDelete("g2");
   ObjectDelete("g3");
   ObjectDelete("g4");
   ObjectDelete("g5");
   ObjectDelete("g6");
   ObjectDelete("g7");
   ObjectDelete("g8");
   ObjectDelete("g9");
   
   ObjectDelete("t1");
   ObjectDelete("t2");
   ObjectDelete("t3");
   ObjectDelete("t4");
   ObjectDelete("t5");
   ObjectDelete("t6");
   ObjectDelete("t7");
   ObjectDelete("t8");
   ObjectDelete("t9");
  }
  for (i=0;i<NumBar;i++)
  {
    Buf1[i]=iEnvelopes(NULL, 0, Per,MODE_SMA,0,PRICE_CLOSE,1.38,MODE_UPPER,i);
    Buf2[i]=iEnvelopes(NULL, 0, Per,MODE_SMA,0,PRICE_CLOSE,1,MODE_UPPER,i);
    Buf3[i]=iEnvelopes(NULL, 0, Per,MODE_SMA,0,PRICE_CLOSE,0.62,MODE_UPPER,i);
    Buf4[i]=iEnvelopes(NULL, 0, Per,MODE_SMA,0,PRICE_CLOSE,0.38,MODE_UPPER,i);
    Buf5[i]=iEnvelopes(NULL, 0, Per,MODE_SMA,0,PRICE_CLOSE,0.38,MODE_LOWER,i);
    Buf6[i]=iEnvelopes(NULL, 0, Per,MODE_SMA,0,PRICE_CLOSE,0.62,MODE_LOWER,i);
    Buf7[i]=iEnvelopes(NULL, 0, Per,MODE_SMA,0,PRICE_CLOSE,1,MODE_LOWER,i);
    Buf8[i]=iEnvelopes(NULL, 0, Per,MODE_SMA,0,PRICE_CLOSE,1.38,MODE_LOWER,i);
  }
   if(ObjectFind("g1") == -1) 
   {
           ObjectCreate("g1", OBJ_TREND, 0, Time[0], Buf1[0],Time[0]+(24-TimeHour(Time[0]))*3600, Buf1[0]+(Buf1[0]-Buf1[2])*(20-TimeHour(Time[0])));
           ObjectSet("g1", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g1", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g1", OBJPROP_COLOR, DarkGray);
           ObjectMove("g1", 1, Time[0]+(24-TimeHour(Time[0]))*3600,Buf1[0]+(Buf1[0]-Buf1[2])*(20-TimeHour(Time[0])));
   }
   if(ObjectFind("g2") == -1) 
   {
           ObjectCreate("g2", OBJ_TREND, 0, Time[0], Buf2[0],Time[0]+(24-TimeHour(Time[0]))*3600, Buf2[0]+(Buf2[0]-Buf2[2])*(20-TimeHour(Time[0])));
           ObjectSet("g2", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g2", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g2", OBJPROP_WIDTH, 2);
           ObjectSet("g2", OBJPROP_COLOR, Black);
           ObjectMove("g2", 1, Time[0]+(24-TimeHour(Time[0]))*3600,Buf2[0]+(Buf2[0]-Buf2[2])*(20-TimeHour(Time[0])));
   }
   if(ObjectFind("g3") == -1) 
   {
           ObjectCreate("g3", OBJ_TREND, 0, Time[0], Buf3[0],Time[0]+(24-TimeHour(Time[0]))*3600, Buf3[0]+(Buf3[0]-Buf3[2])*(20-TimeHour(Time[0])));
           ObjectSet("g3", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g3", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g3", OBJPROP_COLOR, DarkGray);
           ObjectMove("g3", 1, Time[0]+(24-TimeHour(Time[0]))*3600,Buf3[0]+(Buf3[0]-Buf3[2])*(20-TimeHour(Time[0])));
   }
   
   if(ObjectFind("g4") == -1) 
   {
           ObjectCreate("g4", OBJ_TREND, 0, Time[0], Buf4[0],Time[0]+(24-TimeHour(Time[0]))*3600, Buf4[0]+(Buf4[0]-Buf4[2])*(20-TimeHour(Time[0])));
           ObjectSet("g4", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g4", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g4", OBJPROP_COLOR, DarkGray);
           ObjectMove("g4", 1, Time[0]+(24-TimeHour(Time[0]))*3600,Buf4[0]+(Buf4[0]-Buf4[2])*(20-TimeHour(Time[0])));
   }
   if(ObjectFind("g5") == -1) 
   {
           ObjectCreate("g5", OBJ_TREND, 0, Time[0], Buf5[0],Time[0]+(24-TimeHour(Time[0]))*3600, Buf5[0]+(Buf5[0]-Buf5[2])*(20-TimeHour(Time[0])));
           ObjectSet("g5", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g5", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g5", OBJPROP_COLOR, DarkGray);
           ObjectMove("g5", 1, Time[0]+(24-TimeHour(Time[0]))*3600,Buf5[0]+(Buf5[0]-Buf5[2])*(20-TimeHour(Time[0])));
   }
   if(ObjectFind("g6") == -1) 
   {
           ObjectCreate("g6", OBJ_TREND, 0, Time[0], Buf6[0],Time[0]+(24-TimeHour(Time[0]))*3600, Buf6[0]+(Buf6[0]-Buf6[2])*(20-TimeHour(Time[0])));
           ObjectSet("g6", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g6", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g6", OBJPROP_COLOR, DarkGray);
           ObjectMove("g6", 1, Time[0]+(24-TimeHour(Time[0]))*3600,Buf6[0]+(Buf6[0]-Buf6[2])*(20-TimeHour(Time[0])));
   }
   if(ObjectFind("g7") == -1) 
   {
           ObjectCreate("g7", OBJ_TREND, 0, Time[0], Buf7[0],Time[0]+(24-TimeHour(Time[0]))*3600, Buf7[0]+(Buf7[0]-Buf7[2])*(20-TimeHour(Time[0])));
           ObjectSet("g7", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g7", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g7", OBJPROP_WIDTH, 2);
           ObjectSet("g7", OBJPROP_COLOR, Black);
           ObjectMove("g7", 1, Time[0]+(24-TimeHour(Time[0]))*3600,Buf7[0]+(Buf7[0]-Buf7[2])*(20-TimeHour(Time[0])));
   }
   if(ObjectFind("g8") == -1) 
   {
           ObjectCreate("g8", OBJ_TREND, 0, Time[0], Buf8[0],Time[0]+(24-TimeHour(Time[0]))*3600, Buf8[0]+(Buf8[0]-Buf8[2])*(20-TimeHour(Time[0])));
           ObjectSet("g8", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g8", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g8", OBJPROP_COLOR, DarkGray);
           ObjectMove("g8", 1, Time[0]+(24-TimeHour(Time[0]))*3600,Buf8[0]+(Buf8[0]-Buf8[2])*(20-TimeHour(Time[0])));
   }
   if(ObjectFind("g9") == -1) 
   {
      ma1=iMA(NULL,0,55,0,MODE_SMA,PRICE_CLOSE,0);
      ma2=iMA(NULL,0,55,0,MODE_SMA,PRICE_CLOSE,2);
           ObjectCreate("g9", OBJ_TREND, 0, Time[0], ma1,Time[0]+(24-TimeHour(Time[0]))*3600, ma1+(ma1-ma2)*(20-TimeHour(Time[0])));
           ObjectSet("g9", OBJPROP_RAY, DRAW_LINE);
           ObjectSet("g9", OBJPROP_STYLE, STYLE_SOLID);
           ObjectSet("g9", OBJPROP_WIDTH, 2);
           ObjectSet("g9", OBJPROP_COLOR, Teal);
           ObjectMove("g9", 1, Time[0]+(24-TimeHour(Time[0]))*3600,ma1+(ma1-ma2)*(20-TimeHour(Time[0])));
   }
   if(ObjectFind("t1") == -1) 
   {
           ObjectCreate("t1", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, Buf1[0]+(Buf1[0]-Buf1[2])*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t1", txt[1], 8, "Arial", Black);
           ObjectMove("t1", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  Buf1[0]+(Buf1[0]-Buf1[2])*(20-TimeHour(Time[0]))+7*Point);
   }
   if(ObjectFind("t2") == -1) 
   {
           ObjectCreate("t2", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, Buf2[0]+(Buf2[0]-Buf2[2])*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t2", txt[2], 8, "Arial", Black);
           ObjectMove("t2", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  Buf2[0]+(Buf2[0]-Buf2[2])*(20-TimeHour(Time[0]))+7*Point);
   }
   if(ObjectFind("t3") == -1) 
   {
           ObjectCreate("t3", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, Buf3[0]+(Buf3[0]-Buf3[2])*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t3", txt[3], 8, "Arial", Black);
           ObjectMove("t3", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  Buf3[0]+(Buf3[0]-Buf3[2])*(20-TimeHour(Time[0]))+7*Point);
   }
   if(ObjectFind("t4") == -1) 
   {
           ObjectCreate("t4", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, Buf4[0]+(Buf4[0]-Buf4[2])*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t4", txt[4], 8, "Arial", Black);
           ObjectMove("t4", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  Buf4[0]+(Buf4[0]-Buf4[2])*(20-TimeHour(Time[0]))+7*Point);
   }
   if(ObjectFind("t5") == -1) 
   {
           ObjectCreate("t5", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, Buf5[0]+(Buf5[0]-Buf5[2])*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t5", txt[5], 8, "Arial", Black);
           ObjectMove("t5", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  Buf5[0]+(Buf5[0]-Buf5[2])*(20-TimeHour(Time[0]))+7*Point);
   }
   if(ObjectFind("t6") == -1) 
   {
           ObjectCreate("t6", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, Buf6[0]+(Buf6[0]-Buf6[2])*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t6", txt[6], 8, "Arial", Black);
           ObjectMove("t6", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  Buf6[0]+(Buf6[0]-Buf6[2])*(20-TimeHour(Time[0]))+7*Point);
   }
   if(ObjectFind("t7") == -1) 
   {
           ObjectCreate("t7", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, Buf7[0]+(Buf7[0]-Buf7[2])*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t7", txt[7], 8, "Arial", Black);
           ObjectMove("t7", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  Buf7[0]+(Buf7[0]-Buf7[2])*(20-TimeHour(Time[0]))+7*Point);
   }
   if(ObjectFind("t8") == -1) 
   {
           ObjectCreate("t8", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, Buf8[0]+(Buf8[0]-Buf8[2])*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t8", txt[8], 8, "Arial", Black);
           ObjectMove("t8", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  Buf8[0]+(Buf8[0]-Buf8[2])*(20-TimeHour(Time[0]))+7*Point);
   }
   if(ObjectFind("t9") == -1) 
   {
            ma1=iMA(NULL,0,55,0,MODE_SMA,PRICE_CLOSE,0);
            ma2=iMA(NULL,0,55,0,MODE_SMA,PRICE_CLOSE,2);
           ObjectCreate("t9", OBJ_TEXT, 0, Time[0]+(27-TimeHour(Time[0]))*3600, ma1+(ma1-ma2)*(20-TimeHour(Time[0]))+7*Point);
           ObjectSetText("t9", txt[9], 8, "Arial", Black);
           ObjectMove("t9", 0, Time[0]+(27-TimeHour(Time[0]))*3600,  ma1+(ma1-ma2)*(20-TimeHour(Time[0]))+7*Point);
   }

}


Comments