//+------------------------------------------------------------------+ //| MyStrategy_Scanner.mq4 | //| Copyright 2020, RO IT Consulting | //| https://www.OseiWeb.com | //+------------------------------------------------------------------+ #property copyright "Copyright" #property link "https://www." #property version "1.00" #property indicator_chart_window #property description "Romans 1:16 - For I am not ashamed of the gospel," #property description " " #property description "Pairs: Any | Timeframe: Any" #resource "\\Indicators\\Guass.ex5" #resource "\\Indicators\\AdaptiveTrendFlow.ex5" // #property icon "../../Files/logo.ico" //---- indicator version number //+-----------------------------------+ //| declaration of constants | //+-----------------------------------+ #define RESET 0 // The constant for returning the indicator recalculation command to the terminal #define INDTOTAL 6 // The constant for the number of displayed indicators #define OP_BUY 0 #define OP_SELL 1 #define OBJPROP_TIME1 300 #define OBJPROP_PRICE1 301 #define OBJPROP_TIME2 302 #define OBJPROP_PRICE2 303 #define OBJPROP_TIME3 304 #define OBJPROP_PRICE3 305 //--- #define OBJPROP_RAY 310 #define OBJPROP_FIBOLEVELS 200 datetime lastalert = 0; datetime time[]; //+-----------------------------------+ //---- number of indicator buffers #property indicator_chart_window #property indicator_buffers 11 #property indicator_plots 11 #property indicator_type1 DRAW_ARROW #property indicator_width1 3 #property indicator_color1 clrWhite #property indicator_type2 DRAW_ARROW #property indicator_width2 3 #property indicator_color2 clrWhite #property indicator_type3 DRAW_LINE #property indicator_color3 DeepSkyBlue #property indicator_style3 STYLE_SOLID #property indicator_type4 DRAW_LINE #property indicator_color4 Tomato #property indicator_style4 STYLE_SOLID #property indicator_type5 DRAW_LINE #property indicator_color5 DeepSkyBlue #property indicator_style5 STYLE_SOLID #property indicator_type6 DRAW_LINE #property indicator_color6 Tomato #property indicator_style6 STYLE_SOLID #property indicator_type7 DRAW_LINE #property indicator_color7 DeepSkyBlue #property indicator_style7 STYLE_SOLID #property indicator_type8 DRAW_LINE #property indicator_color8 Tomato #property indicator_style8 STYLE_SOLID #property indicator_type9 DRAW_LINE #property indicator_color9 Lime #property indicator_style9 STYLE_SOLID #property indicator_type10 DRAW_LINE #property indicator_color10 DeepSkyBlue #property indicator_style10 STYLE_SOLID #property indicator_type11 DRAW_LINE #property indicator_color11 Tomato #property indicator_style11 STYLE_SOLID #property indicator_type12 DRAW_LINE #property indicator_color12 Lime #property indicator_style12 STYLE_SOLID #property indicator_type13 DRAW_LINE #property indicator_color13 DeepSkyBlue #property indicator_style13 STYLE_SOLID #property indicator_type14 DRAW_LINE #property indicator_color14 Tomato #property indicator_style14 STYLE_SOLID #property indicator_type15 DRAW_LINE #property indicator_color15 Lime #property indicator_style15 STYLE_SOLID enum enuSignalBar { Current = 0, Close = 1, Next = 2, }; //+-----------------------------------+ //| INDICATOR INPUT PARAMETERS | //+-----------------------------------+ input string ——————————————0—————————————— = "————————| Visual :"; input bool ShowSingleArrow = false; // Show Single Signal input bool ShowMA = false; // Show MAs input bool ShowGuass = true; // Show Guass input bool ShowAdaptiveTrendFlow = false; // Show AdaptiveTrendFlow input enuSignalBar SignalBar = 1; // Signal Bar input bool ShowBuy = true; // Buy Only input bool ShowSell = true; // Sell Only bool ShowNewsDashboard = false; // Show News Dashboard bool ShowPZLopez = false; // Show PZ-Lopez bool ShowSuperBollingerTrend = false; // Show SuperBollingerTrend input string ————————————1—————————————— = "————————| Guass:"; input bool GuassON = true; // Guass input bool show_strength = false; // Show Trend Strength input int len = 20; // Lenght enum Type { type1 = 1, // AVG type2 = 2, // MEADIAN type3 = 3, // MODE }; input Type mode = type1; // Type input double distance = 1; // Distance input bool show_retest = false; // Retest Signals input bool GuassDirectiononly = false; // Use As Trend Direction input string ————————————2—————————————— = "————————| AdaptiveTrendFlow:"; input bool AdaptiveTrendFlowON = true; // AdaptiveTrendFlow input int InpLength = 10; // Main Length input int InpSmoothLen = 14; // Smoothing Length input double InpSensitivity = 2.0; // Sensitivity input bool InpShowSignals = true; // Show Signals input int InpMaxBars = 2000; // Max Bars input bool UseRetest = false; // Use Retest input bool AdaptiveTrendFlowDirectiononly = false; // Use As Trend Direction input string ————————————3—————————————— = "————————| MA Selection :"; enum enuMADirection { MA1 = 1, // Single MA MA2 = 2, // Double MA MA3 = 3, // Triple MA MACandles = 4, // 4 MA Candles }; input bool TripleMAON = false; // Use MA input enuMADirection MADirection = 1; // MA Strategy input bool MADirectiononly = false; // Use MA As Trend Direction Only input string ————————————4—————————————— = "————————| Triple MA :"; input group "————————| Triple MA 1 Settings :"; input int TMA_period1 = 5; input int TMA_Shift1 = 0; input ENUM_MA_METHOD TMA_Method1 = MODE_EMA; input ENUM_APPLIED_PRICE TMA_Price1 = PRICE_CLOSE; input color TMA_Color1 = clrRed; input group "————————| MA 2 Settings :"; input int TMA_period2 = 8; input int TMA_Shift2 = 0; input ENUM_MA_METHOD TMA_Method2 = MODE_EMA; input ENUM_APPLIED_PRICE TMA_Price2 = PRICE_CLOSE; input color TMA_Color2 = clrGold; input group "————————| MA 3 Settings :"; input int TMA_period3 = 13; input int TMA_Shift3 = 0; input ENUM_MA_METHOD TMA_Method3 = MODE_EMA; input ENUM_APPLIED_PRICE TMA_Price3 = PRICE_CLOSE; input color TMA_Color3 = clrWhite; input string ——————————————5—————————————— = "————————| Double MA :"; input group "————————| Double MA 1 Settings :"; input int DMA_period1 = 5; input int DMA_Shift1 = 0; input ENUM_MA_METHOD DMA_Method1 = MODE_EMA; input ENUM_APPLIED_PRICE DMA_Price1 = PRICE_CLOSE; input color DMA_Color1 = clrRed; input group "————————| MA 2 Settings :"; input int DMA_period2 = 20; input int DMA_Shift2 = 0; input ENUM_MA_METHOD DMA_Method2 = MODE_EMA; input ENUM_APPLIED_PRICE DMA_Price2 = PRICE_CLOSE; input color DMA_Color2 = clrGold; input string ——————————————6—————————————— = "————————| Single MA :"; input group "————————| single MA 1 Settings :"; input int SMA_period1 = 50; input int SMA_Shift1 = 0; input ENUM_MA_METHOD SMA_Method1 = MODE_EMA; input ENUM_APPLIED_PRICE SMA_Price1 = PRICE_CLOSE; input color SMA_Color1 = clrRed; input string ——————————————07—————————————— = "————————| Notification :"; input bool AlertOn = true; // Computer Alert input bool NotificationOn = false; // Mobile Alert input bool EmailOn = false; // Email Alert input string ——————————————8—————————————— = "————————| TP and SL :"; input bool ShowSLTP = false; // Show TPs and SL input double StopLoss = 10000; input double TakeProfit1 = 5000; // TakeProfit int barscount = 1000; int displ = 10; // Arrow displacement //+-----------------------------------+ //---- Declaration of a variable for storing the indicator initialization result bool Init; //---- Declaration of integer variables of data starting point int min_rates_total; int MaHandleh, MaHandlel; int MaHandleo, MaHandlec; int MaHandle1, MaHandle2, MaHandle3; datetime lastime = 0; double BufferBuy[], BufferSell[]; double mma1[], mma2[], mma3[]; double MAH[], MAL[], MAO[], MAC[]; int lastype = 0; int lastsignal; bool oncerun = true; double ma1[], ma2[], ma3[]; double ExtOBuffer[]; double ExtHBuffer[]; double ExtLBuffer[]; double ExtCBuffer[]; double ExtColorBuffer[]; int Heikenashihandle; double PZtrend[]; double PZcolor[]; double up[], down[], zigzagup[], zigzagdn[], trend[]; double TPLine[]; double SLLine[]; double avgLine[]; double upperTrendline[]; double LowerTrendline[]; double BasisBuffer[]; double BullLevelBuffer[]; double BearLevelBuffer[]; //+------------------------------------------------------------------+ //| Getting string time frame | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //---- return (StringSubstr(EnumToString(timeframe), 7, -1)); //---- } //+------------------------------------------------------------------+ //| MACD indicator initialization function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of data starting point min_rates_total = 3; Init = true; int StartBars = 9; //---- Initialization of variables int x; x = 0; SetIndexBuffer(x + 0, BufferBuy, INDICATOR_DATA); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, StartBars); PlotIndexSetString(0, PLOT_LABEL, "Buy"); PlotIndexSetInteger(0, PLOT_ARROW, 233); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0); ArraySetAsSeries(BufferBuy, true); SetIndexBuffer(x + 1, BufferSell, INDICATOR_DATA); PlotIndexSetInteger(x + 1, PLOT_DRAW_BEGIN, StartBars); PlotIndexSetString(x + 1, PLOT_LABEL, "Sell"); PlotIndexSetInteger(x + 1, PLOT_ARROW, 234); PlotIndexSetDouble(x + 1, PLOT_EMPTY_VALUE, 0); ArraySetAsSeries(BufferSell, true); x += 2; SetIndexBuffer(x + 0, avgLine, INDICATOR_DATA); // Average SetIndexBuffer(x + 1, upperTrendline, INDICATOR_DATA); // Upper Trendline SetIndexBuffer(x + 2, LowerTrendline, INDICATOR_DATA); // Lower Trendline ArraySetAsSeries(avgLine, true); ArraySetAsSeries(upperTrendline, true); ArraySetAsSeries(LowerTrendline, true); if (ShowGuass) { PlotIndexSetInteger(x, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(x + 1, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(x + 2, PLOT_DRAW_TYPE, DRAW_LINE); } else { PlotIndexSetInteger(x, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetInteger(x + 1, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetInteger(x + 2, PLOT_DRAW_TYPE, DRAW_NONE); } x += 3; SetIndexBuffer(x + 0, BasisBuffer, INDICATOR_DATA); SetIndexBuffer(x + 1, BullLevelBuffer, INDICATOR_DATA); SetIndexBuffer(x + 2, BearLevelBuffer, INDICATOR_DATA); ArraySetAsSeries(BasisBuffer, true); ArraySetAsSeries(BullLevelBuffer, true); ArraySetAsSeries(BearLevelBuffer, true); if (ShowAdaptiveTrendFlow) { PlotIndexSetInteger(x, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(x + 1, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(x + 2, PLOT_DRAW_TYPE, DRAW_LINE); } else { PlotIndexSetInteger(x, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetInteger(x + 1, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetInteger(x + 2, PLOT_DRAW_TYPE, DRAW_NONE); } x += 3; if (ShowMA) { SetIndexBuffer(x, mma1, INDICATOR_DATA); SetIndexBuffer(x + 1, mma2, INDICATOR_DATA); SetIndexBuffer(x + 2, mma3, INDICATOR_DATA); if (MADirection == 3) { PlotIndexSetInteger(x + 0, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(x + 1, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(x + 2, PLOT_DRAW_TYPE, DRAW_LINE); } if (MADirection == 2) { PlotIndexSetInteger(x + 1, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(x + 2, PLOT_DRAW_TYPE, DRAW_LINE); } if (MADirection == 1) { PlotIndexSetInteger(x + 2, PLOT_DRAW_TYPE, DRAW_LINE); } PlotIndexSetInteger(x + 0, PLOT_LINE_COLOR, TMA_Color1); PlotIndexSetInteger(x + 1, PLOT_LINE_COLOR, TMA_Color2); PlotIndexSetInteger(x + 2, PLOT_LINE_COLOR, TMA_Color3); } else { SetIndexBuffer(x + 0, mma1, INDICATOR_CALCULATIONS); SetIndexBuffer(x + 1, mma2, INDICATOR_CALCULATIONS); SetIndexBuffer(x + 2, mma3, INDICATOR_CALCULATIONS); PlotIndexSetInteger(x + 0, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetInteger(x + 1, PLOT_DRAW_TYPE, DRAW_NONE); PlotIndexSetInteger(x + 2, PLOT_DRAW_TYPE, DRAW_NONE); } PlotIndexSetString(x + 0, PLOT_LABEL, "ma1"); PlotIndexSetString(x + 1, PLOT_LABEL, "ma2"); PlotIndexSetString(x + 2, PLOT_LABEL, "ma3"); PlotIndexSetDouble(x + 0, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(x + 1, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(x + 2, PLOT_EMPTY_VALUE, EMPTY_VALUE); ArraySetAsSeries(mma1, true); ArraySetAsSeries(mma2, true); ArraySetAsSeries(mma3, true); MaHandle1 = iMA(NULL, 0, TMA_period1, TMA_Shift1, TMA_Method1, TMA_Price1); MaHandle2 = iMA(NULL, 0, TMA_period2, TMA_Shift2, TMA_Method2, TMA_Price2); MaHandle3 = iMA(NULL, 0, TMA_period3, TMA_Shift3, TMA_Method3, TMA_Price3); if (MADirection == 2) { MaHandle2 = iMA(NULL, 0, DMA_period1, DMA_Shift1, DMA_Method1, DMA_Price1); MaHandle3 = iMA(NULL, 0, DMA_period2, DMA_Shift2, DMA_Method2, DMA_Price2); } if (MADirection == 1) { MaHandle3 = iMA(NULL, 0, SMA_period1, SMA_Shift1, SMA_Method1, SMA_Price1); } IndicatorSetInteger(INDICATOR_DIGITS, Digits()); EventSetMillisecondTimer(100); //------------------------------------------------------------------------------------------- //------------------------------------------------news end------------------------------------------- //------------------------------------------------------------------------------------------- //---- end of initialization } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ChartRedraw(0); } //+------------------------------------------------------------------+ //| MACD iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, // amount of history in bars at the current tick const int prev_calculated, // amount of history in bars at the previous tick const datetime &Time[], const double &Open[], const double &High[], const double &Low[], const double &Close[], const long &Tick_Volume[], const long &Volume[], const int &Spread[]) { //---- declaration of local variables int to_copy, limit; //---- calculation of the starting number limit for the bar recalculation loop if (prev_calculated > rates_total || prev_calculated <= 0) // checking for the first start of the indicator calculation limit = rates_total - min_rates_total - 1; // starting index for the calculation of all bars else limit = rates_total - prev_calculated; // starting index for calculation of new bars only //---- indexing elements in arrays as timeseries to_copy = limit - min_rates_total - 1; if (to_copy < barscount) to_copy = barscount; double PLTSIGNAL[], BARSIGNAL[], MMA[]; //---- copy newly appeared data into the arrays if (CopyBuffer(MaHandle1, 0, 0, to_copy, mma1) < 0) return (RESET); if (CopyBuffer(MaHandle2, 0, 0, to_copy, mma2) < 0) return (RESET); if (CopyBuffer(MaHandle3, 0, 0, to_copy, mma3) < 0) return (RESET); ArraySetAsSeries(High, true); ArraySetAsSeries(Low, true); ArraySetAsSeries(Close, true); ArraySetAsSeries(Open, true); ArraySetAsSeries(Time, true); ArrayInitialize(BufferBuy, 0); ArrayInitialize(BufferSell, 0); ArrayInitialize(PZtrend, 0); ArrayInitialize(PZcolor, 0); ArraySetAsSeries(up, true); ArraySetAsSeries(down, true); ArraySetAsSeries(TPLine, true); ArraySetAsSeries(SLLine, true); ArraySetAsSeries(avgLine, true); ArraySetAsSeries(upperTrendline, true); ArraySetAsSeries(LowerTrendline, true); ArrayInitialize(indicond, 0); ArrayInitialize(BufferBuy,0); ArrayInitialize(BufferSell,0); ArrayInitialize(avgLine,0); ArrayInitialize(upperTrendline,0); ArrayInitialize(LowerTrendline,0); ArrayInitialize(BasisBuffer,0); ArrayInitialize(BullLevelBuffer,0); ArrayInitialize(BearLevelBuffer,0); ArrayInitialize(mma1,0); ArrayInitialize(mma2,0); ArrayInitialize(mma3,0); ArrayInitialize(ma1,0); ArrayInitialize(ma2,0); ArrayInitialize(ma3,0); ArrayInitialize(up,0); ArrayInitialize(down,0); ArrayInitialize(TPLine,0); ArrayInitialize(SLLine,0); int barshift, idx; string name; int Handle; int limit1 = MathMin(rates_total, 1000); name = "Guass"; Handle = iCustom(NULL, 0, "::Indicators\\" + name + ".ex5", "", 1000, show_strength, len, mode, distance, show_retest); CopyBuffer(Handle, 0, 0, limit1, avgLine); CopyBuffer(Handle, 1, 0, limit1, upperTrendline); CopyBuffer(Handle, 2, 0, limit1, LowerTrendline); name = "AdaptiveTrendFlow"; Handle = iCustom(NULL, 0, "::Indicators\\" + name + ".ex5", InpLength, InpSmoothLen, InpSensitivity, InpShowSignals, InpMaxBars, UseRetest); CopyBuffer(Handle, 0, 0, limit1, BasisBuffer); CopyBuffer(Handle, 1, 0, limit1, BullLevelBuffer); CopyBuffer(Handle, 2, 0, limit1, BearLevelBuffer); for (int i = to_copy - 1; i > 0; i--) { if (i > barscount) break; // Indicator Buffer 2 idx = checksignal(POSITION_TYPE_SELL, i); if (idx > 0 && (lastype != -1 || !ShowSingleArrow) && ShowSell) { BufferSell[i] = High[i] + displ * _Point; if (Time[0] > lastime && i == 1) { PlaySoundo("Sell Signal at " + DoubleToString(Close[i], Digits())); lastime = Time[0]; drawline("radar#targetsl", 1, Close[1] + StopLoss * Point() * 10, Time[10], false); drawline("radar#target", 1, Close[1] - TakeProfit1 * Point() * 10, Time[10]); } lastsignal = i; lastype = -1; } /* else BufferSell[i] = 0;*/ idx = checksignal(POSITION_TYPE_BUY, i); if (idx > 0 && (lastype != 1 || !ShowSingleArrow) && ShowBuy) { BufferBuy[i] = Low[i] - displ * _Point; if (Time[0] > lastime && i == 1) { PlaySoundo("Buy Signal at " + DoubleToString(Close[i], Digits())); lastime = Time[0]; drawline("radar#targetsl", 1, Close[1] - StopLoss * Point() * 10, Time[10], false); drawline("radar#target", 1, Close[1] + TakeProfit1 * Point() * 10, Time[10]); } lastsignal = i; lastype = 1; } /* else BufferBuy[i] = 0;*/ } if (oncerun && lastsignal > 0) { if (lastype == 1) { drawline("radar#targetsl", 1, Close[lastsignal] - StopLoss * Point() * 10, Time[lastsignal + 10], false); drawline("radar#target", 1, Close[lastsignal] + TakeProfit1 * Point() * 10, Time[lastsignal + 10]); oncerun = false; } if (lastype == -1) { drawline("radar#targetsl", 1, Close[lastsignal] + StopLoss * Point() * 10, Time[lastsignal + 10], false); drawline("radar#target", 1, Close[lastsignal] - TakeProfit1 * Point() * 10, Time[lastsignal + 10]); oncerun = false; } } //---- return (rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void drawLine(string name, datetime tm, double lvl, color Color) { bool ret; ret = ObjectCreate(0, name, OBJ_HLINE, 0, 0, 0); // Print(tm," ",lvl); if (ret) { ObjectSetInteger(0, name, OBJPROP_COLOR, Color); ObjectSetInteger(0, name, OBJPROP_TIME, tm); ObjectSetDouble(0, name, OBJPROP_PRICE, lvl); } else Print(GetLastError()); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ void PlaySoundo(string comm) { string comms; comms = Symbol() + "_" + PeriodToString(Period()) + "_" + comm; if (AlertOn) Alert(comms); if (NotificationOn) { Sleep(3000); SendNotification(comms); } if (EmailOn) SendMail(comms, comms); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ string PeriodToString(int Value) { if (Value == 0) Value = _Period; switch (Value) { case PERIOD_M1: // M1 return ("M1"); case PERIOD_M5: // M1 return ("M5"); case PERIOD_M15: return ("M15"); case PERIOD_M30: return ("M30"); case PERIOD_H1: return ("H1"); case PERIOD_H4: return ("H4"); case PERIOD_D1: return ("D1"); case PERIOD_W1: return ("W1"); case PERIOD_MN1: return ("MN1"); default: return ("undefined "); } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ void drawArrow(string name, int arrow, datetime tm, double lvl, color Color) { bool ret; if (arrow == 0) ret = ObjectCreate(0, name, OBJ_ARROW_BUY, 0, 0, 0); else ret = ObjectCreate(0, name, OBJ_ARROW_SELL, 0, 0, 0); // Print(tm," ",lvl); if (ret) { ObjectSetInteger(0, name, OBJPROP_COLOR, Color); ObjectSetInteger(0, name, OBJPROP_TIME, tm); ObjectSetDouble(0, name, OBJPROP_PRICE, lvl); } else Print(GetLastError()); } //+------------------------------------------------------------------+ #define MODE_LOW 1 #define MODE_HIGH 2 #define MODE_TIME 5 #define MODE_BID 9 #define MODE_ASK 10 #define MODE_POINT 11 #define MODE_DIGITS 12 #define MODE_SPREAD 13 #define MODE_STOPLEVEL 14 #define MODE_LOTSIZE 15 #define MODE_TICKVALUE 16 #define MODE_TICKSIZE 17 #define MODE_SWAPLONG 18 #define MODE_SWAPSHORT 19 #define MODE_STARTING 20 #define MODE_EXPIRATION 21 #define MODE_TRADEALLOWED 22 #define MODE_MINLOT 23 #define MODE_LOTSTEP 24 #define MODE_MAXLOT 25 #define MODE_SWAPTYPE 26 #define MODE_PROFITCALCMODE 27 #define MODE_MARGINCALCMODE 28 #define MODE_MARGININIT 29 #define MODE_MARGINMAINTENANCE 30 #define MODE_MARGINHEDGED 31 #define MODE_MARGINREQUIRED 32 #define MODE_FREEZELEVEL 33 //-------------------------------------------tp1----- // input bool ShowSLTP=true; //--------------------------------------------------------------------------------------------- void drawline(string name, int idx, double price1, datetime time1, bool istp = true) { int timediff, period1, timediff2; int Global_Long_00000004 = 10 * Period() * 60; color clr = Yellow; string text; if (!ShowSLTP) return; if (istp) { text = "TP" + string(idx) + " @ " + DoubleToString(price1, (int)MarketInfo(_Symbol, MODE_DIGITS)); clr = Yellow; } else { text = "SL1 @ " + DoubleToString(price1, (int)MarketInfo(_Symbol, MODE_DIGITS)); clr = MediumVioletRed; } datetime Time[]; ArraySetAsSeries(Time, true); CopyTime(Symbol(), 0, 0, 50, Time); ObjectCreate(0, name + string(idx), OBJ_TREND, 0, (time1 - Global_Long_00000004), 0, (Time[0] + Global_Long_00000004), 0, 0, 0); ObjectSet(name + string(idx), OBJPROP_COLOR, clr); ObjectSet(name + string(idx), OBJPROP_WIDTH, 3); period1 = _Period * 300; timediff2 = period1; timediff2 = int(time1 - timediff2); ObjectSet(name + string(idx), OBJPROP_TIME1, timediff2); timediff = int(Time[0] - Time[1]); timediff = timediff * 100; timediff = int(Time[0] + timediff); ObjectSet(name + string(idx), OBJPROP_TIME2, timediff); ObjectSet(name + string(idx), OBJPROP_PRICE1, price1); ObjectSet(name + string(idx), OBJPROP_PRICE2, price1); ObjectCreate(0, name + "-" + string(idx), OBJ_TEXT, 0, Time[0], price1, 0, 0, 0, 0); ObjectSetText(name + "-" + string(idx), "ggggggg", 12, "Webdings", clr); ObjectSet(name + "-" + string(idx), OBJPROP_TIME1, time1); ObjectSet(name + "-" + string(idx), OBJPROP_PRICE1, price1); ObjectCreate(0, name + "--" + string(idx), OBJ_TEXT, 0, time1, price1, 0, 0, 0, 0); ObjectSetText(name + "--" + string(idx), text, 8, "Arial Black", 13434880); ObjectSet(name + "--" + string(idx), OBJPROP_TIME1, time1); ObjectSet(name + "--" + string(idx), OBJPROP_PRICE1, price1); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool ObjectSetText(string name, string text, int font_size, string font_name = NULL, color text_color = CLR_NONE) { int tmpObjType = (int)ObjectGetInteger(0, name, OBJPROP_TYPE); if (tmpObjType != OBJ_LABEL && tmpObjType != OBJ_TEXT) return (false); if (StringLen(text) > 0 && font_size > 0) { if (ObjectSetString(0, name, OBJPROP_TEXT, text) == true && ObjectSetInteger(0, name, OBJPROP_FONTSIZE, font_size) == true) { if ((StringLen(font_name) > 0) && ObjectSetString(0, name, OBJPROP_FONT, font_name) == false) return (false); if (text_color != CLR_NONE && ObjectSetInteger(0, name, OBJPROP_COLOR, text_color) == false) return (false); return (true); } return (false); } return (false); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool ObjectSet(string name, int prop_id, double value) { switch (prop_id) { case OBJPROP_TIME1: ObjectSetInteger(0, name, OBJPROP_TIME, (int)value); return (true); case OBJPROP_PRICE1: ObjectSetDouble(0, name, OBJPROP_PRICE, value); return (true); case OBJPROP_TIME2: ObjectSetInteger(0, name, OBJPROP_TIME, 1, (int)value); return (true); case OBJPROP_PRICE2: ObjectSetDouble(0, name, OBJPROP_PRICE, 1, value); return (true); case OBJPROP_TIME3: ObjectSetInteger(0, name, OBJPROP_TIME, 2, (int)value); return (true); case OBJPROP_PRICE3: ObjectSetDouble(0, name, OBJPROP_PRICE, 2, value); return (true); case OBJPROP_COLOR: ObjectSetInteger(0, name, OBJPROP_COLOR, (int)value); return (true); case OBJPROP_STYLE: ObjectSetInteger(0, name, OBJPROP_STYLE, (int)value); return (true); case OBJPROP_WIDTH: ObjectSetInteger(0, name, OBJPROP_WIDTH, (int)value); return (true); case OBJPROP_BACK: ObjectSetInteger(0, name, OBJPROP_BACK, (int)value); return (true); case OBJPROP_RAY: ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, (int)value); return (true); case OBJPROP_ELLIPSE: ObjectSetInteger(0, name, OBJPROP_ELLIPSE, (int)value); return (true); case OBJPROP_SCALE: ObjectSetDouble(0, name, OBJPROP_SCALE, value); return (true); case OBJPROP_ANGLE: ObjectSetDouble(0, name, OBJPROP_ANGLE, value); return (true); case OBJPROP_ARROWCODE: ObjectSetInteger(0, name, OBJPROP_ARROWCODE, (int)value); return (true); case OBJPROP_TIMEFRAMES: ObjectSetInteger(0, name, OBJPROP_TIMEFRAMES, (int)value); return (true); case OBJPROP_DEVIATION: ObjectSetDouble(0, name, OBJPROP_DEVIATION, value); return (true); case OBJPROP_FONTSIZE: ObjectSetInteger(0, name, OBJPROP_FONTSIZE, (int)value); return (true); case OBJPROP_CORNER: ObjectSetInteger(0, name, OBJPROP_CORNER, (int)value); return (true); case OBJPROP_XDISTANCE: ObjectSetInteger(0, name, OBJPROP_XDISTANCE, (int)value); return (true); case OBJPROP_YDISTANCE: ObjectSetInteger(0, name, OBJPROP_YDISTANCE, (int)value); return (true); case OBJPROP_FIBOLEVELS: ObjectSetInteger(0, name, OBJPROP_LEVELS, (int)value); return (true); case OBJPROP_LEVELCOLOR: ObjectSetInteger(0, name, OBJPROP_LEVELCOLOR, (int)value); return (true); case OBJPROP_LEVELSTYLE: ObjectSetInteger(0, name, OBJPROP_LEVELSTYLE, (int)value); return (true); case OBJPROP_LEVELWIDTH: ObjectSetInteger(0, name, OBJPROP_LEVELWIDTH, (int)value); return (true); default: return (false); } return (false); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool ObjectSetFiboDescription(string name, int index, string text) { return (ObjectSetString(0, name, OBJPROP_LEVELTEXT, index, text)); } // Common Functions double MarketInfo(string symbol, int type) // With hacks to match integer type into double. { switch (type) { case MODE_LOW: return (SymbolInfoDouble(symbol, SYMBOL_LASTLOW)); case MODE_HIGH: return (SymbolInfoDouble(symbol, SYMBOL_LASTHIGH)); case MODE_TIME: return ((double)SymbolInfoInteger(symbol, SYMBOL_TIME)); case MODE_BID: return (SymbolInfoDouble(symbol, SYMBOL_BID)); case MODE_ASK: return (SymbolInfoDouble(symbol, SYMBOL_ASK)); case MODE_POINT: return (SymbolInfoDouble(symbol, SYMBOL_POINT)); case MODE_DIGITS: return ((double)SymbolInfoInteger(symbol, SYMBOL_DIGITS)); case MODE_SPREAD: return ((double)SymbolInfoInteger(symbol, SYMBOL_SPREAD)); case MODE_STOPLEVEL: return ((double)SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL)); case MODE_LOTSIZE: return (SymbolInfoDouble(symbol, SYMBOL_TRADE_CONTRACT_SIZE)); case MODE_TICKVALUE: return (SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE)); case MODE_TICKSIZE: return (SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE)); case MODE_SWAPLONG: return (SymbolInfoDouble(symbol, SYMBOL_SWAP_LONG)); case MODE_SWAPSHORT: return (SymbolInfoDouble(symbol, SYMBOL_SWAP_SHORT)); case MODE_STARTING: return (0); case MODE_EXPIRATION: return (0); case MODE_TRADEALLOWED: return (0); case MODE_MINLOT: return (SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN)); case MODE_LOTSTEP: return (SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP)); case MODE_MAXLOT: return (SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX)); case MODE_SWAPTYPE: return ((double)SymbolInfoInteger(symbol, SYMBOL_SWAP_MODE)); case MODE_PROFITCALCMODE: return ((double)SymbolInfoInteger(symbol, SYMBOL_TRADE_CALC_MODE)); case MODE_MARGINCALCMODE: return (0); case MODE_MARGININIT: return (0); case MODE_MARGINMAINTENANCE: return (0); case MODE_MARGINHEDGED: return (0); case MODE_MARGINREQUIRED: return (0); case MODE_FREEZELEVEL: return ((double)SymbolInfoInteger(symbol, SYMBOL_TRADE_FREEZE_LEVEL)); default: return (0); } return (0); } double m_HisLots, m_HisPro, m_HisPips, maxloss = 0; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double SetHistotyTotal(datetime start, datetime end = 0) { m_HisLots = 0; m_HisPro = 0; m_HisPips = 0; color BuyColor = clrBlue; color SellColor = clrRed; //--- 请求交易历史记录 if (end == 0) end = TimeCurrent(); HistorySelect(start, end); //--- 创建物件 uint total = HistoryDealsTotal(); ulong ticket = 0; double price; double profit = 0, OrderLots, OrderProfit, OrderCommission, OrderSwap, tmp_maxprofit = 0, tmp_minprofit = 0, setpoint; datetime times; string symbol; long type; long entry; long magic; //--- 所有交易 double totalprofitS = 0; for (uint i = 0; i < total; i++) { //--- 尽力获得交易报价 if ((ticket = HistoryDealGetTicket(i)) > 0) { //--- 获得交易属性 price = HistoryDealGetDouble(ticket, DEAL_PRICE); times = (datetime)HistoryDealGetInteger(ticket, DEAL_TIME); symbol = HistoryDealGetString(ticket, DEAL_SYMBOL); type = HistoryDealGetInteger(ticket, DEAL_TYPE); entry = HistoryDealGetInteger(ticket, DEAL_ENTRY); OrderProfit = HistoryDealGetDouble(ticket, DEAL_PROFIT); OrderCommission = HistoryDealGetDouble(ticket, DEAL_COMMISSION); OrderSwap = HistoryDealGetDouble(ticket, DEAL_SWAP); OrderLots = HistoryDealGetDouble(ticket, DEAL_VOLUME); setpoint = SymbolInfoDouble(symbol, SYMBOL_POINT) * 10; magic = HistoryDealGetInteger(ticket, DEAL_MAGIC); //--- 只对当前交易品种 if (price && times > start && times < end && symbol == Symbol()) { m_HisLots += OrderLots; m_HisPro += OrderProfit + OrderCommission + OrderSwap; m_HisPips += (OrderProfit) / OrderLots / 10; // Print(m_HisLots," ",m_HisPro," ",m_HisPips); if (m_HisPro > tmp_maxprofit) { tmp_maxprofit = m_HisPro; tmp_minprofit = m_HisPro; } if (m_HisPro < tmp_minprofit || tmp_minprofit == 0) { tmp_minprofit = m_HisPro; } if (tmp_maxprofit - tmp_minprofit > maxloss) maxloss = tmp_maxprofit - tmp_minprofit; totalprofitS += profit; } } } return totalprofitS; } //******************************************************************** //******************************************************************* bool CheckTime(string startt, string endt) { int sh, eh; sh = int(StringSubstr(startt, 0, StringFind(startt, ":"))); eh = int(StringSubstr(endt, 0, StringFind(endt, ":"))); datetime m_enter = StringToTime(TimeToString(TimeGMT(), TIME_DATE) + " " + startt); datetime m_end = StringToTime(TimeToString(TimeGMT(), TIME_DATE) + " " + endt); if (sh <= eh) { if (TimeGMT() >= m_enter && TimeGMT() < m_end) return (true); else return (false); } else { if (TimeGMT() >= m_enter || TimeGMT() < m_end) return (true); else return (false); } } // Checkup bool IsConnected() { return (bool)TerminalInfoInteger(TERMINAL_CONNECTED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double AccountBalance() { return AccountInfoDouble(ACCOUNT_BALANCE); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double AccountProfit() { return AccountInfoDouble(ACCOUNT_PROFIT); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Day() { MqlDateTime tm; TimeCurrent(tm); return (tm.day); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int DayOfWeek() { MqlDateTime tm; TimeCurrent(tm); return (tm.day_of_week); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int DayOfYear() { MqlDateTime tm; TimeCurrent(tm); return (tm.day_of_year); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Hour() { MqlDateTime tm; TimeCurrent(tm); return (tm.hour); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Year() { MqlDateTime tm; TimeCurrent(tm); return (tm.year); } //+------------------------------------------------------------------+ double indicond[20]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int checksignal(int istype, int i = 1) { double Close[]; double High[]; double Low[]; double Open[]; datetime Time[]; double EMAbuy[], PSARbuy[], RSIbuy[], Engulfingbuy[], Engulfingsell[], CCIbuy[], HeikenAshClose[], HeikenAshOpen[], SpikeBuy[], SpikeSell[], ADXbuy[], ADXsell[], wprsibuy[], wprsisell[]; bool checked[20]; double PZLopezTrendbuy[], PZLopezTrendsell[], TrappedLime[], TrappedRed[], Trappedsignal[], UTBotAlertbuy[], UTBotAlertsell[]; double GuassSELL[], GuassBUY[], GuassMID[]; double SuperBollingerTrendbuy[], SuperBollingerTrendsell[]; double BFTBULE[], BFTRED[], BFTGREEN[]; double BankersFlowBuy[], BankersFlowSell[]; double AdaptiveTrendFlowBuy[], AdaptiveTrendFlowSell[]; ArraySetAsSeries(Time, true); ArraySetAsSeries(GuassBUY, true); ArraySetAsSeries(GuassSELL, true); ArraySetAsSeries(GuassMID, true); ArraySetAsSeries(BFTBULE, true); ArraySetAsSeries(BFTRED, true); ArraySetAsSeries(BFTGREEN, true); ArraySetAsSeries(Close, true); ArraySetAsSeries(Open, true); ArraySetAsSeries(BankersFlowBuy, true); ArraySetAsSeries(BankersFlowSell, true); ArraySetAsSeries(AdaptiveTrendFlowBuy, true); ArraySetAsSeries(AdaptiveTrendFlowSell, true); ArrayInitialize(GuassBUY, EMPTY_VALUE); ArrayInitialize(GuassSELL, EMPTY_VALUE); ArrayInitialize(ADXbuy, 0); ArrayInitialize(ADXsell, 0); ArrayInitialize(checked, 0); CopyClose(_Symbol, _Period, i, 10, Close); CopyHigh(_Symbol, _Period, i, 10, High); CopyLow(_Symbol, _Period, i, 10, Low); CopyOpen(_Symbol, _Period, i, 10, Open); CopyTime(_Symbol, _Period, 0, Bars(NULL, 0) - 1, Time); string name; int Handle; // if(AdaptiveTrendFlowON) { name = "AdaptiveTrendFlow"; Handle = iCustom(NULL, 0, "::Indicators\\" + name + ".ex5", InpLength, InpSmoothLen, InpSensitivity, InpShowSignals, InpMaxBars, UseRetest); CopyBuffer(Handle, 4, i, 5, AdaptiveTrendFlowBuy); CopyBuffer(Handle, 5, i, 5, AdaptiveTrendFlowSell); } if (GuassON) { name = "Guass"; Handle = iCustom(NULL, 0, "::Indicators\\" + name + ".ex5", "", 1000, show_strength, len, mode, distance, show_retest); CopyBuffer(Handle, 2, i, 5, GuassBUY); CopyBuffer(Handle, 1, i, 5, GuassSELL); CopyBuffer(Handle, 0, i, 5, GuassMID); } //-------------------------00----------------------------------------------- int z = 0; if (GuassON) { if ((Close[0] > GuassSELL[0] && Close[0 + 1] < GuassSELL[1] && GuassSELL[1] != EMPTY_VALUE && GuassSELL[0] > 0) || (GuassBUY[0] > 0 && show_retest && Close[0] > GuassMID[0] && Close[0 + 1] < GuassMID[1])) { indicond[z] = OP_BUY; // Linear if (!GuassDirectiononly) checked[z] = true; } if ((Close[0] < GuassBUY[0] && Close[0 + 1] > GuassBUY[1] && GuassBUY[0] != EMPTY_VALUE && GuassBUY[1] > 0) || (GuassSELL[0] > 0 && show_retest && Close[0] < GuassMID[0] && Close[0 + 1] > GuassMID[1])) { indicond[z] = OP_SELL; // Linear if (!GuassDirectiononly) checked[z] = true; } } //-------------------------11----------------------------------------------- z++; //------------------------22------------------------------------------------ z++; //------------------------33------------------------------------------------ z++; if (AdaptiveTrendFlowBuy[0] > 0 && AdaptiveTrendFlowBuy[0] != EMPTY_VALUE) { indicond[z] = OP_BUY; // Linear if (!AdaptiveTrendFlowDirectiononly) checked[z] = true; } if (AdaptiveTrendFlowSell[0] > 0 && AdaptiveTrendFlowSell[0] != EMPTY_VALUE) { indicond[z] = OP_SELL; // Linear if (!AdaptiveTrendFlowDirectiononly) checked[z] = true; } //-------------------------44----------------------------------------------- z++; if ((MADirection == 3 && mma1[i] > mma2[i] && mma2[i] > mma3[i] && !(mma1[i + 1] > mma2[i + 1] && mma2[i + 1] > mma3[i + 1])) || (MADirection == 2 && mma1[i] > mma2[i] && mma1[i + 1] < mma2[i + 1]) || (MADirection == 1 && Close[0] > mma1[i] && Close[0 + 1] < mma1[i + 1])) { indicond[z] = POSITION_TYPE_BUY; // TripleMA if (!MADirectiononly) checked[z] = true; } if ((MADirection == 3 && mma1[i] < mma2[i] && mma2[i] < mma3[i] && !(mma1[i + 1] < mma2[i + 1] && mma2[i + 1] < mma3[i + 1])) || (MADirection == 2 && mma1[i] < mma2[i] && mma1[i + 1] > mma2[i + 1]) || (MADirection == 1 && Close[0] < mma1[i] && Close[0 + 1] > mma1[i + 1])) { indicond[z] = POSITION_TYPE_SELL; if (!MADirectiononly) checked[z] = true; } //------------------------55------------------------------------------------ z++; //------------------------66------------------------------------------------ z++; //------------------------77------------------------------------------------ z++; //--------------------------88---------------------------------------------- z++; //--------------------99-------------------------------------------------- z++; //--------------------10-------------------------------------------------- z++; //--------------------11-------------------------------------------------- z++; //--------------------12-------------------------------------------------- z++; //--------------------12-------------------------------------------------- z++; int signumber = 0; int chknumber = 0; if (GuassON && indicond[0] == istype) { signumber++; if (checked[0]) chknumber++; } if (AdaptiveTrendFlowON && indicond[3] == istype) { signumber++; if (checked[3]) chknumber++; } if (TripleMAON && indicond[4] == istype) { signumber++; if (checked[4]) { chknumber++; } } if (signumber == TripleMAON + GuassON + AdaptiveTrendFlowON) { if (chknumber > 0) { return 1; } } // if(signumber>0 && chknumber>0 && TradingOption==1) return 1; return 0; } // Technical Indicators /** * This function fulfills the will of the developer * @param handle: Argument 1 * @param index: Argument 2 * @param shift: Argument 3 * @return ( double ) */ double CopyBuffer(int handle, int index, int shift) { double buf[]; switch (index) { case 0: if (::CopyBuffer(handle, 0, shift, 1, buf) > 0) return (buf[0]); break; case 1: if (::CopyBuffer(handle, 1, shift, 1, buf) > 0) return (buf[0]); break; case 2: if (::CopyBuffer(handle, 2, shift, 1, buf) > 0) return (buf[0]); break; case 3: if (::CopyBuffer(handle, 3, shift, 1, buf) > 0) return (buf[0]); break; case 4: if (::CopyBuffer(handle, 4, shift, 1, buf) > 0) return (buf[0]); break; default: break; } return (EMPTY_VALUE); } //+------------------------------------------------------------------+ void SetIndexEmptyValue(int index, double value) { PlotIndexSetDouble(index, PLOT_EMPTY_VALUE, value); } // —————————————————————| end of the algorithm |——————————————————————|