奔赴魔方量化 发表于 2024-11-26 15:14:51

【k线倒计时指标】k线倒计时指标

双重显示 赠与给有缘人      大写显示点差 和实时卖价线
k线倒计时指标可以跟随价格摆动
右下角固定位置显示单根k 读秒

以下是源码可以忽略


//+------------------------------------------------------------------+
//|                               Π.EA 跨应用周期均线1.1|
//|                                                             @老顽童 |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "@Π.EA 大树My05613828"
#property link      "https://www.eahub.cn/space-uid-8564.html"
#property version   "1.0"
//#propertyicon   "//include//M5//logo.ico"

#property indicator_chart_window
#property indicator_plots   0

//--- indicator buffers

input string时间参数="=======时间参数=====";
input color 文本颜色=clrYellow;
input int 平移值=232;
inputENUM_BASE_CORNER 时间角落=CORNER_RIGHT_LOWER;
input color 背景颜色2=clrYellow;
input color 字颜色2=clrBlack;
input int 字号2=15;
input bool 显示文本标签=true,显示文本框=true;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   EventSetTimer(1);
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//ObjectsDeleteAll(0);
   ObjectDelete(0,"time");
   ObjectDelete(0,"K时间");
   ObjectDelete(0,"point");
   ObjectDelete(0,"bid");
   ObjectsDeleteAll(0,0,OBJ_EDIT);
   Comment("");
   EventKillTimer();
}
//+------------------------------------------------------------------+
//| 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[])
{
//---

   text("bid","价格 "+DoubleToString(SymbolInfoDouble(Symbol(),SYMBOL_BID),Digits()),TimeCurrent()-(long)(ChartVisibleBars()*0.3*PeriodSeconds(PERIOD_CURRENT)),ChartPriceMin()+(ChartPriceMax()-ChartPriceMin())*0.618,文本颜色,20);
   text("point","点差 "+IntegerToString(SymbolInfoInteger(Symbol(),SYMBOL_SPREAD)),TimeCurrent()-(long)(ChartVisibleBars()*0.7*PeriodSeconds(PERIOD_CURRENT)),ChartPriceMin()+(ChartPriceMax()-ChartPriceMin())*0.618,文本颜色,20);

   return(rates_total);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
{
   long m,s;
   m=iTime(Symbol(),PERIOD_CURRENT,0)+PeriodSeconds(PERIOD_CURRENT)-TimeCurrent();
//i=m/60.0;
   s=m%60;
   m=(m-m%60)/60;
   Comment((string)m + " minutes " + (string)s + " seconds left to bar end");
   if(ObjectFind(0,"time")!=-1)
      ObjectDelete(0,"time");
//---

   if(显示文本标签)
      text("time","\t\t         < "+IntegerToString(m)+":"+IntegerToString(s,2,'0'),TimeCurrent()+2*PeriodSeconds(PERIOD_CURRENT),SymbolInfoDouble(Symbol(),SYMBOL_BID),文本颜色,11);
   else
      ObjectDelete(0,"time");

   if(显示文本框)
      画编辑框("K时间",0,平移值,39,80,40,true,时间角落,IntegerToString(m)+":"+IntegerToString(s,2,'0'),背景颜色2,clrBlack,字颜色2,"楷体",字号2,ALIGN_CENTER,true,false,true);
   else
      ObjectDelete(0,"K时间");
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void text(string name,string text,datetime time,double price,color colo=clrYellow,int fontsize=10,int sub_window=0)
{
   if(ObjectFind(0,name)<0)
   {
      ObjectCreate(0,name,OBJ_TEXT,sub_window,time,price);
   }
   else
   {
      if(ObjectGetInteger(0,name,OBJPROP_TIME)!=time)
      {
         ObjectSetInteger(0,name,OBJPROP_TIME,time);
      }
      if(ObjectGetDouble(0,name,OBJPROP_PRICE)!=price)
      {
         ObjectSetDouble(0,name,OBJPROP_PRICE,price);
      }
   }
   if(ObjectGetInteger(0,name,OBJPROP_FONTSIZE)!=fontsize)
   {
      ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);
   }
   if(ObjectGetInteger(0,name,OBJPROP_COLOR)!=colo)
   {
      ObjectSetInteger(0,name,OBJPROP_COLOR,colo);
   }
   if(ObjectGetString(0,name,OBJPROP_TEXT)!=text)
   {
      ObjectSetString(0,name,OBJPROP_TEXT,text);
   }
}


//+------------------------------------------------------------------+
void 画编辑框
(
   string            编辑框名称,
   int               编辑框窗口,
   int               编辑框X轴,
   int               编辑框Y轴,
   int               编辑框宽度,
   int               编辑框高度,
   bool            编辑框只读,
   ENUM_BASE_CORNER编辑框角落,
   string            编辑框内容,
   color             编辑框背景色,
   color             编辑框边框色,
   color             字体颜色,
   string            编辑框字体,
   int               字体大小,
   ENUM_ALIGN_MODE   字体对齐,
   bool            编辑框前景,
   bool            编辑框可选,
   bool            编辑框移动
)
{
//---创建编辑框
   if(ObjectFind(0,编辑框名称)<0)
   {
      bool 编辑框=ObjectCreate(0,编辑框名称,OBJ_EDIT,编辑框窗口,0,0);
      if(编辑框==false)
      {
         Print("编辑框创建失败:"+IntegerToString(GetLastError()));
      }
   }
//---设置编辑框的X轴和Y轴
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_XDISTANCE)!=编辑框X轴 ||ObjectGetInteger(0,编辑框名称,OBJPROP_YDISTANCE)!=编辑框Y轴)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_XDISTANCE,编辑框X轴);
      ObjectSetInteger(0,编辑框名称,OBJPROP_YDISTANCE,编辑框Y轴);
   }
//---设置编辑框的高度和宽度
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_XSIZE)!=编辑框宽度 ||ObjectGetInteger(0,编辑框名称,OBJPROP_YSIZE)!=编辑框高度)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_XSIZE,编辑框宽度);
      ObjectSetInteger(0,编辑框名称,OBJPROP_YSIZE,编辑框高度);
   }
//---设置编辑框的状态
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_READONLY)!=编辑框只读)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_READONLY,编辑框只读);
   }
//---设置编辑框的角落
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_CORNER)!=编辑框角落)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_CORNER,编辑框角落);
   }
//---设置编辑框的内容
   if(ObjectGetString(0,编辑框名称,OBJPROP_TEXT)!=编辑框内容)
   {
      ObjectSetString(0,编辑框名称,OBJPROP_TEXT,编辑框内容);
   }
//---设置编辑的背景色
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_BGCOLOR)!=编辑框背景色)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_BGCOLOR,编辑框背景色);
   }
//---设置编辑框的边框色
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_BORDER_COLOR)!=编辑框边框色)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_BORDER_COLOR,编辑框边框色);
   }
//---设置编辑框的文本色
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_COLOR)!=字体颜色)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_COLOR,字体颜色);
   }
//---设置编辑框文本字体
   if(ObjectGetString(0,编辑框名称,OBJPROP_FONT)!=编辑框字体)
   {
      ObjectSetString(0,编辑框名称,OBJPROP_FONT,编辑框字体);
   }
//---设置编辑框字体大小
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_FONTSIZE)!=字体大小)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_FONTSIZE,字体大小);
   }
//---设置编辑框字体对齐
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_ALIGN)!=字体对齐)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_ALIGN,字体对齐);
   }
//---设置编辑框前景
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_BACK)!=编辑框前景)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_BACK,编辑框前景);
   }
//---设置编辑框可选
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_SELECTABLE)!=编辑框可选)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_SELECTABLE,编辑框可选);
   }
//---设置编辑框移动
   if(ObjectGetInteger(0,编辑框名称,OBJPROP_SELECTED)!=编辑框移动)
   {
      ObjectSetInteger(0,编辑框名称,OBJPROP_SELECTED,编辑框移动);
   }
};
//+-----
//+------------------------------------------------------------------+
void 空值不显示(int 缓冲区)
{
   PlotIndexSetDouble(缓冲区,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(缓冲区,PLOT_EMPTY_VALUE,0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
double ChartPriceMin(const long chart_ID=0,const int sub_window=0)
{
   double result=EMPTY_VALUE;
   ResetLastError();
   if(!ChartGetDouble(chart_ID,CHART_PRICE_MIN,sub_window,result))
      Print(__FUNCTION__+", Error Code = ",GetLastError());
   return(result);
}
//+--------------------------------------------------------------------------------+
//| 这个函数接收主窗口或子窗口的图表最大值。                                             |
//+--------------------------------------------------------------------------------+
double ChartPriceMax(const long chart_ID=0,const int sub_window=0)
{
   double result=EMPTY_VALUE;
   ResetLastError();
   if(!ChartGetDouble(chart_ID,CHART_PRICE_MAX,sub_window,result))
      Print(__FUNCTION__+", Error Code = ",GetLastError());
   return(result);
}
//+------------------------------------------------------------------+
int ChartVisibleBars(const long chart_ID=0)
{
//--- 准备变量获得属性值
   long result=-1;
//--- 重置错误的值
   ResetLastError();
//--- 接收属性值
   if(!ChartGetInteger(chart_ID,CHART_VISIBLE_BARS,0,result))
   {
      //--- 在EA日志显示错误信息
      Print(__FUNCTION__+", Error Code = ",GetLastError());
   }
//--- 返回图表属性值
   return((int)result);
}

david6843 发表于 2024-11-26 23:23:43

看着不错,可以用这试试`

shuiluo 发表于 2024-11-26 23:53:08

正好方便看盘

peterzhu2004 发表于 2024-11-27 06:12:48

多谢分享实用工具

liutong3721 发表于 2024-11-27 14:05:08

是个好东西

胖教授 发表于 2024-12-12 20:26:22

take away!thanks.

守护神 发表于 2024-12-13 11:44:21

多谢分享实用工具 感谢分享

weixi 发表于 2024-12-13 15:58:33

很实用,谢谢分享

纯手艺 发表于 2025-3-3 16:41:22

这个非常好用 ,感谢分享

gao123456 发表于 2025-3-3 17:20:22

wtf123 发表于 2025-3-8 03:45:22

这个非常好用 ,感谢分享]

EA187374 发表于 2025-3-8 12:25:30

不错不错,感谢分享

yangxiao 发表于 2025-5-29 11:43:47

实用性很好。

csby78 发表于 2025-10-24 23:22:21

积分还不够下载

yh8888 发表于 2026-4-9 19:28:16

为什么会闪缩
页: [1]
查看完整版本: 【k线倒计时指标】k线倒计时指标