[MT4指标]MT4指标怎样取时点的数值?
请教各位怎样把指标里红色字“P = (yesterday_high + yesterday_low + yesterday_close) / 3”改为
“P = (yesterday_high + yesterday_low + yesterday_close + 昨天15:59的收盘价) / 4。
这个指标希望可以在任何时间周期内使用。
#property indicator_chart_window double day_high=0; double day_low=0; double yesterday_high=0; double yesterday_open=0; double yesterday_low=0; double yesterday_close=0; double today_open=0; double today_high=0; double today_low=0; double P=0; double Q=0; double R1,R2,R3; double S1,S2,S3; double rates_d1[2][6]; int init() { R1=0; R2=0; S1=0; S2=0; return(0); } int deinit() { ObjectsDeleteAll(); return(0); } int start() { ArrayCopyRates(rates_d1, Symbol(), PERIOD_D1); int i; i=1;//you can change the value of i if you want draw pivot of before //the first dimension of arry rates_d1 is :today 0, yesterday 1,the day before yesterday 2 and so on //the second dimension of arry rates_d10 - time,1 - open,2 - low,3 - high,4 - close,5 - volume. yesterday_close = rates_d1[4]; yesterday_open = rates_d1[1]; today_open = rates_d1[i-1][1]; yesterday_high = rates_d1[3]; day_high = rates_d1[i-1][3]; yesterday_low = rates_d1[2]; day_low = rates_d1[i-1][2]; //---- Calculate Pivots P = (yesterday_high + yesterday_low + yesterday_close) / 3;
R1 = (2*P)-yesterday_low; S1 = (2*P)-yesterday_high; R2 = P+(yesterday_high - yesterday_low); S2 = P-(yesterday_high - yesterday_low); R3 = (2*P)+(yesterday_high-(2*yesterday_low)); S3 = (2*P)-((2* yesterday_high)-yesterday_low); Comment("Yesterday " ,TimeToStr(rates_d1[0]), "\n", "Yesterdays High= ",yesterday_high,"Yesterdays Low= ",yesterday_low,"Close= ",yesterday_close ); //----Draw Pivot Lines SetLevel("R1", R1, Blue); SetLevel("R2", R2, Blue); SetLevel("Pivot", P, Magenta); SetLevel("S1", S1, Red); SetLevel("S2", S2, Red); SetLevel("R3", R3, Blue); SetLevel("S3", S3, Red); return(0); } void SetLevel(string text, double level, color col1) { string labelname= text + " Label"; string linename= text + " Line"; if (ObjectFind(labelname) != 0) { ObjectCreate(labelname, OBJ_TEXT, 0, Time[20], level); ObjectSetText(labelname, " " + text, 8, "Arial", White); } else { ObjectMove(labelname, 0, Time[20], level); } if (ObjectFind(linename) != 0) { ObjectCreate(linename, OBJ_HLINE, 0, Time[40], level); ObjectSet(linename, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(linename, OBJPROP_COLOR, col1); } else { ObjectMove(linename, 0, Time[40], level); } }
“P = (yesterday_high + yesterday_low + yesterday_close + 昨天15:59的收盘价) / 4。
这个指标希望可以在任何时间周期内使用。
#property indicator_chart_window double day_high=0; double day_low=0; double yesterday_high=0; double yesterday_open=0; double yesterday_low=0; double yesterday_close=0; double today_open=0; double today_high=0; double today_low=0; double P=0; double Q=0; double R1,R2,R3; double S1,S2,S3; double rates_d1[2][6]; int init() { R1=0; R2=0; S1=0; S2=0; return(0); } int deinit() { ObjectsDeleteAll(); return(0); } int start() { ArrayCopyRates(rates_d1, Symbol(), PERIOD_D1); int i; i=1;//you can change the value of i if you want draw pivot of before //the first dimension of arry rates_d1 is :today 0, yesterday 1,the day before yesterday 2 and so on //the second dimension of arry rates_d10 - time,1 - open,2 - low,3 - high,4 - close,5 - volume. yesterday_close = rates_d1[4]; yesterday_open = rates_d1[1]; today_open = rates_d1[i-1][1]; yesterday_high = rates_d1[3]; day_high = rates_d1[i-1][3]; yesterday_low = rates_d1[2]; day_low = rates_d1[i-1][2]; //---- Calculate Pivots P = (yesterday_high + yesterday_low + yesterday_close) / 3;
R1 = (2*P)-yesterday_low; S1 = (2*P)-yesterday_high; R2 = P+(yesterday_high - yesterday_low); S2 = P-(yesterday_high - yesterday_low); R3 = (2*P)+(yesterday_high-(2*yesterday_low)); S3 = (2*P)-((2* yesterday_high)-yesterday_low); Comment("Yesterday " ,TimeToStr(rates_d1[0]), "\n", "Yesterdays High= ",yesterday_high,"Yesterdays Low= ",yesterday_low,"Close= ",yesterday_close ); //----Draw Pivot Lines SetLevel("R1", R1, Blue); SetLevel("R2", R2, Blue); SetLevel("Pivot", P, Magenta); SetLevel("S1", S1, Red); SetLevel("S2", S2, Red); SetLevel("R3", R3, Blue); SetLevel("S3", S3, Red); return(0); } void SetLevel(string text, double level, color col1) { string labelname= text + " Label"; string linename= text + " Line"; if (ObjectFind(labelname) != 0) { ObjectCreate(labelname, OBJ_TEXT, 0, Time[20], level); ObjectSetText(labelname, " " + text, 8, "Arial", White); } else { ObjectMove(labelname, 0, Time[20], level); } if (ObjectFind(linename) != 0) { ObjectCreate(linename, OBJ_HLINE, 0, Time[40], level); ObjectSet(linename, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(linename, OBJPROP_COLOR, col1); } else { ObjectMove(linename, 0, Time[40], level); } }