📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    求大佬指导一下,同时加载两个只显示一个

    2026-02-06 · 70 阅读
    求大佬指导一下,同时加载两个只显示一个,给改下文件名和周期,但是只显示一个,不知道原因在哪里



    //+------------------------------------------------------------------+
    //|                                       MTF Inside Bar v1.2        |
    //|                                  2014 - Joca (nc32007a@gmail.com)|
    //+------------------------------------------------------------------+

    #property indicator_chart_window

    //---- input parameters
    extern int       TFup=5;
    extern int       bars_back=0;
    extern bool      stats=false;
    extern color     UpCandleColor=clrCrimson;
    extern color     DownCandleColor=clrSeaGreen;
    extern int       width = 3;
    extern bool      filling=false;
    extern int       Font_Size=15;
    extern int       Corner=3;
    //template code start1
    extern string             button_note1          = "------------------------------";
    extern ENUM_BASE_CORNER   btn_corner            = CORNER_LEFT_UPPER; // chart btn_corner for anchoring
    extern string             btn_text              = "4小时线";
    extern string             btn_Font              = "Arial1";
    extern int                btn_FontSize          = 10;                             //btn__font size
    extern color              btn_text_ON_color     = clrWhite;
    extern color              btn_text_OFF_color    = clrRed;
    extern color              btn_background_color  = clrDimGray;
    extern color              btn_border_color      = clrBlack;
    extern int                button_x              = 100;                                     //btn__x
    extern int                button_y              = 50;                                     //btn__y
    extern int                btn_Width             = 60;                                 //btn__width
    extern int                btn_Height            = 30;                                //btn__height
    extern string             button_note2          = "------------------------------";

    bool                      show_data             = true;
    string IndicatorName, IndicatorObjPrefix;
    //template code end1


    //---- internal parameters

    int timeFrame[] = {1,5,15,30,60,240,1440,10080,43200};
    string TimeFrames[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
    int nextTF;
    color clr;

    //+------------------------------------------------------------------------------------------------------------------+
    string GenerateIndicatorName(const string target) //don't change anything here
    {
       string name = target;
       int try = 2;
       while (WindowFind(name) != -1)
       {
          name = target + " #" + IntegerToString(try++);
       }
       return name;
    }
    //+------------------------------------------------------------------------------------------------------------------+
    string buttonId;

    int OnInit()
    {
       IndicatorName = GenerateIndicatorName(btn_text);
       IndicatorObjPrefix = "__" + IndicatorName + "__";
       IndicatorShortName(IndicatorName);
       IndicatorDigits(Digits);
       
       double val;
       if (GlobalVariableGet(IndicatorName + "_visibility", val))
          show_data = val != 0;

       ChartSetInteger(ChartID(), CHART_EVENT_MOUSE_MOVE, 1);
       buttonId = IndicatorObjPrefix + "Donchian2020";
       createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_ON_color);
       ObjectSetInteger(ChartID(), buttonId, OBJPROP_YDISTANCE, button_y);
       ObjectSetInteger(ChartID(), buttonId, OBJPROP_XDISTANCE, button_x);

    // put init() here
       init2();
       return(INIT_SUCCEEDED);
    }
    //+------------------------------------------------------------------------------------------------------------------+
    //+------------------------------------------------------------------+
    //| Custom indicator initialization function                         |
    //+------------------------------------------------------------------+

    void init2()

      {

    for(int i=0;i<ArraySize(timeFrame);i++)

    {
    if(i==ArraySize(timeFrame)-TFup){nextTF=timeFrame[8];Print("Sorry maximum time frame reached");break;}
    if(timeFrame==Period()){nextTF=timeFrame[i+TFup];break;}

      }
       
      
      }
    //+------------------------------------------------------------------------------------------------------------------+
    //don't change anything here
    void createButton(string buttonID,string buttonText,int width2,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor)
    {
          ObjectDelete    (ChartID(),buttonID);
          ObjectCreate    (ChartID(),buttonID,OBJ_BUTTON,0,0,0);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_COLOR,txtColor);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_BGCOLOR,bgColor);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_BORDER_COLOR,borderColor);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_XSIZE,width2);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_YSIZE,height);
          ObjectSetString (ChartID(),buttonID,OBJPROP_FONT,font);
          ObjectSetString (ChartID(),buttonID,OBJPROP_TEXT,buttonText);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_FONTSIZE,fontSize);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_SELECTABLE,0);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_CORNER,btn_corner);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_HIDDEN,1);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_XDISTANCE,9999);
          ObjectSetInteger(ChartID(),buttonID,OBJPROP_YDISTANCE,9999);
    }
    //+------------------------------------------------------------------------------------------------------------------+
    int deinit()
    {
       ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);

    //put deinit() here
       deinit2();
            return(0);
    }
    //+------------------------------------------------------------------------------------------------------------------+
    //don't change anything here
    bool recalc = true;

    void handleButtonClicks()
    {
       if (ObjectGetInteger(ChartID(), buttonId, OBJPROP_STATE))
       {
          ObjectSetInteger(ChartID(), buttonId, OBJPROP_STATE, false);
          show_data = !show_data;
          GlobalVariableSet(IndicatorName + "_visibility", show_data ? 1.0 : 0.0);
          recalc = true;
          start();
       }
    }
    //+------------------------------------------------------------------------------------------------------------------+
    void OnChartEvent(const int id, //don't change anything here
                      const long &lparam,
                      const double &dparam,
                      const string &sparam)
    {
       handleButtonClicks();
    }
    //+------------------------------------------------------------------------------------------------------------------+
    //+------------------------------------------------------------------+
    //| Custor indicator deinitialization function                       |
    //+------------------------------------------------------------------+


    void deinit2()
    {

      ObjectDelete("Timeframe");
      for(int ind=0;ind<=bars_back*3+2;ind++)
      {
      ObjectDelete("rect"+ind);
      }

      
    }
    //+------------------------------------------------------------------------------------------------------------------+
    int start()
    {
       handleButtonClicks();
       recalc = false;
       //put start () here
       int   limit, counted_bars = IndicatorCounted();
       if(counted_bars > 0) limit = Bars - counted_bars - 1;
       if(counted_bars < 0) return(0);
       
          if (show_data)
             {
              ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_ON_color);
              init2();
              start2();
             }
          else
          {
           ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_OFF_color);
           deinit2();
          }
       return(0);
    }
    //+------------------------------------------------------------------------------------------------------------------+


    //+------------------------------------------------------------------+
    //| Custom indicator iteration function                              |
    //+------------------------------------------------------------------+


    int start2()


      {
       
      
      
       
       //----
       
       datetime dif=Period();
       datetime difTF=nextTF;
       int ii=0;
       int ix=0;
       datetime Tini, Tfim, Tmed;
       
       
         {
         
         while(ix<=bars_back)
         
         {
         
          Tini=iTime(NULL,nextTF,ix);
          Tfim=iTime(NULL,nextTF,ix-1)-dif; //if (ix==0) {Tfim=Tfim;}
          double aux=iClose(NULL,nextTF,ix);
          double range_bar=MathAbs((iClose(NULL,nextTF,ix)-iOpen(NULL,nextTF,ix))*10000);
          
          if (iOpen(NULL,nextTF,ix) > iClose(NULL,nextTF,ix)) aux=iOpen(NULL,nextTF,ix);
             
          if (ix<=1) {Tini =iTime(NULL,nextTF,ix); Tfim=Tini+(difTF-dif)*60;}
          
          Tmed=(Tini+Tfim)/2+dif;
          
          ObjectDelete("rect"+ii);
          
          ObjectCreate("rect"+ii,OBJ_RECTANGLE, 0, 0, iOpen(NULL,nextTF,ix), 0, iClose(NULL,nextTF,ix));
          clr=DownCandleColor; if (iOpen(NULL,nextTF,ix) < iClose(NULL,nextTF,ix)) clr=UpCandleColor;
          
          ObjectSet("rect"+ii, OBJPROP_TIME1,Tini);
          ObjectSet("rect"+ii, OBJPROP_TIME2, Tfim);
          ObjectSet("rect"+ii, OBJPROP_STYLE, STYLE_SOLID);
          ObjectSet("rect"+ii, OBJPROP_BACK, filling);
          ObjectSet("rect"+ii, OBJPROP_COLOR, clr);
          ObjectSet("rect"+ii, OBJPROP_WIDTH, width );
          ObjectSet("rect"+ii, OBJPROP_RAY, False);
          if (stats) ObjectSetText("rect"+ii," This Bar=  "+ MathRound(range_bar)+ " Pips", 15,"Times New Roman");
          
          ii+=1;
          
          ObjectDelete("rect"+ii);

          
          
          ObjectCreate("rect"+ii,OBJ_TREND, 0, 0, iHigh(NULL,nextTF,ix), 0, aux);
          
          
          
          ObjectSet("rect"+ii, OBJPROP_TIME1, Tmed);
          ObjectSet("rect"+ii, OBJPROP_TIME2, Tmed);
          ObjectSet("rect"+ii, OBJPROP_STYLE, STYLE_SOLID);
          ObjectSet("rect"+ii, OBJPROP_BACK, 0);
          ObjectSet("rect"+ii, OBJPROP_COLOR, clr);
          ObjectSet("rect"+ii, OBJPROP_WIDTH, width );
          ObjectSet("rect"+ii, OBJPROP_RAY, False);
          
          
          
          ii+=1;
          
          ObjectDelete("rect"+ii);
          
          aux=iOpen(NULL,nextTF,ix);
          
          if (iOpen(NULL,nextTF,ix) > iClose(NULL,nextTF,ix)) aux=iClose(NULL,nextTF,ix);
          
          
          ObjectCreate("rect"+ii,OBJ_TREND, 0, 0, iLow(NULL,nextTF,ix), 0, aux);
          
          

          ObjectSet("rect"+ii, OBJPROP_TIME1, Tmed);
          ObjectSet("rect"+ii, OBJPROP_TIME2, Tmed);
          ObjectSet("rect"+ii, OBJPROP_STYLE, STYLE_SOLID);
          ObjectSet("rect"+ii, OBJPROP_BACK, 0);
          ObjectSet("rect"+ii, OBJPROP_COLOR, clr);
          ObjectSet("rect"+ii, OBJPROP_WIDTH, width );
          ObjectSet("rect"+ii, OBJPROP_RAY, False);
          
          ii+=1;
          ix+=1;

          }
          
          string Message;
          
          
          for(int i=0;i<ArraySize(timeFrame);i++)
          
          {if(timeFrame==nextTF){Message=TimeFrames+ "\n";}}
       
       
          ObjectDelete("Timeframe");
          clr=DownCandleColor; if (iOpen(NULL,nextTF,0) < iClose(NULL,nextTF,0)) clr=UpCandleColor;
          ObjectCreate   ("Timeframe", OBJ_LABEL, 0, 0, 0);
          ObjectSet      ("Timeframe", OBJPROP_CORNER, Corner);
          ObjectSet      ("Timeframe", OBJPROP_YDISTANCE, 50);
          ObjectSet      ("Timeframe", OBJPROP_XDISTANCE, 200);
          ObjectSetText  ("Timeframe", "显示的周期为 = "+ Message, Font_Size, "Verdana", clr);
       
          //WindowRedraw();
          
    }

       return(0);
    }

    360截图-215452.jpg
    ""
    还没有人打赏,支持一下
    回复

    举报

     
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服