如何使XY绘制的对象平稳变化(MT4 vs MT5) - 页 2

 
Vitaliy Kuznetsov:

谢谢你提供这种解决问题的办法。事实上,渲染速度已经提高了。看来我得学习图书馆了。

我还想澄清以下细微差别。它用这种配方编译时有一个警告。

而用这个编译时没有警告,但速度有点慢。

什么是更正确的?)

啊,对了,我忘了放int。该图书馆是面向双坐标的。
速度不能下降。(int)实际上是免费的。不到纳秒。
你可以这样设置。

y = Round(Canvas.Y(price));

它也不会影响速度(+ ~1 ns),但它会定位得更准确一些。

iCanvas内置的Round函数返回int,比普通的round()函数快得多,但双倍参数x必须在int之内(-2 147 483 648 <= x <= 2 147 483 647)

int Ceil (double x) { return (x-(int)x>0)?(int)x+1:(int)x; }
int Round(double x) { return (x>0)?(int)(x+0.5):(int)(x-0.5);}
int Floor(double x) { return (x>0)?(int)x:((int)x-x>0)?(int)x-1:(int)x; }
int Fabs(int x) {if (x<0) return -x; else return x;}
 
Vitaliy Kuznetsov:
我不太清楚Canvas.Y(price)是什么类型。

它返回什么类型

在iCanvas里面看,这个问题就不存在了。

   double            X(double bar){return((double)W.Left_bar-bar)*W.dx_pix;}; //The X coordinate by the bar number. The bar number must be of type double, otherwise, the bar will be interpreted as time.
   double            X(datetime Time)                                         //The X coordinate by the time.
     { if(tester) return X((double)iBarShift(_Symbol,_Period,Time));
       else return X(wBarShift(Time,W.time,_Period));}
   double            Y(double Price) {if(W.dy_pix==0) W.dy_pix=1; return((W.Y_max-Price)/W.dy_pix); }; //The Y coordinate by the price.
   double            Price(int y)     {return (W.Y_max-y*(W.Y_max-W.Y_min)/W.Height);};                // Price by the Y coordinate
   double            Bar(double x) {return((double)W.Left_bar+1-x/(double)W.dx_pix);};                 // bar number by coordinate X                                                                      
   datetime          TimePos(double x)                                                                 // time by coordinate X 
     {
      double B=Bar(x);
      if (tester || W.BarsInWind == 0) iT[0]=iTime(_Symbol,_Period,(int)B);
      else {if(B<0 ) iT[0]=datetime(W.time[W.BarsInWind-1]-(long)B*PeriodSeconds());
      else if(B<W.Right_bar || B>W.Left_bar) iT[0]=iTime(_Symbol,_Period,(int)B);
      else iT[0]=W.time[W.BarsInWind-Floor(B)-1+(int)W.Right_bar];}
      return iT[0]+int((double)PeriodSeconds()*(1-B+(int)B));
     };
 
如鱼得水 :)
 
Vitaliy Kuznetsov:

但Kanvas的工作环境更好,你可以应用透明度,速度更快,代码占用的空间也更少))。

#property indicator_chart_window
#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164
#define  width 50                 
#define  height 10

#property indicator_buffers 0
#property indicator_plots   0

//+------------------------------------------------------------------+
int OnInit() {
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,
                 const int prev_calculated,
                 const int begin,
                 const double& price[]) {
   if (rates_total!=prev_calculated) DrawObj();
   return(rates_total);
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
   if(id == CHARTEVENT_CHART_CHANGE) DrawObj();
}
//+------------------------------------------------------------------+
void DrawObj() {

   double startPricePos = SymbolInfoDouble(_Symbol,SYMBOL_BID);
   int step_Pips = 50;
   Canvas.Erase(0x00FFFFFF);
   int x1 = W.Width/2;
   Canvas.CurentFont("Arial",10);
   for(int i=-19; i<=20; i++) {
      double stp = step_Pips*i*_Point;
      int y1 = (int)Canvas.Y(startPricePos + stp);
      Canvas.FillRectangle(x1,y1,x1+width, y1+ height, 0xA0ECE9D8);
      Canvas.Rectangle(x1,y1,x1+width, y1+ height, 0xDD807870);
      _CommXY(x1+5, y1, string(startPricePos + stp));
   }
   Canvas.Update();
}
//+------------------------------------------------------------------+



 
Vitaliy Kuznetsov:

谢谢你提供这种解决问题的办法。确实,渲染速度得到了改善。看来我得学习图书馆了。

我还想澄清以下细微差别。它用这种配方编译时有一个警告。

而用这个编译时没有警告,但速度有点慢。

什么是更正确的?)

把你的这段代码从循环中拿出来,在每个重绘事件的循环前调用一次。

 x=(int)(ChartGetInteger(chart_ID,CHART_WIDTH_IN_PIXELS,sub_window)/2);
   ChartXYToTimePrice(chart_ID,x,y,sub_window,time_pos_X_centr,price_pos_Y_tmp);         
         
   ChartTimePriceToXY(chart_ID,sub_window,time_pos_X_centr,price,x,y);

这比学习一些图书馆更复杂吗?

 
Aleksei Stepanenko:
如鱼得水 :)

PNB2))

 
Dmitry Fedoseev:

把这段代码从循环中拿出来,在每个重绘事件之前调用一次。

这真的比学习一些库更复杂吗?

这就是我所说的
我只是想知道--你能不能自己做,而不只是重复我的建议?
,其中两个很容易输出...
代码,谢谢。
,如果你不这样做,明天我醒来后自己写。但这样我就会说费多塞耶夫是个白痴。))

 
Nikolai Semko:

这就是我所说的
我只是想知道--你能不能自己做,而不只是重复我的建议?
,其中两个很容易输出...
代码,谢谢。
,如果你不这样做,明天我醒来后自己写。但这样我就会说费多塞耶夫是个白痴。))

你对我的想法让人难以置信))

 
Dmitry Fedoseev:

你对我的看法给我留下了难以置信的印象))。

少说话,多行动

 

谢谢你提供的例子!非常清晰,信息量大,而且不乏快速。

对象列表中Kanvas上的例子的所有图形看起来都是一个单一的对象。

当把鼠标悬停在个别图形项目 上时,是否可以得到不同的工具提示(tooltips)?

还是我可以为每个矩形创建一个单独的画布对象?这不会影响速度吗?

如果你有时间,我在等待你的回答,也许还有一个代码例子。