指标加载后,线过一会就会落后几根K线,如图
请朋友们看下,代码要如何改,才可以一直保持K线出来,指标线就出来呢?
/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: http://purebeam.biz
E-mail : purebeam@gmail.com
*/
#property copyright ""
#property link ""
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
extern int Periods = 20;
extern int Dev = 2;
double g_ibuf_84[];
double g_ibuf_88[];
double g_ibuf_92[];
double g_ibuf_96[];
int init() {
IndicatorBuffers(4);
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_NONE);
SetIndexStyle(2, DRAW_NONE);
SetIndexStyle(3, DRAW_NONE);
SetIndexBuffer(0, g_ibuf_92);
SetIndexBuffer(1, g_ibuf_84);
SetIndexBuffer(2, g_ibuf_88);
SetIndexBuffer(3, g_ibuf_96);
writetext("", "", 10, 10, Yellow, 10);
return (0);
}
int start() {
int bar = IndicatorCounted();
int limit = Bars - bar;
for (int i = 0; i < limit; i++) {
g_ibuf_84 = iBands(NULL, 0, Periods, Dev, 0, PRICE_CLOSE, MODE_UPPER, i);
g_ibuf_88 = iBands(NULL, 0, Periods, Dev, 0, PRICE_CLOSE, MODE_LOWER, i);
g_ibuf_96 = iBands(NULL, 0, Periods, Dev, 0, PRICE_CLOSE, MODE_MAIN, i);
g_ibuf_92 = (g_ibuf_84 - g_ibuf_88)/g_ibuf_96;
}
return (0);
}
void writetext(string a_name_0, string a_text_8, int a_x_16, int a_y_20, color a_color_24, int a_fontsize_28) {
ObjectDelete(a_name_0);
ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0);
ObjectSetText(a_name_0, a_text_8, a_fontsize_28, "Arial", a_color_24);
ObjectSet(a_name_0, OBJPROP_CORNER, 0);
ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_16);
ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_20);
}
|