成国 发表于 2021-8-20 18:41:08

显示星期一到星期5指标

//--- strict compilation mode
#property strict
#property copyright "© 2006 RickD"
#property link      "www.fxstrategy.ca"
#property version   "v1.1"


#propertyindicator_chart_window
#propertyindicator_buffers 0

extern int MaxDays = 20;
extern int FontSize = 8;
extern string FontName = "Verdana";

extern string __2__ = ""; //------------------------------------------------------------------------------------------------------

extern string Text1 = "星期一";
extern string Text2 = "星期二";
extern string Text3 = "星期三";
extern string Text4 = "星期四";
extern string Text5 = "星期五";

extern string __3__ = ""; //------------------------------------------------------------------------------------------------------

extern color ColorMonday = Blue;
extern color ColorTuesday = MediumSeaGreen;
extern color ColorWednesday = Orange;
extern color ColorThursday = Orchid;
extern color ColorFriday = Coral;

extern string __4__ = ""; //------------------------------------------------------------------------------------------------------

extern bool ShowToday = true;
extern string __5__ = ""; //------------------------------------------------------------------------------------------------------

extern bool ShowMonday = true;
extern bool ShowTuesday = true;
extern bool ShowWednesday = true;
extern bool ShowThursday = true;
extern bool ShowFriday = true;


string Text;
color Color;
bool ShowDay;

string prefix = "5days_";

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void init() {

Text = Text1;
Text = Text2;
Text = Text3;
Text = Text4;
Text = Text5;

Color = ColorMonday;
Color = ColorTuesday;
Color = ColorWednesday;
Color = ColorThursday;
Color = ColorFriday;

ShowDay = ShowMonday;
ShowDay = ShowTuesday;
ShowDay = ShowWednesday;
ShowDay = ShowThursday;
ShowDay = ShowFriday;

clear();
show();
}

void deinit() {
clear();
}

void start()
{
show();
}

void OnChartEvent(const int EventID,    // Event ID
                  const long& lparam,   // Parameter of type long event
                  const double& dparam, // Parameter of type double event
                  const string& sparam// Parameter of type string events
               )
{
   if (EventID == CHARTEVENT_CHART_CHANGE)
   {
      clear();
      show();
   }
}

void show() {
int P = Period();
if (P > PERIOD_D1) return;

string name = "";

int cnt = MathMin(Bars, PERIOD_D1/P*MaxDays);
int j=0;
if (!ShowToday) j = PERIOD_D1/P;
for (int i=j; i < cnt; i++)
{
    if (TimeDayOfWeek(Time) != TimeDayOfWeek(Time))
    {
      name = prefix + TimeToStr(Time);
      
      int res = ObjectFind(name);
      if (res == -1)
      {      
      int day = TimeDayOfWeek(Time);
      if (!ShowDay) continue;
      ObjectCreate(0,name, OBJ_TEXT, 0, Time+3600 , WindowPriceMin() + 50*Point);
      ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_LEFT);
      if(Period()<PERIOD_H4){
      ObjectSetText(name, Text, FontSize, FontName, Color);
      }else{
       ObjectDelete(name);
      }
      }
    }
}
}

void clear() {
int P = Period();
if (P > PERIOD_D1) return;

string name = "";

int cnt = MathMin(Bars, PERIOD_D1/P*MaxDays);
for (int i=0; i < cnt; i++)
{
    name = prefix + TimeToStr(Time);
   
    int res = ObjectFind(name);
    ObjectDelete(name);
}
}
页: [1]
查看完整版本: 显示星期一到星期5指标