文章 "可视化!类似于 R 语言 "plot (绘图)" 的 MQL5 图形库" - 页 3

 
Roman Konopelko:

您好!

自定义绘图函数(CustomPlotFunction) 模式已在库中实现,用于类似目的,使用该模式的示例大致实现了您感兴趣的功能。

附注:更多详情请参见论坛


太好了,谢谢 :)
[删除]  

有办法将 X 轴标签绘制成日期序列吗?

 
Pablo Rego:

有办法将 X 轴标签绘制成日期序列吗?

举例说明:

#include <Graphics/Graphic.mqh>
double arrX[];
double arrY[];
//---
string TimeFormat(double x,void*data)
  {
   return(TimeToString((datetime)arrX[ArraySize(arrX)-(int)x-1]));
  }
//+------------------------------------------------------------------+
void OnStart()
  {
   MqlRates rates[];
   CopyRates(Symbol(),Period(),0,100,rates);
   ArraySetAsSeries(rates,true);
   int size=ArraySize(rates);
   ArrayResize(arrX,size);
   ArrayResize(arrY,size);
   for(int i=0; i<size;++i)
     {
      arrX[i]=(double)rates[i].time;
      arrY[i]=rates[i].close;
     }
   CGraphic graphic;
   graphic.Create(0,"Rates",0,30,30,780,380);
   CCurve *curve=graphic.CurveAdd(arrY,CURVE_LINES,"Close");
   CAxis *xAxis=graphic.XAxis();
   xAxis.AutoScale(false);
   xAxis.Type(AXIS_TYPE_CUSTOM);
   xAxis.ValuesFunctionFormat(TimeFormat);
   xAxis.DefaultStep(20.0);
   curve.Visible(true);
   graphic.Redraw();
   graphic.Update();
  }

结果:


 

是否可以在 X 轴上按相反(反向)顺序绘制标签?

例如,查看时间序列索引。

 
Dennis Kirichenko:

是否可以在 X 轴上按相反(反向)顺序绘制标签?

例如,查看时间序列索引。

调用一个函数并不能快速解决所有问题。与 一样,您需要创建自己的函数来绘制数值,并将其传递给 ValuesFunctionFormat 方法。
 

mql4 中有类似的库吗?

 

您能告诉我是否可以设置背景透明度吗?也许可以在基类中设置,也许需要做些调整?

 
Maxim Dmitrievsky:

您能告诉我是否可以在基类中设置背景透明度吗? 我找不到。


只有修改CGraphic(直接编辑是错误的,您需要继承,这里的例子只是为了方便)。

//+------------------------------------------------------------------+
//| 创建图形|
//+------------------------------------------------------------------+
bool CGraphic::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
  {
//--- 检查对象名称 
   if(ObjectFind(chart,name)>=0)
      return(false);
//--- 初步计算
   int width=x2-x1;
   int height=y2-y1;
   if(width>0 && height>0)
     {
      m_width=width;
      m_height=height;
      //--- 创建对象
      if(!ObjectCreate(chart,name,OBJ_BITMAP_LABEL,subwin,0,0))
         return(false);
      //--- 自定义对象
      if(!ObjectSetInteger(chart,name,OBJPROP_XDISTANCE,x1) || 
         !ObjectSetInteger(chart,name,OBJPROP_YDISTANCE,y1))
        {
         ObjectDelete(chart,name);
         return(false);
        }
      //--- 附加对象
      if(!m_canvas.Attach(chart,name,width,height,COLOR_FORMAT_ARGB_NORMALIZE))
        {
         ObjectDelete(chart,name);
         return(false);
        }
     }
//--- 成功
   return(true);
  }

然后就可以控制颜色了:

   CGraphic graphic;
   graphic.Create(0,"Graphic",0,10,10,680,360);

   graphic.BackgroundColor(ColorToARGB(clrRed,150));
   graphic.GridBackgroundColor(ColorToARGB(clrBlue,150));

:

示例

 
Vladimir Karputov:

只有当您对 CGraphic 类进行更改 时(只有直接编辑才是错误的,您需要继承,此处的示例纯粹是为了快捷起见)

之后您就可以控制颜色了:

:



谢谢,我会处理好继承问题的:)

 

如何在更改智能交易系统 Expert Advisor)(REASON_PARAMETERS)中的输入时,图表不会产生错误并刷新新参数? 如果我切换 tf 或更改符号,一切正常,但如果我更改参数,则会出现指针无效的错误。曲线的数量在参数中发生了变化,而正是在这些曲线上,指针出现了错误。

如果不清楚,我可以举例说明 )