This script is designed to display a "corridor" on a price chart. Think of it as drawing two lines that try to capture the recent high and low price movements.
Here's a breakdown of how it works:
-
Initialization: When the script starts, it sets up the visual aspects of the corridor. It defines two lines (the upper and lower boundaries of the corridor) and gives them a black color. It also prepares the script to handle price data efficiently.
-
Configuration: The script allows you to specify a "period" - essentially, how many past price bars to consider when calculating the corridor's boundaries. The default is set to 12. This setting influences how wide or narrow the corridor will be. A larger number will likely produce a wider corridor.
-
Data Processing: The core of the script calculates the upper and lower boundaries of the corridor for each price bar on the chart.
-
Upper Boundary: For each bar, the script looks back at the past "period" number of bars (as defined in configuration) and finds the highest price during that period. That highest price becomes the value for the upper line of the corridor at that bar's position.
-
Lower Boundary: Similarly, it finds the lowest price during the past "period" number of bars. This lowest price becomes the value for the lower line of the corridor at that bar's position.
-
-
Drawing the Corridor: The script takes the high and low values it found and draws the two lines on the price chart connecting each value. This visual representation is the corridor. This draws a zone around the current price based on recent highest and lowest prices.
//+---------------------------------------------------------------------+
//| Corridor.mq4 |
//| Copyright © Trofimov 2009 |
//+---------------------------------------------------------------------+
//| Êîðèäîð |
//| |
//| Àâòîðñêîå ïðàâî ïðèíàäëåæèò Òðîôèìîâó Åâãåíèþ Âèòàëüåâè÷ó, 2009 |
//+---------------------------------------------------------------------+
#property copyright "Copyright © Trofimov Evgeniy Vitalyevich, 2009"
#property link "http://TrofimovVBA.narod.ru/"
//---- Ñâîéñòâà èíäèêàòîðà
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Black
#property indicator_width1 1
#property indicator_color2 Black
#property indicator_width2 1
//---- Âõîäÿùèå ïàðàìåòðû
extern int MyPeriod=12;
double Buff_line1[];
double Buff_line2[];
string Shortname;
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè èíäèêàòîðà |
//+------------------------------------------------------------------+
int init() {
IndicatorBuffers(2);
IndicatorDigits(Digits);
//---- ïàðàìåòðû ðèñîâàíèÿ (óñòàíîâêà íà÷àëüíîãî áàðà)
SetIndexDrawBegin(0,MyPeriod);
//---- x ðàñïðåäåëåííûõ áóôåðà èíäèêàòîðà
SetIndexBuffer(0,Buff_line1);
SetIndexLabel(0,"UpCorridor");
SetIndexBuffer(1,Buff_line2);
SetIndexLabel(1,"DnCorridor");
//---- èìÿ èíäèêàòîðà è ïîäñêàçêè äëÿ ëèíèé
Shortname="Corridor("+MyPeriod+")";
IndicatorShortName(Shortname);
return(0);
}
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíäèêàòîðà |
//+------------------------------------------------------------------+
int start() {
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
limit=Bars-counted_bars-1;
//---- îñíîâíûå ïåðåìåííûå
double B, Hbid, Lbid;
//---- îñíîâíîé öèêë
for(int t=limit; t>0; t--) {
Buff_line1[t]=High[iHighest(NULL,0,MODE_HIGH,MyPeriod,t)];
Buff_line2[t]= Low[iLowest (NULL,0,MODE_LOW, MyPeriod,t)];
if(t==1) {
Buff_line1[0]=Buff_line1[1];
Buff_line2[0]=Buff_line2[1];
}
}//Next t
return(0);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---