- //+------------------------------------------------------------------+
- //| DRAW_ARROW.mq5 |
- //| Copyright 2011, MetaQuotes Software Corp. |
- //| https://www.mql5.com |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2011, MetaQuotes Software Corp."
- #property link "https://www.mql5.com"
- #property version "1.00"
- #property description "An indicator to demonstrate DRAW_ARROW"
- #property description "Draws arrows set by Unicode characters, on a chart"
- #property description "The color, size, shift and symbol code of the arrow are changed in a random way"
- #property description "after every N ticks"
- #property description "The code parameter sets the base value: code=159 (a circle)"
- #property indicator_chart_window
- #property indicator_buffers 1
- #property indicator_plots 1
- //--- plot Arrows
- #property indicator_label1 "Arrows"
- #property indicator_type1 DRAW_ARROW
- #property indicator_color1 clrGreen
- #property indicator_width1 1
- //--- input parameters
- input int N=5; // Number of ticks to change
- input ushort code=169; // Symbol code to draw in DRAW_ARROW
- //--- An indicator buffer for the plot
- double ArrowsBuffer[];
- int PivotPointBuffer[];
- //--- An array to store colors
- color colors[]={clrRed,clrBlue,clrGreen};
- int high_handle;
- int low_handle;
- input int length = 5;
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //--- indicator buffers mapping
- SetIndexBuffer(0,ArrowsBuffer,INDICATOR_DATA);
- SetIndexBuffer(0,PivotPointBuffer,INDICATOR_CALCULATIONS);
- //--- Define the symbol code for drawing in PLOT_ARROW
- PlotIndexSetInteger(0,PLOT_ARROW,code);
- //--- Set the vertical shift of arrows in pixels
- PlotIndexSetInteger(0,PLOT_ARROW_SHIFT, 0);
- //--- Set as an empty value 0
- PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
- PlotIndexSetInteger(0,PLOT_LINE_WIDTH, 3);
- //---
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| 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[])
- {
- for(int i=1;i<rates_total;i++)
- {
- //if(ArrayMaximum(high, i - 5, 10) == high[i])
- int highestValueIndex = ArrayMaximum(high, i-5, 10);
- int lowestValueIndex = ArrayMinimum(low, i-5, 10);
- if (highestValueIndex != -1 && high[highestValueIndex] == high[i]) {
- ArrowsBuffer[i]=high[i] + Point()*100;
- PivotPointBuffer[i] = 1;
- } else if (highestValueIndex != -1 && low[lowestValueIndex] == low[i]) {
- ArrowsBuffer[i]=low[i] - Point()*100;
- PivotPointBuffer[i] = -1;
- }
- else {
- ArrowsBuffer[i]=0;
- PivotPointBuffer[i] = 0;
- }
- }
- return(rates_total);
- }