#MFT_Trendenvelopes_v2

The script you've provided is designed to display trend envelopes on your chart, but with a twist: it uses data from a higher timeframe than the one you're currently viewing. Think of it like looking at the forest (the larger timeframe) to understand the trees (your current chart).

Here's how it works:

  1. Setup: The script first sets up two lines, a Magenta line labeled "Up" and an Aqua line labeled "Dn", which will be drawn on your chart. These lines represent the upper and lower bounds of the trend.

  2. Timeframe Selection: A key setting is the "TimeFrame" which is set to 1440 minutes. This setting determines the timeframe from which the trend envelopes will be calculated. 1440 minutes equates to a daily timeframe (24 hours * 60 minutes). So the underlying TrendEnvelopes indicator is calculated on a daily timeframe.

  3. Data Synchronization: The script then compares the time of each bar on your current chart with the time of each bar on the chosen higher timeframe (daily in this case). It figures out which daily bar corresponds to each bar on your current chart. It is important to note here that the script is using TrendEnvelopes_v2 to obtain values on the bigger timeframe.

  4. Trend Envelope Calculation: For each bar on your chart, the script retrieves the values of the "Up" and "Dn" lines from another indicator called "TrendEnvelopes_v2" (which you must have installed) that has been calculated on the higher timeframe.

  5. Display: Finally, the script draws the "Up" and "Dn" lines on your current chart, using the values it retrieved from the "TrendEnvelopes_v2" indicator running on the higher timeframe.

In essence, this script overlays the trend envelopes calculated from a higher timeframe onto your current chart, allowing you to see a broader trend perspective without having to switch to that higher timeframe directly. The "TrendEnvelopes_v2" indicator is calculating what's considered the upper and lower values of the trend on the larger timeframe, and this script shows those values as lines on your current chart.

Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
#MFT_Trendenvelopes_v2
//+------------------------------------------------------------------+
//|                            MTF_TrendEnvelopes_v2.mq4 
//| by Zathar
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Aqua
#property indicator_width1 2
#property indicator_width2 2

extern int TimeFrame=1440;
double ExtMapBuffer1[];
double ExtMapBuffer2[];


int init()
  {
   //---- indicator line
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_LINE);   
   IndicatorShortName("MTF_Trendenvelopes_v2(14)");
   SetIndexLabel(0,"Up");
   SetIndexLabel(1,"Dn");
  }
//----
   return(0);
 

int start()
  {
   datetime TimeArray[];
   int    i,shift,limit,y=0,counted_bars=IndicatorCounted();
     
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   
   limit=Bars-counted_bars;
   for(i=0,y=0;i<limit;i++) {
     if (Time[i]<TimeArray[y]) {y++;}   
     ExtMapBuffer1[i]=iCustom(NULL,TimeFrame,"TrendEnvelopes_v2",1,y); 
     ExtMapBuffer2[i]=iCustom(NULL,TimeFrame,"TrendEnvelopes_v2",0,y);
   }
   return(0);
  }

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---