#property copyright "Copyright 2023 Prop Firm EA Phase 1" #property link "https://propfirmea.io" #import "urlmon.dll" int URLDownloadToFileW(int pCaller,string szURL,string szFileName,int dwReserved,int Callback); #import //--- #define INAME "FFC" #define TITLE 0 #define COUNTRY 1 #define DATE 2 #define TIME 3 #define IMPACT 4 #define FORECAST 5 #define PREVIOUS 6 #import "user32.dll" extern string EA = "--------------------- Prop Firm EA Phase 1 ---------------------"; extern string License = "Please Enter License..."; extern double Lots = 0.01; extern double TakeProfit = 150.0; extern int MaxTrades = 20; extern double Multiplier = 2.0; extern double PipStep = 10.0; bool UseEquityStop = TRUE; double Equity = 10; // Equity up in % double Equity_down = 4.9; // Equity down in % bool Stop_EA = true; //Ea stop when Equity reached bool InpCloseAllTrades = true; // Close All Trades when EA turns off string _Visor1_ = "-----------------------------Visor 1 --------------------"; bool Visor1_Show_the_Time = true; bool Visor1_Show_the_Price = true; color Visor1_Price_Up_Color = LawnGreen; color Visor1_Price_Down_Color = Tomato; int Visor1_Price_X_Position = 10; int Visor1_Price_Y_Position = 10; int Visor1_Price_Size = 20; int Visor1_Porcent_X_Position = 10; int Visor1_Porcent_Y_Position = 70; int Visor1_Porcent_Size = 20; int Visor1_Symbol_X_Position = 10; int Visor1_Symbol_Y_Position = 40; int Visor1_Symbol_Size = 20; int Visor1_Chart_Timezone = -5; color Visor1_Time_Color = Yellow; int Visor1_Time_Size = 17; int Visor1_Time_X_Position = 10; int Visor1_Time_Y_Position = 10; int Visor1_Spread_Size = 10; int Visor1_Spread_X_Position = 10; int Visor1_Spread_Y_Position = 100; string ___NEWS___ ="<<====== High Impacts News Settings ======>>"; bool Use_HighImpactNews = true; bool ShowPanel = true; // Show panel int orderstop_beforenews = 120; // event before (in minutes) int orderstart_afternews = 60; bool IncludeHigh = true; // Include high bool IncludeMedium = true; // Include medium bool IncludeLow = true; // Include low bool AllowUpdates = true; // Allow updates int UpdateHour = 1; // Update every (in hours) int EventDisplay = 60; // Hide event after (in minutes) color InfoColor = C'255,185,83'; // Info color int InfoFontSize = 8; // Info font size ENUM_BASE_CORNER Corner = 2; string PanelTitle ="Forex Calendar News"; // Panel title color TitleColor = C'46,188,46'; // Title color bool ShowPanelBG = true; // Show panel backgroud color Pbgc = C'25,25,25'; // Panel backgroud color color LowImpactColor = C'91,192,222'; // Low impact color color MediumImpactColor = C'255,185,83'; // Medium impact color color HighImpactColor = clrRed; // High impact color color RemarksColor = clrGray; // Remarks color color PreviousColor = C'170,170,170'; // Forecast color color PositiveColor = C'46,188,46'; // Positive forecast color color NegativeColor = clrTomato; // Negative forecast color bool ReportActive = false; // Report for active chart only (override other inputs) // Panel side bool order_run = true; //--- Vars and arrays string xmlFileName; string sData; string Event[200][7]; string eTitle[10],eCountry[10],eImpact[10],eForecast[10],ePrevious[10]; int eMinutes[10]; datetime eTime[10]; int anchor,x0,x1,x2,xf,xp; int Factor; //--- Alert bool FirstAlert; bool SecondAlert; datetime AlertTime; //--- Buffers double MinuteBuffer[200]; double ImpactBuffer[200]; //--- time datetime xmlModifed; int TimeOfDay; datetime search, Midnight; bool IsEvent; string comment = "Prop Firm EA Phase 1"; extern string Panel_ = "-------------------------Display Settings---------------------------"; color Display_Color = clrWhite; color Display_Color2 = clrWhite; int Display_Fontsize = 10; double g_price_196; double gd_204; double gd_unused_212; double gd_unused_220; double g_price_228; double g_bid_236; double g_ask_244; double gd_252; double gd_260; double gd_276; bool gi_284; string gs_288 = ""; int g_time_296 = 0; int gi_300; int gi_304 = 0; double gd_308; int g_pos_316 = 0; int gi_320; double gd_324 = 0.0; int MMType = 1; bool UseTrailingStop = FALSE; bool UseTimeOut = FALSE; double MaxTradeOpenHours = 48.0; bool UseClose = FALSE; bool UseAdd = TRUE; bool gi_332 = FALSE; bool gi_336 = FALSE; bool gi_340 = FALSE; int gi_344; bool gi_348 = FALSE; int StartTrade = 0; int EndTrade = 23; int MagicNumber = 658; double g_pips_128 = 40.0; double slip = 3.0; double LotsDigits = 2.0; double gd_136 = 15.0; double gd_144 = 15.0; double gd_360; double gd_368; string txt,txt1; string txt2=""; string txt3=""; string txt4=""; string txt5=""; string txt6=""; string txt7=""; double AccountEquityHigh, AccountBalance_ ; int init() { ObjectsDeleteAll(0); visual(); gd_276 = MarketInfo(Symbol(), MODE_SPREAD) * Point; AccountEquityHigh = AccountBalance(); AccountBalance_ = AccountBalance(); if(!IsDllsAllowed()){ Alert("Please Check DLL Allowed"); return(0); } TimeOfDay=(int)TimeLocal()%86400; Midnight=TimeLocal()-TimeOfDay; //--- set xml file name ffcal_week_this (fixed name) xmlFileName=INAME+"-ffcal_week_this.xml"; //--- checks the existence of the file. if(!FileIsExist(xmlFileName)) { xmlDownload(); xmlRead(); } //--- else just read it else xmlRead(); //--- get last modification time xmlModifed=(datetime)FileGetInteger(xmlFileName,FILE_MODIFY_DATE,false); //--- check for updates if(AllowUpdates) { if(xmlModifed StrToTime("2023.11.27 00:00")) return(0); // ******end code protect by date***** static datetime time_dd; double ld_0 = CalculateProfit(); if (UseEquityStop) { double equity = (1+(Equity / 100)) * AccountEquityHigh; if (AccountEquity() >= equity) { CloseThisSymbolAll(); Print("Closed All due to Limit Profit"); if(Stop_EA) stop = true; else AccountEquityHigh = AccountBalance(); gi_348 = FALSE; } if(AccountBalance_ < AccountEquity()) AccountBalance_ = AccountEquity(); double equity_dw = AccountBalance_ - ((Equity_down/100)*AccountBalance_); if (AccountEquity() <= equity_dw) { CloseThisSymbolAll(); Print("Closed All due to Stop Out"); stop = true; gi_348 = FALSE; } } double l_ord_lots_8; double l_ord_lots_16; double l_iclose_24; double l_iclose_32; if (UseTrailingStop) TrailingAlls(gd_136, gd_144, g_price_228); if (UseTimeOut) { if (TimeCurrent() >= gi_300) { CloseThisSymbolAll(); Print("Closed All due to TimeOut"); } } if (g_time_296 == Time[0]) return (0); g_time_296 = Time[0]; gi_320 = CountTrades(); if (gi_320 == 0) gi_284 = FALSE; for (g_pos_316 = OrdersTotal() - 1; g_pos_316 >= 0; g_pos_316--) { OrderSelect(g_pos_316, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) { gi_336 = TRUE; gi_340 = FALSE; l_ord_lots_8 = OrderLots(); break; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_SELL) { gi_336 = FALSE; gi_340 = TRUE; l_ord_lots_16 = OrderLots(); break; } } } if (gi_320 > 0 && gi_320 <= MaxTrades) { RefreshRates(); gd_252 = FindLastBuyPrice(); gd_260 = FindLastSellPrice(); if (gi_336 && gd_252 - Ask >= PipStep * Point) gi_332 = TRUE; if (gi_340 && Bid - gd_260 >= PipStep * Point) gi_332 = TRUE; } if (gi_320 < 1) { gi_340 = FALSE; gi_336 = FALSE; gi_332 = TRUE; gd_204 = AccountEquity(); } if (gi_332) { gd_252 = FindLastBuyPrice(); gd_260 = FindLastSellPrice(); if (gi_340) { if (UseClose) { fOrderCloseMarket(0, 1); gd_308 = NormalizeDouble(Multiplier * l_ord_lots_16, LotsDigits); } else gd_308 = fGetLots(OP_SELL); if (UseAdd) { gi_304 = gi_320; if (gd_308 > 0.0) { RefreshRates(); gi_344 = OpenPendingOrder(1, gd_308, Bid, slip, Ask, 0, 0, gs_288 + "-" + gi_304, MagicNumber, 0, HotPink); if (gi_344 < 0) { Print("Error: ", GetLastError()); return (0); } gd_260 = FindLastSellPrice(); gi_332 = FALSE; gi_348 = TRUE; } } } else { if (gi_336) { if (UseClose) { fOrderCloseMarket(1, 0); gd_308 = NormalizeDouble(Multiplier * l_ord_lots_8, LotsDigits); } else gd_308 = fGetLots(OP_BUY); if (UseAdd) { gi_304 = gi_320; if (gd_308 > 0.0) { gi_344 = OpenPendingOrder(0, gd_308, Ask, slip, Bid, 0, 0, gs_288 + "-" + gi_304, MagicNumber, 0, Lime); if (gi_344 < 0) { Print("Error: ", GetLastError()); return (0); } gd_252 = FindLastBuyPrice(); gi_332 = FALSE; gi_348 = TRUE; } } } } } if (gi_332 && gi_320 < 1) { l_iclose_24 = iClose(Symbol(), 0, 2); l_iclose_32 = iClose(Symbol(), 0, 1); g_bid_236 = Bid; g_ask_244 = Ask; if (!gi_340 && !gi_336) { gi_304 = gi_320; if (l_iclose_24 > l_iclose_32) { gd_308 = fGetLots(OP_SELL); if (gd_308 > 0.0) { gi_344 = OpenPendingOrder(1, gd_308, g_bid_236, slip, g_bid_236, 0, 0, gs_288 + "-" + gi_304, MagicNumber, 0, HotPink); if (gi_344 < 0) { Print(gd_308, "Error: ", GetLastError()); return (0); } gd_252 = FindLastBuyPrice(); gi_348 = TRUE; } } else { gd_308 = fGetLots(OP_BUY); if (gd_308 > 0.0) { gi_344 = OpenPendingOrder(0, gd_308, g_ask_244, slip, g_ask_244, 0, 0, gs_288 + "-" + gi_304, MagicNumber, 0, Lime); if (gi_344 < 0) { Print(gd_308, "Error: ", GetLastError()); return (0); } gd_260 = FindLastSellPrice(); gi_348 = TRUE; } } } if (gi_344 > 0) gi_300 = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours); gi_332 = FALSE; } gi_320 = CountTrades(); g_price_228 = 0; double ld_40 = 0; for (g_pos_316 = OrdersTotal() - 1; g_pos_316 >= 0; g_pos_316--) { OrderSelect(g_pos_316, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { g_price_228 += OrderOpenPrice() * OrderLots(); ld_40 += OrderLots(); } } } if (gi_320 > 0) g_price_228 = NormalizeDouble(g_price_228 / ld_40, Digits); if (gi_348) { for (g_pos_316 = OrdersTotal() - 1; g_pos_316 >= 0; g_pos_316--) { OrderSelect(g_pos_316, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) { g_price_196 = g_price_228 + TakeProfit * Point ; gd_unused_212 = g_price_196; gd_324 = g_price_228 - g_pips_128 ; gi_284 = TRUE; } } if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_SELL) { g_price_196 = g_price_228 - TakeProfit * Point ; gd_unused_220 = g_price_196; gd_324 = g_price_228 + g_pips_128 ; gi_284 = TRUE; } } } } if (gi_348) { if (gi_284 == TRUE) { for (g_pos_316 = OrdersTotal() - 1; g_pos_316 >= 0; g_pos_316--) { OrderSelect(g_pos_316, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) OrderModify(OrderTicket(), g_price_228, OrderStopLoss(), g_price_196, 0, Yellow); gi_348 = FALSE; } } } return (0); } double ND(double ad_0) { return (NormalizeDouble(ad_0, Digits)); } int fOrderCloseMarket(bool ai_0 = TRUE, bool ai_4 = TRUE) { int li_ret_8 = 0; for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) { if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY && ai_0) { RefreshRates(); if (!IsTradeContextBusy()) { if (!OrderClose(OrderTicket(), OrderLots(), ND(Bid), 5, CLR_NONE)) { Print("Error close BUY " + OrderTicket()); li_ret_8 = -1; } } else { if (StartTrade != iTime(NULL, 0, 0)) { StartTrade = iTime(NULL, 0, 0); Print("Need close BUY " + OrderTicket() + ". Trade Context Busy"); } return (-2); } } if (OrderType() == OP_SELL && ai_4) { RefreshRates(); if (!IsTradeContextBusy()) { if (!OrderClose(OrderTicket(), OrderLots(), ND(Ask), 5, CLR_NONE)) { Print("Error close SELL " + OrderTicket()); li_ret_8 = -1; } } else { if (EndTrade != iTime(NULL, 0, 0)) { EndTrade = iTime(NULL, 0, 0); Print("Need close SELL " + OrderTicket() + ". Trade Context Busy"); } return (-2); } } } } } return (li_ret_8); } double fGetLots(int a_cmd_0) { double l_lots_4; int l_datetime_16; switch (MMType) { case 0: l_lots_4 = Lots; break; case 1: l_lots_4 = NormalizeDouble(Lots * MathPow(Multiplier, gi_304), LotsDigits); break; case 2: l_datetime_16 = 0; l_lots_4 = Lots; for (int l_pos_20 = OrdersHistoryTotal() - 1; l_pos_20 >= 0; l_pos_20--) { if (OrderSelect(l_pos_20, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (l_datetime_16 < OrderCloseTime()) { l_datetime_16 = OrderCloseTime(); if (OrderProfit() < 0.0) l_lots_4 = NormalizeDouble(OrderLots() * Multiplier, LotsDigits); else l_lots_4 = Lots; } } } else return (-3); } } if (AccountFreeMarginCheck(Symbol(), a_cmd_0, l_lots_4) <= 0.0) return (-1); if (GetLastError() == 134/* NOT_ENOUGH_MONEY */) return (-2); return (l_lots_4); } int CountTrades() { int l_count_0 = 0; for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) { OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) if (OrderType() <2) l_count_0++; } return (l_count_0); } void CloseThisSymbolAll() { for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol()) { if(OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 3, Blue); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red); } //Sleep(1000); } } } int OpenPendingOrder(int ai_0, double a_lots_4, double a_price_12, int a_slippage_20, double ad_24, int ai_32, int ai_36, string a_comment_40, int a_magic_48, int a_datetime_52, color a_color_56) { int l_ticket_60 = 0; int l_error_64 = 0; int l_count_68 = 0; int li_72 = 100; switch (ai_0) { case 2: for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) { l_ticket_60 = OrderSend(Symbol(), OP_BUYLIMIT, a_lots_4, a_price_12, a_slippage_20, StopLong(ad_24, ai_32), TakeLong(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56); l_error_64 = GetLastError(); if (l_error_64 == 0/* NO_ERROR */) break; if (!(l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */)) break; Sleep(1000); } break; case 4: for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) { l_ticket_60 = OrderSend(Symbol(), OP_BUYSTOP, a_lots_4, a_price_12, a_slippage_20, StopLong(ad_24, ai_32), TakeLong(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56); l_error_64 = GetLastError(); if (l_error_64 == 0/* NO_ERROR */) break; if (!(l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 0: for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) { RefreshRates(); l_ticket_60 = OrderSend(Symbol(), OP_BUY, a_lots_4, Ask, a_slippage_20, StopLong(Bid, ai_32), TakeLong(Ask, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56); l_error_64 = GetLastError(); if (l_error_64 == 0/* NO_ERROR */) break; if (!(l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 3: for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) { l_ticket_60 = OrderSend(Symbol(), OP_SELLLIMIT, a_lots_4, a_price_12, a_slippage_20, StopShort(ad_24, ai_32), TakeShort(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56); l_error_64 = GetLastError(); if (l_error_64 == 0/* NO_ERROR */) break; if (!(l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 5: for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) { l_ticket_60 = OrderSend(Symbol(), OP_SELLSTOP, a_lots_4, a_price_12, a_slippage_20, StopShort(ad_24, ai_32), TakeShort(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56); l_error_64 = GetLastError(); if (l_error_64 == 0/* NO_ERROR */) break; if (!(l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */)) break; Sleep(5000); } break; case 1: for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) { l_ticket_60 = OrderSend(Symbol(), OP_SELL, a_lots_4, Bid, a_slippage_20, StopShort(Ask, ai_32), TakeShort(Bid, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56); l_error_64 = GetLastError(); if (l_error_64 == 0/* NO_ERROR */) break; if (!(l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */)) break; Sleep(5000); } } return (l_ticket_60); } double StopLong(double ad_0, int ai_8) { if (ai_8 == 0) return (0); return (ad_0 - ai_8 * Point); } double StopShort(double ad_0, int ai_8) { if (ai_8 == 0) return (0); return (ad_0 + ai_8 * Point); } double TakeLong(double ad_0, int ai_8) { if (ai_8 == 0) return (0); return (ad_0 + ai_8 * Point); } double TakeShort(double ad_0, int ai_8) { if (ai_8 == 0) return (0); return (ad_0 - ai_8 * Point); } double CalculateProfit() { double ld_ret_0 = 0; for (g_pos_316 = OrdersTotal() - 1; g_pos_316 >= 0; g_pos_316--) { OrderSelect(g_pos_316, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) if (OrderType() < 2) ld_ret_0 += OrderProfit(); } return (ld_ret_0); } double CalculateProfit_dd() { double ld_ret_0 = 0; for (g_pos_316 = OrdersTotal() - 1; g_pos_316 >= 0; g_pos_316--) { OrderSelect(g_pos_316, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderOpenTime()>= iTime(NULL, PERIOD_D1,0)) if (OrderType() < 2) ld_ret_0 += OrderProfit(); } return (ld_ret_0); } double lots() { double ld_ret_0 = 0; for (g_pos_316 = OrdersTotal() - 1; g_pos_316 >= 0; g_pos_316--) { OrderSelect(g_pos_316, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) if (OrderType() < 2) ld_ret_0 += OrderLots(); } return (ld_ret_0); } void TrailingAlls(int ai_0, int ai_4, double a_price_8) { int li_16; double l_ord_stoploss_20; double l_price_28; if (ai_4 != 0) { for (int l_pos_36 = OrdersTotal() - 1; l_pos_36 >= 0; l_pos_36--) { if (OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) { li_16 = NormalizeDouble((Bid - a_price_8) / Point, 0); if (li_16 < ai_0) continue; l_ord_stoploss_20 = OrderStopLoss(); l_price_28 = Bid - ai_4 * Point; if (l_ord_stoploss_20 == 0.0 || (l_ord_stoploss_20 != 0.0 && l_price_28 > l_ord_stoploss_20)) OrderModify(OrderTicket(), a_price_8, l_price_28, OrderTakeProfit(), 0, Aqua); } if (OrderType() == OP_SELL) { li_16 = NormalizeDouble((a_price_8 - Ask) / Point, 0); if (li_16 < ai_0) continue; l_ord_stoploss_20 = OrderStopLoss(); l_price_28 = Ask + ai_4 * Point; if (l_ord_stoploss_20 == 0.0 || (l_ord_stoploss_20 != 0.0 && l_price_28 < l_ord_stoploss_20)) OrderModify(OrderTicket(), a_price_8, l_price_28, OrderTakeProfit(), 0, Red); } } Sleep(1000); } } } } //double AccountEquityHigh() { //if (CountTrades() == 0) gd_360 = AccountEquity(); // return (gd_360); //} double FindLastBuyPrice() { double l_ord_open_price_8; int l_ticket_24; double ld_unused_0 = 0; int l_ticket_20 = 0; for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) { OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) { l_ticket_24 = OrderTicket(); if (l_ticket_24 > l_ticket_20) { l_ord_open_price_8 = OrderOpenPrice(); ld_unused_0 = l_ord_open_price_8; l_ticket_20 = l_ticket_24; } } } return (l_ord_open_price_8); } double FindLastSellPrice() { double l_ord_open_price_8; int l_ticket_24; double ld_unused_0 = 0; int l_ticket_20 = 0; for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) { OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) { l_ticket_24 = OrderTicket(); if (l_ticket_24 > l_ticket_20) { l_ord_open_price_8 = OrderOpenPrice(); ld_unused_0 = l_ord_open_price_8; l_ticket_20 = l_ticket_24; } } } return (l_ord_open_price_8); } void visual(){ string fonts = "Verdana"; int count = 10; int counters = 13; double floated; if(AccountBalance()==0) floated = 0; else floated = (CalculateProfit()*100)/AccountBalance(); string floating = DoubleToStr(floated,1)+"%"; background(); for(int s=0; seForecast[i]) ForecastColor=NegativeColor; else if(ePrevious[i]1) windows=1; ObjectDelete(name); ObjectCreate(name,OBJ_LABEL,windows,0,0); ObjectSetText(name,label,size,font,clr); ObjectSet(name,OBJPROP_CORNER,c); ObjectSet(name,OBJPROP_XDISTANCE,x); ObjectSet(name,OBJPROP_YDISTANCE,y); //--- justify text ObjectSet(name,OBJPROP_ANCHOR,anchor); ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip); ObjectSet(name,OBJPROP_SELECTABLE,0); //--- } //+------------------------------------------------------------------+ //| Converts ff time & date into yyyy.mm.dd hh:mm - by deVries | //+------------------------------------------------------------------+ string MakeDateTime(string strDate,string strTime) { //--- int n1stDash=StringFind(strDate, "-"); int n2ndDash=StringFind(strDate, "-", n1stDash+1); string strMonth=StringSubstr(strDate,0,2); string strDay=StringSubstr(strDate,3,2); string strYear=StringSubstr(strDate,6,4); int nTimeColonPos=StringFind(strTime,":"); string strHour=StringSubstr(strTime,0,nTimeColonPos); string strMinute=StringSubstr(strTime,nTimeColonPos+1,2); string strAM_PM=StringSubstr(strTime,StringLen(strTime)-2); int nHour24=StrToInteger(strHour); if((strAM_PM=="pm" || strAM_PM=="PM") && nHour24!=12) nHour24+=12; if((strAM_PM=="am" || strAM_PM=="AM") && nHour24==12) nHour24=0; string strHourPad=""; if(nHour24<10) strHourPad="0"; return(StringConcatenate(strYear, ".", strMonth, ".", strDay, " ", strHourPad, nHour24, ":", strMinute)); //--- } //+------------------------------------------------------------------+ //| Impact to number && color //+------------------------------------------------------------------+ color ImpactToColor(string impact) { //--- if(impact == "High") return (HighImpactColor); else if(impact == "Medium") return (MediumImpactColor); else if(impact == "Low") return (LowImpactColor); //else if(impact == "Holiday") return (HolidayColor); else return (RemarksColor); //--- } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int ImpactToNumber(string impact) { //--- if(impact == "High") return(3); else if(impact == "Medium") return(2); else if(impact == "Low") return(1); else return(0); //--- } //+------------------------------------------------------------------+ //| Convert day of the week to text | //+------------------------------------------------------------------+ string DayToStr(datetime time) { int ThisDay=TimeDayOfWeek(time); string day=""; switch(ThisDay) { case 0: day="Sun"; break; case 1: day="Mon"; break; case 2: day="Tue"; break; case 3: day="Wed"; break; case 4: day="Thu"; break; case 5: day="Fri"; break; case 6: day="Sat"; break; } return(day); } //+------------------------------------------------------------------+ //| Convert months to text | //+------------------------------------------------------------------+ string MonthToStr() { int ThisMonth=Month(); string month=""; switch(ThisMonth) { case 1: month="Jan"; break; case 2: month="Feb"; break; case 3: month="Mar"; break; case 4: month="Apr"; break; case 5: month="May"; break; case 6: month="Jun"; break; case 7: month="Jul"; break; case 8: month="Aug"; break; case 9: month="Sep"; break; case 10: month="Oct"; break; case 11: month="Nov"; break; case 12: month="Dec"; break; } return(month); } bool IsCurrency(string symbol) { //--- string sim = Symbol(); string right = StringSubstr(sim,3,0); string left = StringSubstr(sim,0,3); if(symbol == left || symbol == right) return(true); return(false); //--- } void news() { string sTags[7]= {"","<country>","<date><![CDATA[","<time><![CDATA[","<impact><![CDATA[","<forecast><![CDATA[","<previous><![CDATA["}; string eTags[7]= {"","","]]>","]]>","]]>","]]>","]]>"}; int index=0; int next=-1; int BoEvent=0,begin=0,end=0; string myEvent=""; datetime EventTime=0; int EventMinute=0; //--- split the currencies into the two parts string MainSymbol=StringSubstr(Symbol(),0,3); string SecondSymbol=StringSubstr(Symbol(),3,3); //--- loop to get the data from xml tags while(true) { BoEvent=StringFind(sData,"",BoEvent); if(BoEvent==-1) break; BoEvent+=7; next=StringFind(sData,"",BoEvent); if(next == -1) break; myEvent = StringSubstr(sData,BoEvent,next-BoEvent); BoEvent = next; begin=0; for(int i=0; i<7; i++) { Event[index][i]=""; next=StringFind(myEvent,sTags[i],begin); //--- Within this event, if tag not found, then it must be missing; skip it if(next==-1) continue; else { //--- We must have found the sTag okay... //--- Advance past the start tag begin=next+StringLen(sTags[i]); end=StringFind(myEvent,eTags[i],begin); //---Find start of end tag and Get data between start and end tag if(end>begin && end!=-1) Event[index][i]=StringSubstr(myEvent,begin,end-begin); } } if(ReportActive && MainSymbol!=Event[index][COUNTRY] && SecondSymbol!=Event[index][COUNTRY]) continue; if(!IsCurrency(Event[index][COUNTRY])) continue; if(!IncludeHigh && Event[index][IMPACT]=="High") continue; if(!IncludeMedium && Event[index][IMPACT]=="Medium") continue; if(!IncludeLow && Event[index][IMPACT]=="Low") continue; if(Event[index][TIME]=="All Day" || Event[index][TIME]=="Tentative" || Event[index][TIME]=="") continue; //--- sometimes they forget to remove the tags :) if(StringFind(Event[index][TITLE],"")!=-1) StringReplace(Event[index][TITLE],"]]>",""); if(StringFind(Event[index][TITLE],"]]>")!=-1) StringReplace(Event[index][TITLE],"]]>",""); //--- if(StringFind(Event[index][FORECAST],"<")!=-1) StringReplace(Event[index][FORECAST],"<",""); if(StringFind(Event[index][PREVIOUS],"<")!=-1) StringReplace(Event[index][PREVIOUS],"<",""); //--- set some values (dashes) if empty if(Event[index][FORECAST]=="") Event[index][FORECAST]="---"; if(Event[index][PREVIOUS]=="") Event[index][PREVIOUS]="---"; //--- Convert Event time to MT4 time EventTime=datetime(MakeDateTime(Event[index][DATE],Event[index][TIME])); //--- calculate how many minutes before the event (may be negative) EventMinute=int(EventTime-TimeGMT())/60; //--- Remove the event after x minutes if(EventMinute+EventDisplay<0) continue; //--- Set buffers MinuteBuffer[index]=EventMinute; ImpactBuffer[index]=ImpactToNumber(Event[index][IMPACT]); index++; } //--- loop to set arrays/buffers that uses to draw objects and alert for(i=0; i(-orderstart_afternews))){ order_run = false; }else order_run = true; } } //--- check then call draw / alert function if(IsEvent) DrawEvents(); else Draw("no more events","NO MORE EVENTS",14,"Arial Black",RemarksColor,2,10,30,"Get some rest!"); //if(ShowInfo) SymbolInfo(); }