有您的持续关注
我们会做得更好

整数位置网格指标Grid10



整数位置网格指标Grid10实现在各个整数价格位置画线。

Grid10指标图表效果如下:整数网格指标

Grid10指标源码如下:

//+------------------------------------------------------------------+
//|                                                       Grid10.mq4 |
//|                                     Copyright 2016, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"

#property indicator_chart_window

//---- input parameters

//---- data
int gridCt;
string sGrid = "GridLine";

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   string sGridLine;

   for(int gridNo=0; gridNo < gridCt; gridNo++)
   {
      sGridLine = sGrid + CharToStr('0' + gridNo);
      ObjectDelete(sGridLine);
   }
   
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   double hiBarHi, loBarLo;
   int    hiBar, loBar;
   string sGridLine;
   double gridRes = 0.0100;
   double gridPos, startPos;
   double range;
   static double prevRange;
   int numBars, firstBar;
   static int prevNumBars;
   
   // calculate the number of bars displayed on the chart
   numBars = WindowBarsPerChart();
   firstBar = WindowFirstVisibleBar() - numBars;
   if(firstBar < 0)
   {
      firstBar = 0;
   }
   if(firstBar + numBars > WindowFirstVisibleBar())
   {
      numBars = WindowFirstVisibleBar() - firstBar;
   }
   
   // calculate the high - low range of the chart
   hiBar = iHighest(NULL, 0, MODE_HIGH, numBars, firstBar);
   hiBarHi = High[hiBar];
   
   loBar = iLowest(NULL, 0, MODE_LOW, numBars, firstBar);
   loBarLo = Low[loBar];

   range = hiBarHi - loBarLo;

   // need only draw the grid if the high - low range has changed
   // or the number of bars displayed has changed (ie. the chart has been resized)
   if((prevRange != range) || (prevNumBars != numBars))
   {
      deinit();
      prevRange = range;
      prevNumBars = numBars;
   
      // select a grid resolution based on the range of the chart
      if(range > 10000.0)
         gridRes = 10000.0;
      else if (range > 1000.0)
         gridRes = 1000.0;
      else if(range > 100.0)
         gridRes = 100.0;
      else if(range > 10.0)
         gridRes = 10.0;
      else if(range > 1.0)
         gridRes = 1.0;
      else if (range > 0.1000)
         gridRes = 0.1000;
      else
         gridRes = 0.0100;
      
      
      // draw the grid lines to encompass the full range of the chart
      startPos = loBarLo - gridRes;
      gridPos = startPos - MathMod(startPos, gridRes);
      gridCt = 0;
      while(gridPos < hiBarHi + gridRes)
      {
         sGridLine = sGrid + CharToStr('0' + gridCt);
         ObjectCreate(sGridLine, OBJ_HLINE, 0, 0, gridPos);
         ObjectSet(sGridLine, OBJPROP_COLOR, Salmon);
         ObjectSet(sGridLine, OBJPROP_STYLE, STYLE_DOT);
      
         gridPos += gridRes;
         gridCt++;
      }   
   
      //---- force objects drawing
      ObjectsRedraw();

   }
   
   return(0);
}
//+------------------------------------------------------------------+

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 整数位置网格指标Grid10
上一篇:
下一篇:
分享到:更多 ()