诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

MT4区间画线指标 HiLo Lines.mq4

HiLo Lines指标自动绘制临近的高低点直线,为交易提供区间或突破参考。

图表:HiLo Lines指标

源码:

//+------------------------------------------------------------------+
//|                                                   HiLo Lines.mq4 |
//+------------------------------------------------------------------+
#property copyright "TradeForex"
#property link      "http://www.125808047.com/"

#property indicator_chart_window

extern int Lookback_Period = 15;
extern int Buy_At_Low_Plus = 20;
extern int Sell_At_High_Minus = 20;

extern bool ViewComment = true;
double period_Low=0;
double period_High=0;
double Period_Low_Line;
double Period_High_Line;
double Buy_Line=0;
double Sell_Line=0;
double BuyAt = 0;
double SellAt =0;
double HighAt = 0;
double LowAt =0;
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
   void OnDeinit(const int reason)
   {
   ObjectDelete("BuyAt Label"); 
   ObjectDelete("BuyAt Line");
   ObjectDelete("SellAt Label");
   ObjectDelete("SellAt Line");
   Comment("www.125808047.com");
   }
//+------------------------------------------------------------------+
//| 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[])
  {
        period_High =High[iHighest(NULL,0,MODE_HIGH,Lookback_Period,1)];
         period_Low =Low[iLowest(NULL,0,MODE_LOW,Lookback_Period,1)];
        Period_Low_Line =  (period_Low );
        Period_High_Line =  (period_High );
         Buy_Line =  (period_Low + Buy_At_Low_Plus * Point );
         Sell_Line =  (period_High - Sell_At_High_Minus * Point );
   
   if (ViewComment==true){

   Comment("Buy at break of = ",Buy_Line, "  Sell at break of =  ",Sell_Line);
      }
   {
      SetLevel("High Line", Period_High_Line, Blue); //Blue
      SetLevel("Low Line", Period_Low_Line, Blue); //Blue
      
      SetLevel("LOW Plus Buy line", Buy_Line, Green); //Green
      SetLevel("HIGH Minus Sell line", Sell_Line, Yellow); //Red
   }
   return(rates_total);
}
//+------------------------------------------------------------------+
//| Helper                                                           |
//+------------------------------------------------------------------+
void SetLevel(string text, double level, color col1)
{
   string labelname= text + " Label";
   string linename= text + " Line";

   if (ObjectFind(labelname) != 0) {
      ObjectCreate(labelname, OBJ_TEXT, 0, Time[20], level);
      ObjectSetText(labelname, " " + text, 8, "Arial", White);
   }
   else {
      ObjectMove(labelname, 0, Time[20], level);
   }
   
   if (ObjectFind(linename) != 0) {
      ObjectCreate(linename, OBJ_HLINE, 0, Time[40], level);
      ObjectSet(linename, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(linename,OBJPROP_LEVELWIDTH, 5);
      ObjectSet(linename, OBJPROP_COLOR, col1);
      
      }
   else {
      ObjectMove(linename, 0, Time[40], level);
      
   }
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » MT4区间画线指标 HiLo Lines.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏