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

HiLo_Activator_Profi.mq4 指标创建止损及突破参考水平

HiLo_Activator_Profi 指标根据价格高低点特定算法创建止损及突破参考水平。

图表:HiLo_Activator_Profi 指标

源码:

//+------------------------------------------------------------------+
//|                                         HiLo_Activator_Profi.mq4 |
//|                                                 Copyright @2005, |
//+------------------------------------------------------------------+
#property copyright "Copyright @2005"
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Black

extern int       Range=3;

double Up[];
double Dn[];
double ur1[];
double ur2[];
double h1[];
double l1[];

int cb;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
   IndicatorBuffers(6);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexArrow(1,159);
   SetIndexBuffer(0,Up);
   SetIndexBuffer(1,Dn);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexLabel(0,"HL_Act_Up");
   SetIndexLabel(1,"HL_Act_Dn");
   
   SetIndexBuffer(2,ur1);
   SetIndexBuffer(3,ur2);
   SetIndexBuffer(4,h1);
   SetIndexBuffer(5,l1);
   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[])
  {
   int counted_bars=IndicatorCounted();
   int NumBars=1000, n=0, Nbar=0, k=0, hh=0, ll=0, mm=0;
   double MaH=0.0, MaL=0.0;

if(Bars<Range*12-10) return(0);
if(counted_bars>=Bars-1)
{
   NumBars=0;
}
else
{
   NumBars=MathMax(Bars-1-counted_bars-(Range*12-10),Range*12-10);
}

for( cb=NumBars; cb>=0; cb--)
{
   Nbar=-1;
   k=1;
   mm=0;
   Dn[cb]=0.0;
   Up[cb]=0.0;
   ur1[cb]=0.0;
   ur2[cb]=0.0;
   h1[cb]=0.0;
   l1[cb]=0.0;
//-----------------------------------------------------------------------------
   if( Period()==5 ) 
   {
      if( TimeHour(Time[cb+1])!=TimeHour(Time[cb]) )
      {
         n=cb-15;
         while( n<=cb+Range*12+5 )
         {
            if( n<0 )
            {
               Nbar=0;
               n=1;
            }
            if( TimeHour(Time[n+1])!=TimeHour(Time[n]) )
            {
               if( Nbar==-1 )
               {
               	Nbar=n;
               	mm=n;
               	n++;
               	continue;
               }
               else
               {
               	h1[k]=High[Highest(NULL,0,MODE_HIGH,(n-Nbar),n)];
               	l1[k]=Low[Lowest(NULL,0,MODE_LOW,(n-Nbar),n)];
               	k++;
               	Nbar=n;
               }
            }
            n++;
         }
         MaH=0;
         MaL=0;
         for( n=1;n<=Range;n++)
         {
            MaH=MaH+h1[n];
            MaL=MaL+l1[n];
         }
         MaH=MaH/Range;
         MaL=MaL/Range;
         ur1[cb]=MaH;
         ur2[cb]=MaL;
         if( Close[mm+1]>=MaH )
         {
            ll=1;
            hh=0;
         }
         if( Close[mm+1]<=MaL )
         {
            hh=1;
            ll=0;
         }
      }
      if( ur1[cb]==0.0 )
      {
         ur1[cb]=ur1[cb+1];
         ur2[cb]=ur2[cb+1];
      }
      if( ll==1 )
      {
         Up[cb]=ur2[cb];
      }
      else
      {
      	if( hh==1 )
      	{
         	Dn[cb]=ur1[cb];
      	}
      	else
      	{
            Dn[cb]=Dn[cb+1];
            Up[cb]=Up[cb+1];
      	}
      }   
   }
   else {
//-----------------------------------------------------------------------------

   if( Period()==15 )
   {
      if( TimeHour(Time[cb+1])!=TimeHour(Time[cb]) ) 
      {
         n=cb-5;
         while( n<=cb+Range*4+2 )
         {
            if( n<0 )
            {
               Nbar=0;
               n=1;
            }
            if( TimeHour(Time[n+1])!=TimeHour(Time[n]) )
            {
				if( Nbar==-1 ) 
               {
                  Nbar=n;
               	mm=n;
               	n++;
               	continue;
               }
            	else
               {
                  h1[k]=High[iHighest(NULL,0,MODE_HIGH,(n-Nbar),n)];
               	l1[k]=Low[iLowest(NULL,0,MODE_LOW,(n-Nbar),n)];
               	k++;
               	Nbar=n;
               }
         	}
            n++;
         }
         MaH=0;
         MaL=0;
         for( n=1;n<=Range;n++ )
         {
            MaH=MaH+h1[n];
            MaL=MaL+l1[n];
         }
         MaH=MaH/Range;
         MaL=MaL/Range;
         ur1[cb]=MaH;
         ur2[cb]=MaL;
         if( Close[mm+1]>=MaH )
         {
            ll=1;
            hh=0;
         }
         if( Close[mm+1]<=MaL )
         {
            hh=1;
            ll=0;
         }
      }
      if( ur1[cb]==0.0 )
      {
         ur1[cb]=ur1[cb+1];
         ur2[cb]=ur2[cb+1];
      }
      if( ll==1 )
      {
         Up[cb]=ur2[cb];
      }
      else
      {
      	if( hh==1 )
      	{
         	Dn[cb]=ur1[cb];
      	}
	  }
   }
   else {
//-----------------------------------------------------------------------------

   if( Period()==30 ) 
   {
      if( (TimeMinute(Time[cb])==0 && (TimeHour(Time[cb])==0 || TimeHour(Time[cb])==4 || TimeHour(Time[cb])==8 || 
           TimeHour(Time[cb])==12 || TimeHour(Time[cb])==16 || TimeHour(Time[cb])==20)) )
      {
         n=cb-10;
         while( n<=cb+Range*8+5 )
         {
            if( n<0 )
            {
               Nbar=0;
               n=1;
            }
            if( (TimeMinute(Time[n])==0 && (TimeHour(Time[n])==0 || TimeHour(Time[n])==4 || TimeHour(Time[n])==8 ||
			        TimeHour(Time[n])==12 || TimeHour(Time[n])==16 || TimeHour(Time[n])==20)) )
            {
				  if( Nbar==-1 )
              {
                  Nbar=n;
                  mm=n;
                  n++;
                  continue;
              }
              else
              {
                  h1[k]=High[Highest(NULL,0,MODE_HIGH,(n-Nbar),n)];
                  l1[k]=Low[Lowest(NULL,0,MODE_LOW,(n-Nbar),n)];
                  k++;
                  Nbar=n;
              }
            }
            n++;
         }
         MaH=0;
         MaL=0;
         for( n=1;n<=Range;n++ )
         {
            MaH=MaH+h1[n];
            MaL=MaL+l1[n];
         }
         MaH=MaH/Range;
         MaL=MaL/Range;
         ur1[cb]=MaH;
         ur2[cb]=MaL;
         if( Close[mm+1]>=MaH )
         {
            ll=1;
            hh=0;
         }
         if( Close[mm+1]<=MaL )
         {
            hh=1;
            ll=0;
         }
      }
      if( ur1[cb]==0 )
      {
         ur1[cb]=ur1[cb+1];
         ur2[cb]=ur2[cb+1];
      }
      if( ll==1 )
      {
         Up[cb]=ur2[cb];
      }
      else
      {
      	if( hh==1 )
      	{
         	Dn[cb]=ur1[cb];
      	}
	  }
   }
   else {
//-----------------------------------------------------------------------------

   if( Period()==60 ) 
      {
      if( (TimeMinute(Time[cb])==0 && (TimeHour(Time[cb])==0 || TimeHour(Time[cb])==4 || TimeHour(Time[cb])==8 || 
           TimeHour(Time[cb])==12 || TimeHour(Time[cb])==16 || TimeHour(Time[cb])==20)) )
      {
         n=cb-6;
         while( n<=cb+Range*4+3 )
         {
            if( n<0 )
            {
               Nbar=0;
               n=1;
            }
			   if( (TimeMinute(Time[n])==0 && (TimeHour(Time[n])==0 || TimeHour(Time[n])==4 || TimeHour(Time[n])==8 ||
   			     TimeHour(Time[n])==12 || TimeHour(Time[n])==16 || TimeHour(Time[n])==20)) ) 
	     		{
               if( Nbar==-1 )
               {
                  Nbar=n;
                  mm=n;
                  n++;
                  continue;
               }
				  else
               {
                  h1[k]=High[Highest(NULL,0,MODE_HIGH,(n-Nbar),n)];
                  l1[k]=Low[Lowest(NULL,0,MODE_LOW,(n-Nbar),n)];
                  k++;
                  Nbar=n;
               }
            }
            n++;
         }
         MaH=0;
         MaL=0;
         for( n=1;n<=Range;n++ )
         {
            MaH=MaH+h1[n];
            MaL=MaL+l1[n];
         }
         MaH=MaH/Range;
         MaL=MaL/Range;
         ur1[cb]=MaH;
         ur2[cb]=MaL;
         if( Close[mm+1]>=MaH )
         {
            ll=1;
            hh=0;
         }
         if( Close[mm+1]<=MaL )
         {
            hh=1;
            ll=0;
         }
      }
      if( ur1[cb]==0 )
      {
         ur1[cb]=ur1[cb+1];
         ur2[cb]=ur2[cb+1];
      }
      if( ll==1 )
      {
         Up[cb]=ur2[cb];
      }
      else
      {
      	if( hh==1 )
      	{
         	Dn[cb]=ur1[cb];
      	}
	  }
   }
   else {
//-----------------------------------------------------------------------------

   if( Period()==240 ) 
      {
      if( TimeDay(Time[cb+1])!=TimeDay(Time[cb]) )
      {
         n=cb-8;
         while( n<=cb+Range*8+4 )
         {
            if( n<0 )
            {
               Nbar=0;
               n=1;
            }
            if( TimeDay(Time[n+1])!=TimeDay(Time[n]) )
            {
               if( Nbar==-1 )
               {
                  Nbar=n;
                  mm=n;
                  n++;
                  continue;
               }
            	else
               {
                  h1[k]=High[Highest(NULL,0,MODE_HIGH,(n-Nbar),n)];
                  l1[k]=Low[Lowest(NULL,0,MODE_LOW,(n-Nbar),n)];
                  k++;
                  Nbar=n;
               }
            }
            n++;
         }
         MaH=0;
         MaL=0;
         for( n=1;n<=Range;n++ )
         {
            MaH=MaH+h1[n];
            MaL=MaL+l1[n];
         }
         MaH=MaH/Range;
         MaL=MaL/Range;
         ur1[cb]=MaH;
         ur2[cb]=MaL;
         if( Close[mm+1]>=MaH )
         {
            ll=1;
            hh=0;
         }
         if( Close[mm+1]<=MaL )
         {
            hh=1;
            ll=0;
         }
      }
      if( ur1[cb]==0 )
      {
         ur1[cb]=ur1[cb+1];
         ur2[cb]=ur2[cb+1];
      }
      if( ll==1 )
      {
         Up[cb]=ur2[cb];
      }
      else
      {
      	if( hh==1 )
      	{
         	Dn[cb]=ur1[cb];
      	}
      }
   }
   else {
//-----------------------------------------------------------------------------

   if( Period()==1440 ) 
   {
      if( TimeDayOfWeek(Time[cb+1])==5 && TimeDayOfWeek(Time[cb])==1 )
      {
         n=cb-6;
         while( n<=cb+Range*5+3 )
         {
            if( n<0 )
            {
               Nbar=0;
               n=1;
            }
            if( TimeDayOfWeek(Time[n+1])==6 || TimeDayOfWeek(Time[n])==2 )
            {
            	if( Nbar==-1 )
            	{
                  Nbar=n;
               	mm=n;
               	n++;
               	continue;
            	}
            	else
               {
                  h1[k]=High[Highest(NULL,0,MODE_HIGH,(n-Nbar),n)];
               	l1[k]=Low[Lowest(NULL,0,MODE_LOW,(n-Nbar),n)];
               	k++;
               	Nbar=n;
               }
            }
            n++;
         }
         MaH=0;
         MaL=0;
         for( n=1;n<=Range;n++ )
         {
            MaH=MaH+h1[n];
            MaL=MaL+l1[n];
         }
         MaH=MaH/Range;
         MaL=MaL/Range;
         ur1[cb]=MaH;
         ur2[cb]=MaL;
         if( Close[mm+1]>=MaH )
         {
            ll=1;
            hh=0;
         }
         if( Close[mm+1]<=MaL )
         {
            hh=1;
            ll=0;
         }
      }
      if( ur1[cb]==0 )
      {
         ur1[cb]=ur1[cb+1];
         ur2[cb]=ur2[cb+1];
      }
      if( ll==1 )
      {
         Up[cb]=ur2[cb];
      }
      else
      {
      	if( hh==1 )
      	{
         	Dn[cb]=ur1[cb];
      	}
      }
   }
   else {
//-----------------------------------------------------------------------------

   if( Period()== 10080 ) 
   {
      if( TimeMonth(Time[cb+1])!=TimeMonth(Time[cb]) )
      {
         n=cb-8;
         while( n<=cb+Range*8+4 )
         {
            if( n<0 )
            {
               Nbar=0;
               n=1;
            }
            if( TimeMonth(Time[n+1])!=TimeMonth(Time[n]) )
            {
               if( Nbar==-1 )
               {
                  Nbar=n;
                  mm=n;
                  n++;
                  continue;
               }
               else
            	{
                  h1[k]=High[Highest(NULL,0,MODE_HIGH,(n-Nbar),n)];
                  l1[k]=Low[Lowest(NULL,0,MODE_LOW,(n-Nbar),n)];
            		k++;
                  Nbar=n;
	            }
            }
            n++;
         }
         MaH=0;
         MaL=0;
         for( n=1;n<=Range;n++ )
         {
            MaH=MaH+h1[n];
            MaL=MaL+l1[n];
         }
         MaH=MaH/Range;
         MaL=MaL/Range;
         ur1[cb]=MaH;
         ur2[cb]=MaL;
         if( Close[mm+1]>=MaH )
         {
            ll=1;
            hh=0;
         }
         if( Close[mm+1]<=MaL )
         {
            hh=1;
            ll=0;
         }
      }
      if( ur1[cb]==0 )
      {
         ur1[cb]=ur1[cb+1];
         ur2[cb]=ur2[cb+1];
      }
      if( ll==1 )
      {
         Up[cb]=ur2[cb];
      }
      else
      {
      	if( hh==1 )
      	{
         	Dn[cb]=ur1[cb];
      	}
	  }
	}
	}}}}}}
//-----------------------------------------------------------------------------
   if (Dn[cb+1]==0.0 && Dn[cb]!=0.0)
   {
      if(cb==0) Alert("");
      SetSymbol("sell_sig",cb,0,Time[cb],High[cb]+15*Point,Black,2,218);
   }
   if (Up[cb+1]==0.0 && Up[cb]!=0.0)
   {
      if(cb==0) Alert("");
      SetSymbol("buy_sig",cb,0,Time[cb],Low[cb]-15*Point,DeepSkyBlue,2,217);
   }
}
   return(rates_total);
  }
//+------------------------------------------------------------------+

void SetSymbol(string txt,int cb_1,int win,datetime stime, double sprice,int scol,int swidth,int scode)
  {
//---- 
   if(ObjectFind(txt+" "+cb_1) == -1)
   {
      ObjectCreate(txt+" "+cb_1,OBJ_ARROW,win,stime,sprice);
      ObjectSet(txt+" "+cb_1,OBJPROP_COLOR,scol);
      ObjectSet(txt+" "+cb_1,OBJPROP_WIDTH,swidth);
      ObjectSet(txt+" "+cb_1,OBJPROP_ARROWCODE,scode);
   }
   else 
   {
      ObjectMove(txt+" "+cb_1,0,stime,sprice);
   }
//----
  }
//+------------------------------------------------------------------+ 

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
//---- TODO: add your code here
   for(cb=Bars-1-Range;cb>=0;cb--) 
   {
      if( ObjectFind("buy_sig "+cb)!=-1 )
      {
         ObjectDelete("buy_sig "+cb);
      }
      else
      {
         if( ObjectFind("sell_sig "+cb)!=-1)
         {
            ObjectDelete("sell_sig "+cb);
         }
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » HiLo_Activator_Profi.mq4 指标创建止损及突破参考水平
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏