Facebook
From Bistre Iguana, 7 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 86
  1. //+------------------------------------------------------------------+
  2. //|                                                   DRAW_ARROW.mq5 |
  3. //|                        Copyright 2011, MetaQuotes Software Corp. |
  4. //|                                              https://www.mql5.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2011, MetaQuotes Software Corp."
  7. #property link      "https://www.mql5.com"
  8. #property version   "1.00"
  9.  
  10. #property description "An indicator to demonstrate DRAW_ARROW"
  11. #property description "Draws arrows set by Unicode characters, on a chart"
  12. #property description "The color, size, shift and symbol code of the arrow are changed in a random way"
  13. #property description "after every N ticks"
  14. #property description "The code parameter sets the base value: code=159 (a circle)"
  15.  
  16. #property indicator_chart_window
  17. #property indicator_buffers 1
  18. #property indicator_plots   1
  19. //--- plot Arrows
  20. #property indicator_label1  "Arrows"
  21. #property indicator_type1   DRAW_ARROW
  22. #property indicator_color1  clrGreen
  23. #property indicator_width1  1
  24. //--- input parameters
  25. input int      N=5;         // Number of ticks to change  
  26. input ushort   code=169;    // Symbol code to draw in DRAW_ARROW
  27. //--- An indicator buffer for the plot
  28. double         ArrowsBuffer[];
  29. int         PivotPointBuffer[];
  30. //--- An array to store colors
  31. color colors[]={clrRed,clrBlue,clrGreen};
  32. int high_handle;
  33. int low_handle;
  34. input int length = 5;
  35. //+------------------------------------------------------------------+
  36. //| Custom indicator initialization function                         |
  37. //+------------------------------------------------------------------+
  38. int OnInit()
  39.   {
  40. //--- indicator buffers mapping
  41.    SetIndexBuffer(0,ArrowsBuffer,INDICATOR_DATA);
  42.    SetIndexBuffer(0,PivotPointBuffer,INDICATOR_CALCULATIONS);
  43. //--- Define the symbol code for drawing in PLOT_ARROW
  44.    PlotIndexSetInteger(0,PLOT_ARROW,code);
  45. //--- Set the vertical shift of arrows in pixels
  46.    PlotIndexSetInteger(0,PLOT_ARROW_SHIFT, 0);
  47. //--- Set as an empty value 0
  48.    PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
  49.    
  50.    PlotIndexSetInteger(0,PLOT_LINE_WIDTH, 3);
  51. //---
  52.    return(INIT_SUCCEEDED);
  53.   }
  54. //+------------------------------------------------------------------+
  55. //| Custom indicator iteration function                              |
  56. //+------------------------------------------------------------------+
  57.  
  58. int OnCalculate(const int rates_total,
  59.                 const int prev_calculated,
  60.                 const datetime &time[],
  61.                 const double &open[],
  62.                 const double &high[],
  63.                 const double &low[],
  64.                 const double &close[],
  65.                 const long &tick_volume[],
  66.                 const long &volume[],
  67.                 const int &spread[])
  68.   {
  69.    for(int i=1;i<rates_total;i++)
  70.      {
  71.       //if(ArrayMaximum(high, i - 5, 10) == high[i])
  72.       int highestValueIndex = ArrayMaximum(high, i-5, 10);
  73.       int lowestValueIndex = ArrayMinimum(low, i-5, 10);
  74.       if (highestValueIndex != -1 && high[highestValueIndex] == high[i]) {
  75.          ArrowsBuffer[i]=high[i] + Point()*100;
  76.          PivotPointBuffer[i] = 1;
  77.       } else if (highestValueIndex != -1 && low[lowestValueIndex] == low[i]) {
  78.          ArrowsBuffer[i]=low[i] - Point()*100;
  79.          PivotPointBuffer[i] = -1;
  80.       }
  81.       else {
  82.          ArrowsBuffer[i]=0;
  83.          PivotPointBuffer[i] = 0;
  84.       }
  85.      }
  86.    return(rates_total);
  87.   }