Trend Scanner
Created at 13 May 2016, 19:58
JE
Trend Scanner
13 May 2016, 19:58
Hi,
I am a total newbie regarding coding, but I've tried as much as I could.
I did write, or rather rewrite, some indicators to my liking, but with this one I have huge Trouble.
I got two indicators.
The one already coded for cTrader does not do what I want exactly. And the other one is for MT4.
What I would like is to have the MT4 one, which works with 3SMA's to work on cTrader.
I tried online converter and I tried to do it myself. Obviously I have failed :D
This is the MT4 code. Would be cool if someone can rewrite this for me.
It doesn't have to look 100% like it, I'm more interested in the function, rather than looks.
Thanks
/* Generated by EX4-TO-MQ4 decompiler V4.0.224.1 [] Website: http://purebeam.biz E-mail : purebeam@gmail.com */ #property copyright "Copyright 2008, www.LearnForexLive.com" #property link "http://www.LearnForexLive.com" #property indicator_separate_window extern color colorDown = Red; extern color colorFlat = DimGray; extern color colortext = White; extern color colorUp = Lime; extern int horizontal_space = 40; extern int vertical_space = 20; extern bool MN = FALSE; extern bool W1 = TRUE; extern bool D1 = TRUE; extern bool H4 = TRUE; extern bool H1 = TRUE; extern bool M30 = TRUE; extern bool M15 = TRUE; extern bool M5 = TRUE; extern bool M1 = FALSE; int gi_136 = 40; int gi_140 = 20; int gi_144 = 40; int gi_148 = 5; int gi_152 = 1; extern string Sym1 = "EURUSD"; extern string Sym2 = "GBPUSD"; extern string Sym3 = "USDJPY"; extern string Sym4 = "USDCHF"; extern string Sym5 = "USDCAD"; extern string Sym6 = "AUDUSD"; extern string Sym7 = "NZDUSD"; extern string Sym8 = "EURJPY"; extern string Sym9 = "EURGBP"; extern string Sym10 = "GBPJPY"; extern string Sym11 = "GBPCHF"; extern string Sym12 = "CADJPY"; extern string Sym13 = "EURCHF"; extern string Sym14 = "CHFJPY"; extern string Sym15 = "GBPCAD"; extern string Sym16 = "EURCAD"; extern string Sym17 = "AUDJPY"; extern string Sym18 = "EURAUD"; extern string Sym19 = "GBPAUD"; extern string Sym20 = "NZDCAD"; extern string Sym21 = "NZDJPY"; extern string Sym22 = "NZDCHF"; extern string Sym23 = "EURNZD"; extern string Sym24 = "AUDNZD"; extern string Sym25 = "CADCHF"; extern string Sym26 = "AUDCHF"; extern string Sym27 = "AUDCAD"; extern string Sym28 = "GBPNZD"; int gi_380; int gi_384; int gi_388; int gi_392; string gs_396; string gs_404; string gs_412; string g_name_420; string gsa_428[30]; int gi_432 = 28; int init() { gs_396 = "Trend Scanner"; IndicatorShortName(gs_396); gsa_428[0] = Sym1; gsa_428[1] = Sym2; gsa_428[2] = Sym3; gsa_428[3] = Sym4; gsa_428[4] = Sym5; gsa_428[5] = Sym6; gsa_428[6] = Sym7; gsa_428[7] = Sym8; gsa_428[8] = Sym9; gsa_428[9] = Sym10; gsa_428[10] = Sym11; gsa_428[11] = Sym12; gsa_428[12] = Sym13; gsa_428[13] = Sym14; gsa_428[14] = Sym15; gsa_428[15] = Sym16; gsa_428[16] = Sym17; gsa_428[17] = Sym18; gsa_428[18] = Sym19; gsa_428[19] = Sym20; gsa_428[20] = Sym21; gsa_428[21] = Sym22; gsa_428[22] = Sym23; gsa_428[23] = Sym24; gsa_428[24] = Sym25; gsa_428[25] = Sym26; gsa_428[26] = Sym27; gsa_428[27] = Sym28; gsa_428[28] = ""; gsa_428[29] = ""; return (0); } void deinit() { cleanup(); } int start() { cleanup(); gi_380 = 35; gi_384 = horizontal_space; for (int l_index_0 = 0; l_index_0 < gi_432; l_index_0++) { if (gsa_428[l_index_0] != "") { Calc(gsa_428[l_index_0], gi_380); DrawText(gsa_428[l_index_0], gi_380, 1); gi_380 += gi_384; } } return (0); } void Calc(string as_0, int ai_8) { RefreshRates(); gi_388 = 20; gi_392 = 19; gs_404 = StringSubstr(Symbol(), 6, 1); if (StringFind(AccountCompany(), "Interbank") == 0 && gs_404 == "m" == TRUE) gs_412 = as_0 + "m"; else gs_412 = as_0; int li_12 = 0; if (M1 == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_M1); if (li_12 > 0) DrawObject(as_0 + "m1", ai_8, gi_388, colorUp); if (li_12 < 0) DrawObject(as_0 + "m1", ai_8, gi_388, colorDown); if (li_12 == 0) DrawObject(as_0 + "m1", ai_8, gi_388, colorFlat); DrawText2("M1", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } if (M5 == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_M5); if (li_12 > 0) DrawObject(as_0 + "m5", ai_8, gi_388, colorUp); if (li_12 < 0) DrawObject(as_0 + "m5", ai_8, gi_388, colorDown); if (li_12 == 0) DrawObject(as_0 + "m5", ai_8, gi_388, colorFlat); DrawText2("M5", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } if (M15 == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_M15); if (li_12 > 0) DrawObject(as_0 + "m15", ai_8, gi_388, colorUp); if (li_12 < 0) DrawObject(as_0 + "m15", ai_8, gi_388, colorDown); if (li_12 == 0) DrawObject(as_0 + "m15", ai_8, gi_388, colorFlat); DrawText2("M15", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } if (M30 == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_M30); if (li_12 > 0) DrawObject(as_0 + "m30", ai_8, gi_388, colorUp); if (li_12 < 0) DrawObject(as_0 + "m30", ai_8, gi_388, colorDown); if (li_12 == 0) DrawObject(as_0 + "m30", ai_8, gi_388, colorFlat); DrawText2("M30", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } if (H1 == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_H1); if (li_12 > 0) DrawObject(as_0 + "h1", ai_8, gi_388, colorUp); if (li_12 < 0) DrawObject(as_0 + "h1", ai_8, gi_388, colorDown); if (li_12 == 0) DrawObject(as_0 + "h1", ai_8, gi_388, colorFlat); DrawText2("H1", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } if (H4 == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_H4); if (li_12 > 0) DrawObject(as_0 + "h4", ai_8, gi_388, colorUp); if (li_12 < 0) DrawObject(as_0 + "h4", ai_8, gi_388, colorDown); if (li_12 == 0) DrawObject(as_0 + "h4", ai_8, gi_388, colorFlat); DrawText2("H4", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } if (D1 == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_D1); if (li_12 > 0) DrawObject(as_0 + "d1", ai_8, gi_388, colorUp); if (li_12 < 0) DrawObject(as_0 + "d1", ai_8, gi_388, colorDown); if (li_12 == 0) DrawObject(as_0 + "d1", ai_8, gi_388, colorFlat); DrawText2("D1", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } if (W1 == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_W1); if (li_12 > 0) DrawObject(as_0 + "w1", ai_8, gi_388, colorUp); if (li_12 < 0) DrawObject(as_0 + "w1", ai_8, gi_388, colorDown); if (li_12 == 0) DrawObject(as_0 + "w1", ai_8, gi_388, colorFlat); DrawText2("W1", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } if (MN == TRUE) { li_12 = CalcTrend(gs_412, PERIOD_MN1); if (li_12 > 0) DrawObject(as_0 + "mn", ai_8, gi_388, colorUp);Alert("Buy",PERIOD_MN1,Symbol()); if (li_12 < 0) DrawObject(as_0 + "mn", ai_8, gi_388, colorDown);Alert("Sell",PERIOD_MN1,Symbol()); if (li_12 == 0) DrawObject(as_0 + "mn", ai_8, gi_388, colorFlat); DrawText2("MN", gi_392); gi_388 += vertical_space; gi_392 += vertical_space; } } void DrawObject(string a_name_0, int a_x_8, int a_y_12, color a_color_16) { a_name_0 = "HoF" + a_name_0; if (ObjectFind(a_name_0) == -1) ObjectCreate(a_name_0, OBJ_LABEL, WindowFind(gs_396), 0, 0); ObjectSet(a_name_0, OBJPROP_CORNER, 2); ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8); ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12); ObjectSet(a_name_0, OBJPROP_COLOR, a_color_16); ObjectSetText(a_name_0, "_", 44, "Arial", a_color_16); } void DrawText(string a_text_0, int ai_8, int a_y_12) { g_name_420 = "HoF" + a_text_0 + "text"; if (ObjectFind(g_name_420) == -1) ObjectCreate(g_name_420, OBJ_LABEL, WindowFind(gs_396), 0, 0); ObjectSet(g_name_420, OBJPROP_CORNER, 2); ObjectSet(g_name_420, OBJPROP_XDISTANCE, ai_8 - 1); ObjectSet(g_name_420, OBJPROP_YDISTANCE, a_y_12); ObjectSet(g_name_420, OBJPROP_COLOR, colortext); ObjectSetText(g_name_420, a_text_0, 6, "Arial", colortext); } void DrawText2(string a_text_0, int a_y_8) { g_name_420 = "HoF" + a_text_0 + "text"; if (ObjectFind(g_name_420) == -1) ObjectCreate(g_name_420, OBJ_LABEL, WindowFind(gs_396), 0, 0); ObjectSet(g_name_420, OBJPROP_CORNER, 2); ObjectSet(g_name_420, OBJPROP_XDISTANCE, 5); ObjectSet(g_name_420, OBJPROP_YDISTANCE, a_y_8); ObjectSet(g_name_420, OBJPROP_COLOR, colortext); ObjectSetText(g_name_420, a_text_0, 7, "Arial", colortext); } void cleanup() { string l_name_4; for (int li_0 = ObjectsTotal() - 1; li_0 >= 0; li_0--) { l_name_4 = ObjectName(li_0); if (StringFind(l_name_4, "HoF") == 0) ObjectDelete(l_name_4); } } int CalcTrend(string a_symbol_0, int a_timeframe_8) { double ld_40; double l_ima_48; int li_ret_12 = 0; int li_16 = 0; int li_20 = 0; int li_24 = 0; int li_28 = 0; int li_32 = 0; int l_datetime_36 = iTime(a_symbol_0, a_timeframe_8, 0); if (l_datetime_36 == 0) { Print("No history for " + a_symbol_0 + " Period=" + a_timeframe_8); return (li_ret_12); } for (li_16 = li_20; li_16 <= gi_136 + li_20; li_16++) { ld_40 = iMA(a_symbol_0, a_timeframe_8, 30, 0, MODE_SMA, PRICE_CLOSE, li_16); l_ima_48 = iMA(a_symbol_0, a_timeframe_8, 50, 0, MODE_SMA, PRICE_CLOSE, li_16); if (ld_40 > l_ima_48 && li_24 == 0) li_24 = 1; if (ld_40 < l_ima_48 && li_24 == 1) { li_24 = 0; break; } if (ld_40 < l_ima_48 && li_24 == 0) li_24 = -1; if (ld_40 > l_ima_48 && li_24 == -1) { li_24 = 0; break; } } for (li_16 = li_20; li_16 <= gi_140 + li_20; li_16++) { ld_40 = iMA(a_symbol_0, a_timeframe_8, 50, 0, MODE_SMA, PRICE_CLOSE, li_16); l_ima_48 = iMA(a_symbol_0, a_timeframe_8, 100, 0, MODE_SMA, PRICE_CLOSE, li_16); if (ld_40 > l_ima_48 && li_28 == 0) li_28 = 1; if (ld_40 < l_ima_48 && li_28 == 1) { li_28 = 0; break; } if (ld_40 < l_ima_48 && li_28 == 0) li_28 = -1; if (ld_40 > l_ima_48 && li_28 == -1) { li_28 = 0; break; } } for (li_16 = li_20; li_16 <= gi_144 + li_20; li_16++) { ld_40 = iClose(a_symbol_0, a_timeframe_8, li_16); l_ima_48 = iMA(a_symbol_0, a_timeframe_8, 100, 0, MODE_SMA, PRICE_CLOSE, li_16); if (ld_40 > l_ima_48 && li_32 == 0) li_32 = 1; if (ld_40 < l_ima_48 && li_32 == 1) { li_32 = 0; break; } if (ld_40 < l_ima_48 && li_32 == 0) li_32 = -1; if (ld_40 > l_ima_48 && li_32 == -1) { li_32 = 0; break; } } if (li_24 == 1 && li_28 == 1 && li_32 == 1) { if (iClose(a_symbol_0, a_timeframe_8, li_20) > iMA(a_symbol_0, a_timeframe_8, 50, 0, MODE_SMA, PRICE_CLOSE, li_20) && iMA(a_symbol_0, a_timeframe_8, 30, 0, MODE_SMA, PRICE_CLOSE, li_20) > iMA(a_symbol_0, a_timeframe_8, 30, 0, MODE_SMA, PRICE_CLOSE, gi_148) && iMA(a_symbol_0, a_timeframe_8, 50, 0, MODE_SMA, PRICE_CLOSE, li_20) > iMA(a_symbol_0, a_timeframe_8, 50, 0, MODE_SMA, PRICE_CLOSE, gi_152)) li_ret_12 = 1; } if (li_24 == -1 && li_28 == -1 && li_32 == -1) { if (iClose(a_symbol_0, a_timeframe_8, li_20) < iMA(a_symbol_0, a_timeframe_8, 50, 0, MODE_SMA, PRICE_CLOSE, li_20) && iMA(a_symbol_0, a_timeframe_8, 30, 0, MODE_SMA, PRICE_CLOSE, li_20) < iMA(a_symbol_0, a_timeframe_8, 30, 0, MODE_SMA, PRICE_CLOSE, gi_148) && iMA(a_symbol_0, a_timeframe_8, 50, 0, MODE_SMA, PRICE_CLOSE, li_20) < iMA(a_symbol_0, a_timeframe_8, 50, 0, MODE_SMA, PRICE_CLOSE, gi_152)) li_ret_12 = -1; } return (li_ret_12); }