成国 发表于 2021-8-19 20:42:43

日枢轴心指标

本帖最后由 成国 于 2021-8-19 20:46 编辑


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Tomato
//---- input parameters
extern int       ExtFormula=0;
extern int       ExtHowManyDays=30;
extern bool      ExtDraw=true;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
string Copyright="\xA9 www.eazhijia.com";
string MPrefix="FI";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//---- clear buffers when reinitializing
   if(ArraySize(ExtMapBuffer1)>0) ArrayInitialize(ExtMapBuffer1,0.0);
   if(ArraySize(ExtMapBuffer2)>0) ArrayInitialize(ExtMapBuffer2,0.0);
//---- set labels for DataWindow
   if(ExtDraw)
   {
      if(ExtFormula==0)
      {
         SetIndexLabel(0,"Pivot");
         SetIndexLabel(1,NULL);
      }
       else
      {
         SetIndexLabel(0,"Resistance");
         SetIndexLabel(1,"Support");
      }
   }
    else
   {
      SetIndexLabel(0,NULL);
      SetIndexLabel(1,NULL);
   }
//---- force daily data load
   iBars(NULL,PERIOD_D1);
//----
   DL("001", Copyright, 5, 20,Gold,"Arial",10,0);
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                     |
//+------------------------------------------------------------------+
int deinit()
{
//----
   ClearObjects();
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int    counted_bars=IndicatorCounted();
   int    begin_bar, first_bar, last_bar, cnt;
   double yesterday_high, yesterday_low, yesterday_close, today_open;
   double P, S, R, S05, R05, S10, R10, S15, R15, S20, R20, S25, R25, S30, R30;
//---- test parameters
   if(ExtFormula<0 || ExtFormula>3) return(-1);
   if(Period()>=PERIOD_D1)          return(-1);
//---- if daily data not loaded yet
   cnt=0;
   while(true)
   {
      if(iTime(NULL,PERIOD_D1,0)>=(Time-PERIOD_D1*60)) break;
      cnt++;
      if(cnt>5) return(0);
      Sleep(1000);
   }
//---- set check beginning
   if(ExtHowManyDays<1) begin_bar=iBars(NULL,PERIOD_D1)-2;
   else               begin_bar=ExtHowManyDays-1;
//---- case of recounting current pivot only
   if(ExtDraw==false || counted_bars>0) begin_bar=0;
//----
   for(cnt=begin_bar; cnt>=0; cnt--)
   {
      yesterday_close=iClose(NULL,PERIOD_D1,cnt+1);
      today_open=iOpen(NULL,PERIOD_D1,cnt);
      yesterday_high=iHigh(NULL,PERIOD_D1,cnt+1);
      yesterday_low=iLow(NULL,PERIOD_D1,cnt+1);
      P = (yesterday_high + yesterday_low + yesterday_close + today_open) / 4;
      switch(ExtFormula)
      {
         case 1 :
            R = P + P - yesterday_low;
            S = P + P - yesterday_high;
            break;
         case 2 :
            R = P + yesterday_high - yesterday_low;
            S = P - yesterday_high + yesterday_low;
            break;
         case 3 :
            R = P + P - yesterday_low - yesterday_low + yesterday_high;
            S = P + P - yesterday_high - yesterday_high + yesterday_low;
      }
      if(ExtDraw==true)
      {
         first_bar=iBarShift(NULL,0,iTime(NULL,PERIOD_D1,cnt))-1;
         if(cnt>0) last_bar=iBarShift(NULL,0,iTime(NULL,PERIOD_D1,cnt-1))-1;
         else last_bar=0;
         while(first_bar>=last_bar)
         {
            if(first_bar==last_bar && last_bar>0) break;
            if(ExtFormula==0) ExtMapBuffer1=P;
            else
            {
               ExtMapBuffer1=R;
               ExtMapBuffer2=S;
            }
             first_bar--;
         }
      }
   }
   P = NormalizeDouble((yesterday_high + yesterday_low + yesterday_close)/3,Digits);
   R10 = NormalizeDouble((2*P)-yesterday_low,Digits);
   S10 = NormalizeDouble((2*P)-yesterday_high,Digits);
   R05 = NormalizeDouble((P+R10)/2,Digits);
   S05 = NormalizeDouble((P+S10)/2,Digits);
   R20 = NormalizeDouble(P+(yesterday_high-yesterday_low),Digits);
   S20 = NormalizeDouble(P-(yesterday_high-yesterday_low),Digits);
   R15 = NormalizeDouble((R10+R20)/2,Digits);
   S15 = NormalizeDouble((S10+S20)/2,Digits);
   R30 = NormalizeDouble(2*P+(yesterday_high-2*yesterday_low),Digits);
   S30 = NormalizeDouble(2*P-(2*yesterday_high-yesterday_low),Digits);
   R25 = NormalizeDouble((R20+R30)/2,Digits);
   S25 = NormalizeDouble((S20+S30)/2,Digits);
   ObjectCreate(MPrefix + "Pivot_Line", OBJ_HLINE, 0, 0, P);
   ObjectSet(MPrefix + "Pivot_Line", OBJPROP_COLOR, Yellow);
   ObjectSet(MPrefix + "Pivot_Line", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetText(MPrefix + "Pivot_Line","Pivot "+DoubleToStr(P,Digits));
   
      ObjectCreate(MPrefix + "R2.0_Line", OBJ_HLINE, 0, 0, R20);
   ObjectSet(MPrefix + "R2.0_Line", OBJPROP_COLOR, YellowGreen);
   ObjectSet(MPrefix + "R2.0_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText(MPrefix + "R2.0_Line","R2.0 "+DoubleToStr(R20,Digits));
   ObjectCreate(MPrefix + "R2.5_Line", OBJ_HLINE, 0, 0, R25);
   ObjectSet(MPrefix + "R2.5_Line", OBJPROP_COLOR, GreenYellow);
   ObjectSet(MPrefix + "R2.5_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText(MPrefix + "R2.5_Line","R2.5 "+DoubleToStr(R25,Digits));

   ObjectCreate(MPrefix + "R3.0_Line", OBJ_HLINE, 0, 0, R30);
   ObjectSet(MPrefix + "R3.0_Line", OBJPROP_COLOR, YellowGreen);
   ObjectSet(MPrefix + "R3.0_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText(MPrefix + "R3.0_Line","R3.0 "+DoubleToStr(R30,Digits));

   
   ObjectCreate(MPrefix + "S2.0_Line", OBJ_HLINE, 0, 0, S20);
   ObjectSet(MPrefix + "S2.0_Line", OBJPROP_COLOR, Salmon);
   ObjectSet(MPrefix + "S2.0_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText(MPrefix + "S2.0_Line","S2.0 "+DoubleToStr(S20,Digits));
   ObjectCreate(MPrefix + "S2.5_Line", OBJ_HLINE, 0, 0, S25);
   ObjectSet(MPrefix + "S2.5_Line", OBJPROP_COLOR, Salmon);
   ObjectSet(MPrefix + "S2.5_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText(MPrefix + "S2.5_Line","S2.5 "+DoubleToStr(S25,Digits));
   ObjectCreate(MPrefix + "S3.0_Line", OBJ_HLINE, 0, 0, S30);
   ObjectSet(MPrefix + "S3.0_Line", OBJPROP_COLOR, Salmon);
   ObjectSet(MPrefix + "S3.0_Line", OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText(MPrefix + "S3.0_Line","S3.0 "+DoubleToStr(S30,Digits));
//---- force objects drawing
   ObjectsRedraw();
//----
   return(0);
}
//+------------------------------------------------------------------+
//| DL function                                                      |
//+------------------------------------------------------------------+
void DL(string label, string text, int x, int y, color clr, string FontName = "Arial",int FontSize = 12, int typeCorner = 1)

{
   string labelIndicator = MPrefix + label;   
   if (ObjectFind(labelIndicator) == -1)
   {
      ObjectCreate(labelIndicator, OBJ_LABEL, 0, 0, 0);
}
   
   ObjectSet(labelIndicator, OBJPROP_CORNER, typeCorner);
   ObjectSet(labelIndicator, OBJPROP_XDISTANCE, x);
   ObjectSet(labelIndicator, OBJPROP_YDISTANCE, y);
   ObjectSetText(labelIndicator, text, FontSize, FontName, clr);

}
//+------------------------------------------------------------------+
//| ClearObjects function                                          |
//+------------------------------------------------------------------+
void ClearObjects()
{
for(int i=0;i<ObjectsTotal();i++)
if(StringFind(ObjectName(i),MPrefix)==0) { ObjectDelete(ObjectName(i)); i--; }
}
//+------------------------------------------------------------------+

武鸣 发表于 2021-8-20 22:53:31

支持下

抖机灵pk装弱智 发表于 2021-8-21 12:08:33

所有交易品种都是有联系的,并不会单独存在。你的枢轴线我不知道是啥原理,不过本人最近也在改良枢轴线参数,4根线以每周星期四轴线为基准,已能适应大多数品种。我正在观察指标报出点位正确与否

猪仔希 发表于 2021-8-22 11:17:42

支持下

朱恒 发表于 2021-8-26 10:09:10

支持下

何平 发表于 2021-8-26 20:18:23

{:1_179:}

开心一刻 发表于 2021-9-4 14:06:06

{:1_179:}

小试菜刀 发表于 2021-9-4 14:26:37

谢谢

spanac 发表于 2021-9-6 19:28:33

顶下

交易家 发表于 2021-9-14 22:58:47

{:1_186:}
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 日枢轴心指标