找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 7|回复: 0

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

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-24 21:42:00 | 显示全部楼层 |阅读模式
双重显示 赠与给有缘人      大写显示点差 和实时卖价线

k线倒计时指标  可以跟随价格摆动

右下角固定位置显示单根k 读秒


以下是源码可以忽略


//+------------------------------------------------------------------+

//|                               Π.EA 跨应用周期均线1.1  |

//|                                                             @老顽童 |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "@Π.EA 大树My05613828"

#property link      "

#property version   "1.0"

//#property  icon     "//include//M5//logo.ico"


#property indicator_chart_window

#property indicator_plots   0


//--- indicator buffers


input string  时间参数="=======时间参数=====";

input color 文本颜色=clrYellow;

input int 平移值=232;

input  ENUM_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);

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

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-12 19:51 , Processed in 0.105282 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表