Indicators Used
0
Views
0
Downloads
0
Favorites
DRAW_FILLING
//+------------------------------------------------------------------+
//| DRAW_FILLING.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property description "This indicator is a demo of DRAW_FILLING drawing style"
#property description "It plots a channel based on two moving averages in the separate window"
#property description "The channel color changed randomly each N ticks"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
//--- plot Intersection
#property indicator_label1 "Intersection"
#property indicator_type1 DRAW_FILLING
#property indicator_color1 clrRed,clrBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int Fast=13; // Period of fast moving average
input int Slow=21; // Period of slow moving average
input int shift=1; // Bars shift (positive)
input int N=5; // Ticks to change properties
//--- indicator buffers
double IntersectionBuffer1[];
double IntersectionBuffer2[];
int fast_handle;
int slow_handle;
//--- colors array
color colors[]={clrRed,clrBlue,clrGreen,clrAquamarine,clrBlanchedAlmond,clrBrown,clrCoral,clrDarkSlateGray};
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,IntersectionBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,IntersectionBuffer2,INDICATOR_DATA);
//---
PlotIndexSetInteger(0,PLOT_SHIFT,shift);
//---
fast_handle=iMA(_Symbol,_Period,Fast,0,MODE_SMA,PRICE_CLOSE);
slow_handle=iMA(_Symbol,_Period,Slow,0,MODE_SMA,PRICE_CLOSE);
//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
static int ticks=0;
//--- count the ticks
ticks++;
//--- if ticks>=N
if(ticks>=N)
{
//--- change channel properties
ChangeLineAppearance();
//--- set ticks counter to 0
ticks=0;
}
//--- first call case
if(prev_calculated==0)
{
//--- copy all the indicator values to the buffers
int copied1=CopyBuffer(fast_handle,0,0,rates_total,IntersectionBuffer1);
int copied2=CopyBuffer(slow_handle,0,0,rates_total,IntersectionBuffer2);
}
else // else copy only updated values
{
//--- bars to copy
int to_copy=rates_total-prev_calculated;
//--- if to_copy=0, update the current (incompleted bar)
if(to_copy==0) to_copy=1;
//--- copy the values
int copied1=CopyBuffer(fast_handle,0,0,to_copy,IntersectionBuffer1);
int copied2=CopyBuffer(slow_handle,0,0,to_copy,IntersectionBuffer2);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Changes the color of channel |
//+------------------------------------------------------------------+
void ChangeLineAppearance()
{
//--- comment
string comm="";
//--- fist color
int number=MathRand(); // get random number
//--- get size
int size=ArraySize(colors);
//--- select color
int color_index1=number%size;
//--- set the first color as PLOT_LINE_COLOR property
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colors[color_index1]);
//--- add to comment
comm=comm+"\r\nColor1 "+(string)colors[color_index1];
//--- second color
number=MathRand(); // get random number
int color_index2=number%size;
//--- set the second color as PLOT_LINE_COLOR property
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,colors[color_index2]);
//--- add to comment
comm=comm+"\r\nColor2 "+(string)colors[color_index2];
//--- show comment on the chart
Comment(comm);
}
//+------------------------------------------------------------------+
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
---