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

价格波动轴心和支撑阻力指标 Daily FiboPivots.mq4

Daily FiboPivots指标绘制价格波动轴心和支撑阻力。

图表:Daily FiboPivots指标

源码:

//+------------------------------------------------------------------+
//|                                             Daily FiboPivots.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "http://www.125808047.com"

#define IND_NAME "Pivot Point S&R"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 LimeGreen
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Blue
#property indicator_color7 Red

extern int       StartHour=0;
extern int       StartMinute=0;
extern int       DaysToPlot=15;
extern color     SupportLabelColor=DodgerBlue;
extern color     ResistanceLabelColor=OrangeRed;
extern color     PivotLabelColor=Green;
extern int       fontsize=8;
extern int       LabelShift = 0;

double R3Buffer[];
double R2Buffer[];
double R1Buffer[];
double PBuffer[];
double S1Buffer[];
double S2Buffer[];
double S3Buffer[];

string Pivot="Pivot",Sup1="S 1", Res1="R 1";
string Sup2="S 2", Res2="R 2", Sup3="S 3", Res3="R 3";
datetime LabelShiftTime;
double P,S1,R1,S2,R2,S3,R3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   SetIndexStyle(0,DRAW_LINE,0,2);
   SetIndexStyle(1,DRAW_LINE,0,2);
   SetIndexStyle(2,DRAW_LINE,0,2);
   SetIndexStyle(3,DRAW_LINE,0,2);
   SetIndexStyle(4,DRAW_LINE,0,2);
   SetIndexStyle(5,DRAW_LINE,0,2);
   SetIndexStyle(6,DRAW_LINE,0,2);
   SetIndexBuffer(0,PBuffer);
   SetIndexBuffer(1,S1Buffer);
   SetIndexBuffer(2,R1Buffer);
   SetIndexBuffer(3,S2Buffer);
   SetIndexBuffer(4,R2Buffer);
   SetIndexBuffer(5,S3Buffer);
   SetIndexBuffer(6,R3Buffer);
   
   IndicatorShortName(IND_NAME);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
  void OnDeinit(const int reason)
  {
   ObjectDelete("Res3");
   ObjectDelete("Res2");
   ObjectDelete("Res1");
   ObjectDelete("Pivot");
   ObjectDelete("Sup1");
   ObjectDelete("Sup2");
   ObjectDelete("Sup3");   
  }
//+------------------------------------------------------------------+
//| 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(); 
  
    if(Period() > 240)
   {
   Print("Error - Chart period is greater than 1 day.");
   return(-1); // then exit
   }
  
{
   if (counted_bars==0)
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
}

   int limit=2000;
   int StartMinutesIntoDay=(StartHour*60)+StartMinute; 
   int CloseMinutesIntoDay=StartMinutesIntoDay-Period();
   
   if (CloseMinutesIntoDay<0)
      {
         CloseMinutesIntoDay=CloseMinutesIntoDay+1440;
      }

   int BarsInDay=1440/Period();
   
   for(int i=0; i<limit; i++)
   { 
      if ( (i<((DaysToPlot+1)*BarsInDay))||DaysToPlot==0)   
      {                                                    
      int PreviousClosingBar = FindLastTimeMatchFast(CloseMinutesIntoDay,i+1);
      int PreviousOpeningBar = FindLastTimeMatchFast(StartMinutesIntoDay,PreviousClosingBar+1);
      
      double PreviousHigh= High[PreviousClosingBar];
      double PreviousLow = Low [PreviousClosingBar];
      double PreviousClose = Close[PreviousClosingBar];

      for (int SearchHighLow=PreviousClosingBar;SearchHighLow<(PreviousOpeningBar+1);SearchHighLow++)
      {
         if (High[SearchHighLow]>PreviousHigh) PreviousHigh=High[SearchHighLow];
         if (Low[SearchHighLow]<PreviousLow) PreviousLow=Low[SearchHighLow];
      }
      {
       double R =  (PreviousHigh - PreviousLow);
       P =  (PreviousHigh+PreviousLow+PreviousClose)/3;
       R3 = P + (R * 1.000);
       R2 = P + (R * 0.618);
       R1 = P + (R * 0.382);
       S1 = P - (R * 0.382);
       S2 = P - (R * 0.618);
       S3 = P - (R * 1.000);
      
      LabelShiftTime = Time[LabelShift];
      
      if (i==0)
         {
         Print(i);
   
         ObjectCreate("Pivot", OBJ_TEXT, 0, LabelShiftTime, 0);   
         ObjectSetText("Pivot", "                           Pivot " +DoubleToStr(P,4),fontsize,"tahoma ",PivotLabelColor);
         SetIndexLabel(0, "Pivot Point");
         ObjectCreate("Sup1", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("Sup1", "                    S1 " +DoubleToStr(S1,4),fontsize,"tahoma ",SupportLabelColor);
         SetIndexLabel(1, "S1");
         ObjectCreate("Res1", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("Res1", "                    R1 " +DoubleToStr(R1,4),fontsize,"tahoma ",ResistanceLabelColor);
         SetIndexLabel(2, "R1");
         ObjectCreate("Sup2", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("Sup2", "                    S2 " +DoubleToStr(S2,4),fontsize,"tahoma ",SupportLabelColor);
         SetIndexLabel(3, "S2");
         ObjectCreate("Res2", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("Res2", "                    R2 " +DoubleToStr(R2,4),fontsize,"tahoma ",ResistanceLabelColor);
         SetIndexLabel(4, "R2");
         ObjectCreate("Sup3", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("Sup3", "                    S3 " +DoubleToStr(S3,4),fontsize,"tahoma ",SupportLabelColor);
         SetIndexLabel(5, "S3");
         ObjectCreate("Res3", OBJ_TEXT, 0, LabelShiftTime, 0);
         ObjectSetText("Res3", "                    R3 " +DoubleToStr(R3,4),fontsize,"tahoma ",ResistanceLabelColor);
         SetIndexLabel(6, "R3");
         Print("ObjectSet Done");
         ObjectMove("Res3", 0, LabelShiftTime,R3);
         ObjectMove("Res2", 0, LabelShiftTime,R2);
         ObjectMove("Res1", 0, LabelShiftTime,R1);
         ObjectMove("Pivot", 0, LabelShiftTime,P);
         ObjectMove("Sup1", 0, LabelShiftTime,S1);
         ObjectMove("Sup2", 0, LabelShiftTime,S2);
         ObjectMove("Sup3", 0, LabelShiftTime,S3);
         Print("ObjectMove Done");
         ObjectsRedraw(); 
         Print("ObjectsRedraw Done");
         }
   }
      
}  
    R3Buffer[i]=R3;
    R2Buffer[i]=R2;
    R1Buffer[i]=R1;
    PBuffer[i]=P;
    S1Buffer[i]=S1;
    S2Buffer[i]=S2;
    S3Buffer[i]=S3;
    
   }
   return(rates_total);
  }
int FindLastTimeMatchFast(int TimeToLookFor,int StartingBar)
   {
   int StartingBarsTime=(TimeHour(Time[StartingBar])*60)+TimeMinute(Time[StartingBar]);

   if (StartingBarsTime<TimeToLookFor)
      {
      StartingBarsTime=StartingBarsTime+1440;
      }

   int HowFarBack=StartingBarsTime-TimeToLookFor;
   
   int HowManyBarsBack=HowFarBack/Period();

   int SuggestedBar=StartingBar+HowManyBarsBack;
   
   int SuggestedBarsTime=(TimeHour(Time[SuggestedBar])*60)+TimeMinute(Time[SuggestedBar]);
   
   if (SuggestedBarsTime==TimeToLookFor)
      {
      return(SuggestedBar);
      }   
      
   int DeltaTimeFound=TimeToLookFor-SuggestedBarsTime;
   int DeltaBarFound=DeltaTimeFound/Period();
   
   if (DeltaTimeFound>0)
      {
        for (int SearchCount=SuggestedBar ;SearchCount>(SuggestedBar-DeltaBarFound-2) ;SearchCount--)
            {
            int PreviousBarsTime=(TimeHour(Time[SearchCount+1])*60)+TimeMinute(Time[SearchCount+1]);
            int CurrentBarsTime=(TimeHour(Time[SearchCount])*60)+TimeMinute(Time[SearchCount]);
            int NextBarsTime=(TimeHour(Time[SearchCount-1])*60)+TimeMinute(Time[SearchCount-1]);
      
            if (CurrentBarsTime==TimeToLookFor)
               {
               return(SearchCount);    
               }

            if(PreviousBarsTime>CurrentBarsTime)  
               {                                       
               PreviousBarsTime=PreviousBarsTime-1440;
               }

            if(NextBarsTime<CurrentBarsTime)         
               {
               NextBarsTime=NextBarsTime+1440;
               }

            if(PreviousBarsTime<TimeToLookFor)
               {
                  if( TimeToLookFor<NextBarsTime)
                  {
                  return(SearchCount);
                  }
               }
            }
      }
   return (SuggestedBar);
   }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 价格波动轴心和支撑阻力指标 Daily FiboPivots.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏