指标描述:
可以计算28个货币对的均线斜率
指标源码:
#property indicator_chart_windowextern ENUM_TIMEFRAMES TimeFrame1 = PERIOD_H1;extern int MA1period = 45;extern ENUM_MA_METHOD MA1mode = MODE_LWMA;extern ENUM_APPLIED_PRICE MA1price = PRICE_CLOSE;extern int TF1_CandlesBack = 24;extern ENUM_TIMEFRAMES TimeFrame2 = PERIOD_M5;extern int MA2period = 45;extern ENUM_MA_METHOD MA2mode = MODE_LWMA;extern ENUM_APPLIED_PRICE MA2price = PRICE_CLOSE;extern int TF2_CandlesBack = 288;extern bool useATR = false;extern int ATRperiod = 20, Factor = 100;extern bool SortMinus = true;extern string Comment = "ea那些事";extern ENUM_BASE_CORNER Corner = CORNER_LEFT_UPPER;extern int x = 20, y = 100;extern color TrendUP = Lavender, TrendDN = DeepPink, TopColor = Gold; extern int HZgap = 110, VTgap = 16, FontSize = 9;extern string prefix = "", suffix = "", Pair1 = "EURUSD", Pair2 = "EURGBP", //"XAUUSD", Pair3 = "EURJPY", Pair4 = "GBPUSD", Pair5 = "GBPJPY", Pair6 = "AUDUSD", Pair7 = "USDCHF", Pair8 = "USDJPY", Pair9 = "USDCAD", Pair10 = "CHFJPY", Pair11 = "CADJPY", Pair12 = "NZDUSD"; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////string prefiX = Comment;void init() { Comment(""); clear();} void deinit() { Comment(""); clear(); } void clear() { string name; int obj_total = ObjectsTotal(); for (int i=obj_total-1; i>=0; i--) { name = ObjectName(i); if (StringFind(name, prefiX) == 0) ObjectDelete(name); } }////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void start(){ clear();string pairss[12];double currsma1[12], prevsma1[12], currsma2[12], prevsma2[12];double smadifftf1[12], smadiffpercenttf1[12], smadifftf2[12], smadiffpercenttf2[12];color trendslopecoltf1[12], trendslopecoltf2[12];double smadiffpercentarraytf1[12][2], smadiffpercentarraytf2[12][2];string tf1s, tf2s;//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Sleep(2000); pairss[0] = prefix + Pair1 + suffix; pairss[1] = prefix + Pair2 + suffix; pairss[2] = prefix + Pair3 + suffix; pairss[3] = prefix + Pair4 + suffix; pairss[4] = prefix + Pair5 + suffix; pairss[5] = prefix + Pair6 + suffix; pairss[6] = prefix + Pair7 + suffix; pairss[7] = prefix + Pair8 + suffix; pairss[8] = prefix + Pair9 + suffix; pairss[9] = prefix + Pair10 + suffix; pairss[10] = prefix + Pair11 + suffix; pairss[11] = prefix + Pair12 + suffix; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Time Frames to show if(TimeFrame1 == PERIOD_M1) tf1s = "M1"; if(TimeFrame1 == PERIOD_M5) tf1s = "M5"; if(TimeFrame1 == PERIOD_M15) tf1s = "M15"; if(TimeFrame1 == PERIOD_M30) tf1s = "M30"; if(TimeFrame1 == PERIOD_H1) tf1s = "H1"; if(TimeFrame1 == PERIOD_H4) tf1s = "H4"; if(TimeFrame1 == PERIOD_D1) tf1s = "Day"; if(TimeFrame1 == PERIOD_W1) tf1s = "Week"; if(TimeFrame1 == PERIOD_MN1) tf1s = "Month"; if(TimeFrame1 == PERIOD_CURRENT) tf1s = "Current"; if(TimeFrame2 == PERIOD_M1) tf2s = "M1"; if(TimeFrame2 == PERIOD_M5) tf2s = "M5"; if(TimeFrame2 == PERIOD_M15) tf2s = "M15"; if(TimeFrame2 == PERIOD_M30) tf2s = "M30"; if(TimeFrame2 == PERIOD_H1) tf2s = "H1"; if(TimeFrame2 == PERIOD_H4) tf2s = "H4"; if(TimeFrame2 == PERIOD_D1) tf2s = "Day"; if(TimeFrame2 == PERIOD_W1) tf2s = "Week"; if(TimeFrame2 == PERIOD_MN1) tf2s = "Month"; if(TimeFrame2 == PERIOD_CURRENT) tf2s = "Current"; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int counter1 = 0; while(counter1 < 12) { currsma1[counter1] = iMA(pairss[counter1],TimeFrame1,MA1period,0,MA1mode,MA1price,1); prevsma1[counter1] = iMA(pairss[counter1],TimeFrame1,MA1period,0,MA1mode,MA1price,TF1_CandlesBack); currsma2[counter1] = iMA(pairss[counter1],TimeFrame2,MA2period,0,MA2mode,MA2price,1); prevsma2[counter1] = iMA(pairss[counter1],TimeFrame2,MA2period,0,MA2mode,MA2price,TF2_CandlesBack);//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(SortMinus == false) { if(currsma1[counter1] >= prevsma1[counter1]) smadifftf1[counter1] = currsma1[counter1] - prevsma1[counter1]; if(currsma1[counter1] < prevsma1[counter1]) smadifftf1[counter1] = prevsma1[counter1] - currsma1[counter1]; if(currsma2[counter1] >= prevsma2[counter1]) smadifftf2[counter1] = currsma2[counter1] - prevsma2[counter1]; if(currsma2[counter1] < prevsma2[counter1]) smadifftf2[counter1] = prevsma2[counter1] - currsma2[counter1]; } else if(SortMinus == true) { if(currsma1[counter1] >= prevsma1[counter1]) smadifftf1[counter1] = currsma1[counter1] - prevsma1[counter1]; if(currsma1[counter1] < prevsma1[counter1]) smadifftf1[counter1] = - prevsma1[counter1] + currsma1[counter1]; if(currsma2[counter1] >= prevsma2[counter1]) smadifftf2[counter1] = currsma2[counter1] - prevsma2[counter1]; if(currsma2[counter1] < prevsma2[counter1]) smadifftf2[counter1] = - prevsma2[counter1] + currsma2[counter1]; } if(useATR == false) { int pipMult = 1000000; if(StringFind(pairss[counter1],"JPY",0) != -1) pipMult = 10000; smadiffpercenttf1[counter1] = (smadifftf1[counter1]/TF1_CandlesBack) * pipMult; smadiffpercenttf2[counter1] = (smadifftf2[counter1]/TF2_CandlesBack) * pipMult; } else if(useATR == true) { double tf1atr = iATR(pairss[counter1],TimeFrame1,ATRperiod,1); double tf2atr = iATR(pairss[counter1],TimeFrame2,ATRperiod,1); smadiffpercenttf1[counter1] = (smadifftf1[counter1]/tf1atr) * Factor; smadiffpercenttf2[counter1] = (smadifftf2[counter1]/tf2atr) * Factor; } trendslopecoltf1[counter1] = Orange; if(currsma1[counter1] > prevsma1[counter1]) trendslopecoltf1[counter1] = TrendUP; if(currsma1[counter1] < prevsma1[counter1]) trendslopecoltf1[counter1] = TrendDN; trendslopecoltf2[counter1] = Orange; if(currsma2[counter1] > prevsma2[counter1]) trendslopecoltf2[counter1] = TrendUP; if(currsma2[counter1] < prevsma2[counter1]) trendslopecoltf2[counter1] = TrendDN; smadiffpercentarraytf1[counter1][0] = smadiffpercenttf1[counter1]; smadiffpercentarraytf1[counter1][1] = counter1; smadiffpercentarraytf2[counter1][0] = smadiffpercenttf2[counter1]; smadiffpercentarraytf2[counter1][1] = counter1; counter1++; } ArraySort(smadiffpercentarraytf1,WHOLE_ARRAY,0,MODE_DESCEND); ///MODE_ASCEND); ArraySort(smadiffpercentarraytf2,WHOLE_ARRAY,0,MODE_DESCEND); Display(prefiX + "top12"+TimeFrame1, x+16,y); ObjectSetText(prefiX + "top12"+TimeFrame1, tf1s,FontSize,"Arial Black",TopColor); Display(prefiX + "top12under"+TimeFrame1,x,y); ObjectSetText(prefiX + "top12under"+TimeFrame1,"____________",FontSize,"Arial Black",TopColor); Display(prefiX + "top12"+TimeFrame2, x+HZgap+16,y); ObjectSetText(prefiX + "top12"+TimeFrame2, tf2s,FontSize,"Arial Black",TopColor); Display(prefiX + "top12under"+TimeFrame2,x+HZgap,y); ObjectSetText(prefiX + "top12under"+TimeFrame2,"____________",FontSize,"Arial Black",TopColor); int counterm = 0; while(counterm < 12) { int pair1 = smadiffpercentarraytf1[counterm][1]; int pair2 = smadiffpercentarraytf2[counterm][1]; Display(prefiX + "strongesttrends" + counterm + TimeFrame1, x,y + ((VTgap * counterm)-10) + (VTgap*2)); ObjectSetText(prefiX + "strongesttrends" + counterm + TimeFrame1,pairss[pair1] + " / " + DoubleToStr(smadiffpercenttf1[pair1],0),FontSize,"Verdana",trendslopecoltf1[pair1]); Display(prefiX + "strongesttrends" + counterm + TimeFrame2, x+HZgap,y + ((VTgap * counterm)-10) + (VTgap*2)); ObjectSetText(prefiX + "strongesttrends" + counterm + TimeFrame2,pairss[pair2] + " / " + DoubleToStr(smadiffpercenttf2[pair2],0),FontSize,"Verdana",trendslopecoltf2[pair2]); counterm++; } //return(0); } void Display(string name, int x2, int y2) { ObjectCreate(name, OBJ_LABEL, 0, 0, 0); ObjectSet(name, OBJPROP_CORNER, Corner); ObjectSet(name, OBJPROP_XDISTANCE, x2); ObjectSet(name, OBJPROP_YDISTANCE, y2); ObjectSet(name, OBJPROP_BACK, FALSE); }
效果图:
▼想了解更详细的信息,请扫码联系我们▼
公众号
小编个人微信
版权声明:本文为weixin_35043331原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。