#property copyright "Copyright © 2009 FEDORA" #property link "www.FEDORAFX.com" double g_ord_lots_76; double gd_92; double g_ord_lots_100; double g_price_108; double g_price_116; double g_lots_124; double gd_132; double gd_unused_148; string gs_dummy_156; string gs_dummy_164; bool gi_172; bool gi_176; int gi_180; int g_datetime_184; int g_datetime_188; int g_day_of_week_192; int g_cmd_196; int g_index_200; int gi_unused_220; int g_count_228; int g_ord_total_236; int g_pos_240; int g_cmd_244; double gd_248; double gd_256; double gd_264; double g_point_272; double gd_280; double gd_304; double g_ibands_312; double g_ibands_320; double g_ima_328; double g_ask_336; double g_bid_344; double g_price_552; double g_price_560; int gi_unused_568 = 3; int gi_unused_572 = 3; bool gi_576; bool gi_580; double gda_584[30]; double gd_unused_588; double gd_unused_604; double gd_612; double g_ask_620; bool gi_628; bool gi_632; double g_ask_660; double g_bid_668; double g_price_676; double g_price_684; int g_ticket_696; int g_cmd_700; bool gi_708; int gi_unused_712; int gi_unused_716; int gi_unused_720; int gi_unused_724; double gd_unused_728; double gd_736; double g_pips_744; double g_ask_752; double g_price_760; double g_price_768; double g_bid_776; double g_price_784; double g_price_792; int gi_unused_800 = 3; int gi_unused_804 = 0; string gs_unused_808 = "zDgO_"; int gi_820 = 3; double gda_824[50]; extern bool DrawFibo = TRUE; int gi_unused_832 = 1; int gi_unused_836 = 20; bool gi_840 = FALSE; string gs_844 = "0.01,0.02,0.04,0.08,0.16,0.32,0.64,1.28,2.56,5.12;"; extern int MethodHedge1 = 0; extern int MethodHedge2 = 100; extern int MethodHedge3 = 63; extern double M30XValue = 5.4545; bool gi_872 = TRUE; extern int HedgeTakeProfit = 10; int gi_880 = 50; int gi_884 = 10; int gi_888 = 20; int gi_892 = 10; bool gi_896 = TRUE; bool gi_900 = TRUE; extern double HedgeLots_ = 2.5; bool gi_912 = FALSE; int gi_916 = 2; int gi_920 = 5; double gd_924 = 0.0; int gi_932 = 1; int gi_unused_936 = 1; int gi_unused_940 = 1; int gi_944 = 2; double gd_948 = 0.1; int gi_956 = 0; int gi_960 = 50; int g_period_964 = 120; int gi_968 = 3; int gi_972 = 10; bool gi_976 = TRUE; int gi_980 = 5; int gi_984 = 1; int gi_988 = 2; extern bool LockPipsEnabled = TRUE; int gi_996 = 5; int gi_1000 = 2; int g_magic_1004 = 112244; string gs_fedora_1008 = "Fedora"; int gi_1016 = 90231269; bool gi_1020 = TRUE; int init() { double ld_12; gd_736 = MarketInfo(Symbol(), MODE_SPREAD) * Point; g_point_272 = MarketInfo(Symbol(), MODE_POINT); if ((gi_984 + gi_988) * Point < MarketInfo(Symbol(), MODE_SPREAD)) gi_988 = 2.0 * MarketInfo(Symbol(), MODE_SPREAD); int li_unused_0 = 0; int l_str_len_4 = StringLen(gs_844); int l_index_8 = 0; gd_unused_728 = HedgeLots_; for (l_index_8 = 0; l_index_8 < 30; l_index_8++) { ld_12 = gda_584[l_index_8 - 1]; gda_584[l_index_8] = ld_12 * gi_916; if (l_index_8 == 0) gda_584[0] = HedgeLots_ * gi_916; } return (0); } int deinit() { return (0); } int start() { if (gi_1016 != AccountNumber()) { Comment("Trade on account :" + AccountNumber() + " FORBIDDEN!"); return (0); } Comment(""); if (gi_1020 == TRUE) comentarios(); if (DayOfWeek() != g_day_of_week_192) { g_day_of_week_192 = DayOfWeek(); CalcularFibo(); } CheckEntry(); if (NumeroTTdeOrdens() == 0) { for (g_pos_240 = 0; g_pos_240 < 50; g_pos_240++) gda_824[g_pos_240] = 0; g_ask_336 = 999999; g_bid_344 = 0; gi_576 = FALSE; gi_580 = FALSE; } if (!ExisteHedgeON() && gi_872 == TRUE) ChecarHedge(); if (ExisteHedgeON() && gi_872 == TRUE) Checar2ndHedge(); if (ExisteHedgeON() && g_cmd_196 == OP_BUY) { if (LockPipsEnabled) LockPipsCheck("Hedge"); if (gi_912) DifTrailingStopCheck_Parameters(0, "Hedge", gi_888, gi_892 + gi_988); } if (ExisteHedgeON() && g_cmd_196 == OP_SELL) { if (LockPipsEnabled) LockPipsCheck("Hedge"); if (gi_912) DifTrailingStopCheck_Parameters(1, "Hedge", gi_888, gi_892 + gi_988); } if (!ExisteHedgeON() && Bid > gd_264 && gi_820 == TRUE) gi_176 = TRUE; if (!ExisteHedgeON() && Bid < gd_264 && gi_820 == FALSE) gi_172 = TRUE; if (gi_576 && gi_976) DifTrailingStopCheck_Parameters(1, gs_fedora_1008, gi_980, gi_984 + gi_988); if (Bid <= g_ima_328 + gi_944 * Point && OrdensEmAndamento(g_magic_1004, 1, OP_SELL, gs_fedora_1008) == 1) { gi_576 = TRUE; gi_580 = FALSE; closeallBSNeg(OP_SELL, 99, g_magic_1004, gs_fedora_1008); } if (gi_580 && gi_976) DifTrailingStopCheck_Parameters(0, gs_fedora_1008, gi_980, gi_984 + gi_988); if (Bid >= g_ima_328 - gi_944 * Point && OrdensEmAndamento(g_magic_1004, 1, OP_BUY, gs_fedora_1008) == 1) { gi_580 = TRUE; gi_576 = FALSE; closeallBSNeg(OP_BUY, 99, g_magic_1004, gs_fedora_1008); } if (gd_612 == 1.0 && gi_632 == TRUE) monitorar(); if (gd_612 == 2.0 && gi_628 == TRUE) monitorar2(); if (LastTradeProf(g_magic_1004) == 1 && gd_612 != 0.0) { close_agendadas(); g_index_200 = 0; g_ask_660 = 0; g_bid_668 = 0; g_price_676 = 0; g_price_684 = 0; gi_708 = FALSE; gd_612 = 0; g_ask_620 = 0; gi_632 = FALSE; gi_628 = FALSE; } if (g_index_200 >= gi_884 && !ExisteHedgeCiclo()) { close_agendadas(); g_index_200 = 0; g_ask_660 = 0; g_bid_668 = 0; g_price_676 = 0; g_price_684 = 0; gi_708 = FALSE; gd_612 = 0; g_ask_620 = 0; gi_632 = FALSE; gi_628 = FALSE; } return (0); } void Checar2ndHedge() { if (Bid > gd_248 && gi_820 == TRUE && !ExisteHedge2ON() && !ExisteHedge3ON() && Bid < gd_248 + 10.0 * Point && gd_612 == 0.0) { closeHedge(); d1buygbp(); } if (Bid < gd_248 && gi_820 == FALSE && !ExisteHedge2ON() && !ExisteHedge3ON() && Bid > gd_248 - 10.0 * Point && gd_612 == 0.0) { closeHedge(); d1sellgbp(); } } void ChecarHedge() { int li_unused_0 = 0; int li_unused_4 = -99; if ((Bid <= gd_256 - gi_932 * Point && Close[1] > gd_256 && gi_820 == FALSE && gi_176 == TRUE && ChecarStoch(1)) || (Ask <= gd_264 - gi_932 * Point && Close[1] > gd_264 && gi_820 == TRUE && gi_176 == TRUE && ChecarStoch(1))) { SendHedgeOrder(1, 1); gi_176 = FALSE; } if ((Bid >= gd_256 + gi_932 * Point && Close[1] < gd_256 && gi_820 == TRUE && gi_172 == TRUE && ChecarStoch(0)) || (Ask >= gd_264 + gi_932 * Point && Close[1] < gd_264 && gi_820 == FALSE) && gi_172 == TRUE && ChecarStoch(0)) { SendHedgeOrder(0, 1); gi_172 = FALSE; } } void SendHedgeOrder(int ai_0, int ai_4) { string l_comment_16; double ld_24; double l_lots_32; int l_count_8 = 0; int l_ticket_12 = -99; if (ai_4 == 1) { if (gd_924 != 0.0) l_lots_32 = GetLots(gi_880); else l_lots_32 = HedgeLots_; if (l_lots_32 == 0.0) gd_unused_148 = HedgeLots_; l_comment_16 = "Hedge"; } if (ai_4 == 2) { l_lots_32 = HedgeLots_ * gi_916; l_comment_16 = "Hedge2"; } if (ai_0 == 0) { if (gi_896) Alert(" Hedge Actived at ", Symbol(), " Price: ", Ask); if (gi_900) SendMail(" Hedge Actived at " + Symbol() + " Price: " + DoubleToStr(Ask, 5), ""); if (ai_4 == 1) { g_price_108 = 0; if (HedgeTakeProfit == 0) g_price_116 = 0; else g_price_116 = Ask + HedgeTakeProfit * Point; } if (ai_4 == 2) { g_price_108 = 0; ld_24 = (gd_248 - gd_264) / Point / gi_916 + gi_920; g_price_116 = Ask + ld_24 * Point; Print(" CalculoTP = ", ld_24, " tpH = ", g_price_116, " bid = ", Bid); } while (l_ticket_12 < 0) { RefreshRates(); l_ticket_12 = OrderSend(Symbol(), OP_BUY, l_lots_32, Ask, 5, g_price_108, g_price_116, l_comment_16, g_magic_1004, 0, Blue); if (l_ticket_12 < 0) { Print("erro buy = ", gi_180, " sl= ", g_price_108, " tp = ", g_price_116, " lt = ", l_lots_32, " texto = ", l_comment_16, " ask = ", Ask, " GetLastError = ", GetLastError()); l_count_8++; } gi_unused_220 = Bars; while (IsTradeContextBusy()) Sleep(250); if (l_count_8 > 10) l_ticket_12 = 99; } if (l_comment_16 != gs_fedora_1008) { g_ask_752 = Ask; g_price_760 = g_price_108; g_price_768 = g_price_116; } Print(" Hedge at = ", Ask, " lt = ", l_lots_32, " texto = ", l_comment_16); } if (ai_0 == 1) { if (gi_896) Alert(" Hedge Actived at ", Symbol(), " Price: ", Bid); if (gi_900) SendMail(" Hedge Actived at " + Symbol() + " Price: " + DoubleToStr(Ask, 5), ""); if (ai_4 == 1) { g_price_108 = 0; if (HedgeTakeProfit == 0) g_price_116 = 0; else g_price_116 = Bid - HedgeTakeProfit * Point; } if (ai_4 == 2) { g_price_108 = 0; ld_24 = (gd_264 - gd_248) / Point / gi_916 + gi_920; g_price_116 = Bid - ld_24 * Point; Print(" CalculoTP = ", ld_24, " tpH = ", g_price_116, " bid = ", Bid); } while (l_ticket_12 < 0) { RefreshRates(); l_ticket_12 = OrderSend(Symbol(), OP_SELL, l_lots_32, Bid, 5, g_price_108, g_price_116, l_comment_16, g_magic_1004, 0, Red); if (l_ticket_12 < 0) { Print("erro sell = ", gi_180, " sl= ", g_price_108, " tp = ", g_price_116, " lt = ", l_lots_32, " texto = ", l_comment_16, " ask = ", Ask, " GetLastError = ", GetLastError()); l_count_8++; } gi_unused_220 = Bars; while (IsTradeContextBusy()) Sleep(250); if (l_comment_16 != gs_fedora_1008) { g_bid_776 = Bid; g_price_784 = g_price_108; g_price_792 = g_price_116; } if (l_count_8 > 10) l_ticket_12 = 99; } Print(" Hedge at = ", Bid, " lt = ", l_lots_32, " texto = ", l_comment_16); } } int ChecarStoch(int ai_0) { double l_istochastic_4 = iStochastic(NULL, PERIOD_H1, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0); double l_istochastic_12 = iStochastic(NULL, PERIOD_H1, 14, 3, 3, MODE_SMA, 0, MODE_MAIN, 0); double l_istochastic_20 = iStochastic(NULL, PERIOD_M30, 14, 3, 3, MODE_SMA, 0, MODE_MAIN, 0); double l_istochastic_28 = iStochastic(NULL, PERIOD_M30, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0); double l_istochastic_36 = iStochastic(NULL, PERIOD_H4, 14, 3, 3, MODE_SMA, 0, MODE_MAIN, 0); if (ai_0 == 1 && l_istochastic_4 < 23.6 && l_istochastic_12 < 23.6 && l_istochastic_20 - M30XValue < 23.6 && l_istochastic_28 - M30XValue < 23.6 && l_istochastic_36 < 23.6) return (1); if (ai_0 == 0 && l_istochastic_4 > 76.4 && l_istochastic_12 > 76.4 && l_istochastic_20 + M30XValue > 76.4 && l_istochastic_28 + M30XValue > 76.4 && l_istochastic_36 > 76.4) return (1); return (0); } void CalcularFibo() { double l_high_8; double l_low_0 = 9999; double l_high_16 = High[iHighest(NULL, PERIOD_H1, MODE_HIGH, 24, 0)]; double l_low_24 = Low[iLowest(NULL, PERIOD_H1, MODE_LOW, 24, 0)]; for (int li_32 = 24; li_32 > 0; li_32--) { if (Low[li_32] < Low[li_32 + 1] && Low[li_32] < l_low_0) { l_low_0 = Low[li_32]; g_datetime_184 = iTime(Symbol(), PERIOD_H1, li_32); } if (High[li_32] > High[li_32 + 1] && High[li_32] > l_high_8) { l_high_8 = High[li_32]; g_datetime_188 = iTime(Symbol(), PERIOD_H1, li_32); } } if (g_datetime_188 > g_datetime_184) { gi_820 = FALSE; gd_280 = DgGetFiboValue(23, l_low_24, l_high_16, 0); gd_304 = DgGetFiboValue(74, l_low_24, l_high_16, 0); gd_264 = DgGetFiboValue(MethodHedge1, l_low_24, l_high_16, 0); gd_256 = DgGetFiboValue(MethodHedge2, l_low_24, l_high_16, 0); gd_248 = DgGetFiboValue(MethodHedge3, l_low_24, l_high_16, 0); if (DrawFibo) DgFibo("1", 0, g_datetime_184, l_low_24, g_datetime_188, l_high_16, Blue); } if (g_datetime_184 > g_datetime_188) { gi_820 = TRUE; gd_280 = DgGetFiboValue(23, l_high_16, l_low_24, 0); gd_304 = DgGetFiboValue(74, l_high_16, l_low_24, 0); gd_264 = DgGetFiboValue(MethodHedge1, l_high_16, l_low_24, 0); gd_256 = DgGetFiboValue(MethodHedge2, l_high_16, l_low_24, 0); gd_248 = DgGetFiboValue(MethodHedge3, l_high_16, l_low_24, 0); if (DrawFibo) DgFibo("1", 0, g_datetime_188, l_high_16, g_datetime_184, l_low_24, Red); } } double DgGetFiboValue(double ad_0, double ad_8, double ad_16, bool ai_24 = FALSE) { double ld_28 = MathAbs(ad_16 - ad_8) / Point; double ld_ret_36 = 0; if (ad_0 > 1.0) ld_ret_36 = MathFloor((ld_28 * (ad_0 - 100.0) + 49.0) / 100.0); else { if (ad_0 == 1.0) ld_ret_36 = 0; else ld_ret_36 = -ld_28; } if (ai_24 == FALSE && ad_16 > ad_8) ld_ret_36 = NormalizeDouble(ad_8 - ld_ret_36 * Point, Digits); if (ai_24 == FALSE && ad_16 < ad_8) ld_ret_36 = NormalizeDouble(ad_8 + ld_ret_36 * Point, Digits); return (ld_ret_36); } bool ExisteHedgeON() { for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_1004 && OrderComment() == "Hedge") { g_cmd_196 = OrderType(); return (TRUE); } } return (FALSE); } bool ExisteHedge2ON() { for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_1004 && OrderComment() == "Hedge2") { g_ord_lots_76 = OrderLots(); if (OrderType() == OP_BUY) gd_92 = OrderTakeProfit() - OrderOpenPrice(); else gd_92 = OrderOpenPrice() - OrderTakeProfit(); return (TRUE); } } return (FALSE); } bool ExisteHedge3ON() { for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_1004 && OrderComment() == "Hedge3") return (TRUE); } return (FALSE); } void closeHedge() { int l_ord_total_8; int l_ord_close_16; int l_count_0 = 0; bool li_4 = FALSE; while (IsTradeContextBusy()) Sleep(250); if (OrdersTotal() != 0) { while (li_4 != TRUE) { l_ord_total_8 = OrdersTotal(); for (int l_pos_12 = l_ord_total_8 - 1; l_pos_12 >= 0; l_pos_12--) { OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_1004 && OrderSymbol() == Symbol() && OrderComment() == "Hedge") { g_ord_lots_100 = OrderLots(); l_ord_close_16 = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 10, Yellow); if (l_ord_close_16 == 1) li_4 = TRUE; else EsperarServidorDisponivel(); } } l_count_0++; if (l_count_0 > 10) li_4 = TRUE; } } } void closeallBSNeg(int a_cmd_0, int ai_unused_4, int a_magic_8, string as_12) { int l_ord_total_28; int l_ord_close_36; int l_count_20 = 0; bool li_24 = FALSE; Sleep(250); while (IsTradeContextBusy()) Sleep(250); if (OrdersTotal() != 0) { while (li_24 != TRUE) { l_ord_total_28 = OrdersTotal(); for (int l_pos_32 = l_ord_total_28 - 1; l_pos_32 >= 0; l_pos_32--) { OrderSelect(l_pos_32, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == a_magic_8 && OrderSymbol() == Symbol() && OrderProfit() < 0.0 && OrderComment() == as_12 && OrderType() == a_cmd_0) l_ord_close_36 = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 10, Yellow); if (l_ord_close_36 == 1) li_24 = TRUE; else EsperarServidorDisponivel(); } l_count_20++; if (l_count_20 > 10) li_24 = TRUE; } } } void EsperarServidorDisponivel() { Sleep(250); while (IsTradeContextBusy()) Sleep(250); } int NumeroTTdeOrdens() { int l_count_0 = 0; g_ord_total_236 = OrdersTotal(); if (g_ord_total_236 != 0) { for (g_pos_240 = 0; g_pos_240 < g_ord_total_236; g_pos_240++) { OrderSelect(g_pos_240, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_1004) l_count_0++; } } return (l_count_0); } void CheckEntry() { g_ibands_320 = iBands(NULL, 0, g_period_964, gi_968, 0, PRICE_CLOSE, MODE_UPPER, 0); g_ima_328 = iMA(NULL, 0, g_period_964, 0, MODE_SMA, PRICE_CLOSE, 1); NormalizeDouble(g_ima_328, 4); g_ibands_312 = iBands(NULL, 0, g_period_964, gi_968, 0, PRICE_CLOSE, MODE_LOWER, 0); if (Bid < g_ibands_312 - 1.0 * Point && Bid <= g_ask_336 - gi_972 * Point && (g_ibands_312 > gd_280 && g_ibands_320 < gd_304) || (g_ibands_320 < gd_280 && g_ibands_312 > gd_304)) SendOrder(0); if (Bid > g_ibands_320 + 1.0 * Point && Bid >= g_bid_344 + gi_972 * Point && (g_ibands_312 > gd_280 && g_ibands_320 < gd_304) || (g_ibands_320 < gd_280 && g_ibands_312 > gd_304)) SendOrder(1); } void SendOrder(int ai_0) { int l_count_4; int l_ticket_8; if (gd_924 != 0.0) g_lots_124 = GetLots(gi_956 + gi_984); else g_lots_124 = gd_948; if (gi_840) { g_lots_124 = gda_584[g_index_200]; if ((g_ima_328 > gda_824[g_index_200 - 1] && ai_0 == 1) || (g_ima_328 < gda_824[g_index_200] && ai_0 == 0)) { g_lots_124 = gda_584[g_index_200]; g_index_200++; } } if (ai_0 == 0) { l_count_4 = 0; l_ticket_8 = -99; if (gi_956 == 0) g_price_552 = 0; else g_price_552 = Ask - gi_956 * Point; if (gi_960 == 0) g_price_560 = 0; else g_price_560 = Ask + gi_960 * Point; while (l_ticket_8 < 0) { RefreshRates(); l_ticket_8 = OrderSend(Symbol(), OP_BUY, g_lots_124, Ask, 5, g_price_552, g_price_560, gs_fedora_1008, g_magic_1004, 0, Blue); g_ask_336 = Ask; if (l_ticket_8 < 0) { Print("erro buy = ", gi_180, " sl= ", g_price_552, " tp = ", g_price_560, " lt = ", g_lots_124, " texto = ", gd_132, " ask = ", Ask, " GetLastError = ", GetLastError()); l_count_4++; } gi_unused_220 = Bars; gi_unused_568 = 0; while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_8 = 99; ArmazenarNoVetor(Ask); } } if (ai_0 == 1) { l_ticket_8 = -1; l_count_4 = 0; if (gi_956 == 0) g_price_552 = 0; else g_price_552 = Bid + gi_956 * Point; if (gi_960 == 0) g_price_560 = 0; else g_price_560 = Bid - gi_960 * Point; while (l_ticket_8 < 0) { RefreshRates(); l_ticket_8 = OrderSend(Symbol(), OP_SELL, g_lots_124, Bid, 5, g_price_552, g_price_560, gs_fedora_1008, g_magic_1004, 0, Red); g_bid_344 = Bid; if (l_ticket_8 < 0) { Print("erro buy = ", gi_180, " sl= ", g_price_552, " tp = ", g_price_560, " lt = ", g_lots_124, " texto = ", gd_132, " ask = ", Ask, " GetLastError = ", GetLastError()); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); gi_unused_568 = 1; gi_unused_220 = Bars; if (l_count_4 > 10) l_ticket_8 = 99; ArmazenarNoVetor(Bid); } } } void ArmazenarNoVetor(double ad_0) { for (g_pos_240 = 0; g_pos_240 < 50; g_pos_240++) { if (gda_824[g_pos_240] == 0.0) { gda_824[g_pos_240] = ad_0; return; } } } int OrdensEmAndamento(int a_magic_0, int a_magic_4, int a_cmd_8, string as_12) { g_count_228 = 0; g_cmd_244 = 111; bool li_ret_20 = FALSE; g_ord_total_236 = OrdersTotal(); for (g_pos_240 = 0; g_pos_240 < g_ord_total_236; g_pos_240++) { OrderSelect(g_pos_240, SELECT_BY_POS, MODE_TRADES); if (a_cmd_8 == OP_BUY || a_cmd_8 == OP_SELL) { if (OrderSymbol() == Symbol() && OrderComment() == as_12 && OrderMagicNumber() == a_magic_0 || OrderMagicNumber() == a_magic_4 && a_cmd_8 == OrderType()) { li_ret_20 = TRUE; g_cmd_244 = OrderType(); break; } } if (a_cmd_8 == OP_BUYLIMIT) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == a_magic_0 || OrderMagicNumber() == a_magic_4) { li_ret_20 = TRUE; g_cmd_244 = OrderType(); if (OrderComment() != "1st") break; g_count_228++; break; } } } return (li_ret_20); } void DifTrailingStopCheck_Parameters(int ai_unused_0, string as_4, int ai_12, int ai_16) { for (int l_pos_20 = 0; l_pos_20 < OrdersTotal(); l_pos_20++) { OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_1004 && OrderComment() == as_4) { if (OrderType() == OP_BUY) { if (ai_12 > 0) { if (Bid >= Point * (ai_12 + ai_16 + gi_988) + OrderStopLoss() || OrderStopLoss() == 0.0 && OrderProfit() > 0.0) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * ai_16, OrderTakeProfit(), 0, MediumSeaGreen); continue; } } } if (OrderType() == OP_SELL) { if (ai_12 > 0) if (Ask <= OrderStopLoss() - Point * (ai_12 + ai_16 + gi_988) || OrderStopLoss() == 0.0 && OrderProfit() > 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * ai_16, OrderTakeProfit(), 0, DarkOrange); } } } } double GetLots(double ad_0) { double ld_ret_8; double ld_16 = AccountEquity() * gd_924 / 100.0; double ld_24 = ld_16 / ad_0; if (MarketInfo(Symbol(), MODE_LOTSIZE) == 100000.0) ld_ret_8 = ld_24 / 10.0; if (MarketInfo(Symbol(), MODE_LOTSIZE) == 10000.0) ld_ret_8 = 1.0 * ld_24; return (ld_ret_8); } int DgFibo(string a_name_0, int a_window_8, int a_datetime_12, double ad_16, int a_datetime_24, double ad_28, color a_color_36, int a_style_40 = 0, int a_style_44 = 2, color a_color_48 = -1, bool a_bool_52 = FALSE) { if (a_color_48 == CLR_NONE) a_color_48 = a_color_36; ObjectCreate(a_name_0, OBJ_FIBO, a_window_8, 1, 1, 2, 2); ObjectSet(a_name_0, OBJPROP_TIME1, a_datetime_12); ObjectSet(a_name_0, OBJPROP_PRICE1, ad_16); ObjectSet(a_name_0, OBJPROP_TIME2, a_datetime_24); ObjectSet(a_name_0, OBJPROP_PRICE2, ad_28); ObjectSet(a_name_0, OBJPROP_COLOR, a_color_36); ObjectSet(a_name_0, OBJPROP_LEVELCOLOR, a_color_48); ObjectSet(a_name_0, OBJPROP_STYLE, a_style_40); ObjectSet(a_name_0, OBJPROP_LEVELSTYLE, a_style_44); ObjectSet(a_name_0, OBJPROP_BACK, a_bool_52); return (0); } void LockPipsCheck(string as_0) { int l_ord_total_8 = OrdersTotal(); for (int l_pos_12 = 0; l_pos_12 < l_ord_total_8; l_pos_12++) { if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_1004 && OrderComment() == as_0) { if (OrderType() == OP_BUY) { if (Bid >= OrderOpenPrice() + gi_996 * Point && OrderStopLoss() != OrderOpenPrice() + gi_1000 * Point && OrderStopLoss() == 0.0 || OrderStopLoss() < OrderOpenPrice()) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + gi_1000 * Point, OrderTakeProfit(), OrderExpiration(), MediumSeaGreen); Print("Locked Pips B - Comment ", as_0); continue; } } if (OrderType() == OP_SELL) { if (Ask <= OrderOpenPrice() - gi_996 * Point && OrderStopLoss() != OrderOpenPrice() - gi_1000 * Point && OrderStopLoss() == 0.0 || OrderStopLoss() > OrderOpenPrice()) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - gi_1000 * Point, OrderTakeProfit(), OrderExpiration(), MediumSeaGreen); Print("Locked Pips S - Comment ", as_0); } } } } } } void comentarios() { string l_str_concat_0 = StringConcatenate(gi_840, " | ", gi_872, " | ", " | ", HedgeTakeProfit, " | ", gi_880, " | ", gi_888, " | ", gi_892, " | ", gi_896, " | ", gi_900, " | ", HedgeLots_, " | ", gi_944, " | ", gd_948, " | ", gi_956, " | ", g_period_964, " | ", gi_968, " | ", gi_972, " | ", gi_976, " | ", gi_980, " | ", gi_984, " | ", gi_960, " | ", gd_924, " | ", g_magic_1004, " | ", gs_fedora_1008); Comment("----Trabalhando... ", "\n", "Upper = ", g_ibands_320, "\n", "---------- > Midle = ", g_ima_328, "\n", "Down = ", g_ibands_312, "\n", "fibo23 = ", gd_280, "\n", "fibo74 = ", gd_304, "\n", "fibo1 = ", gd_264, "\n", "fibo2 = ", gd_256, "\n", "fibo3 = ", gd_248, "\n", "fibo Value = ", gi_820, "\n", "LiberadoSellDeNovo = ", gi_176, "\n", "LiberadoBuyDeNovo = ", gi_172, "\n", "VetorPreco[0] = ", gda_824[0], "\n", "VetorPreco[1] = ", gda_824[1], "\n", "VetorPreco[2] = ", gda_824[2], "\n", "LotInput[0] = ", gda_584[0], "\n", "LotInput[1] = ", gda_584[1], "\n", "NumeroLots = ", g_index_200, "\n", "ChecarTrailSell = ", gi_576, "\n", "ChecarTrailBuy = ", gi_580, "\n", "Parameters = ", l_str_concat_0, "\n"); } void d1buygbp() { int l_ticket_0 = -1; int l_count_4 = 0; gi_unused_800 = 0; Print(" 1ST Buy Trade "); if (g_index_200 < gi_884) { EsperarServidorDisponivel(); g_price_108 = 0; g_pips_744 = NormalizeDouble((Ask - g_bid_776) / 2.0 / Point + gi_920, 0); g_price_116 = Ask + g_pips_744 * Point; Print(" CalculoTP = ", g_pips_744, " tpH = ", g_price_116, " bid = ", Bid); gd_unused_604 = Ask; gd_612 = 2; g_price_676 = g_price_116; g_ask_620 = Ask; g_bid_668 = g_bid_776; gi_628 = TRUE; gi_708 = FALSE; g_lots_124 = gda_584[g_index_200]; l_ticket_0 = -1; l_count_4 = 0; if (g_index_200 <= gi_884) { while (l_ticket_0 < 0) { RefreshRates(); l_ticket_0 = OrderSend(Symbol(), OP_BUY, g_lots_124, Ask, 5, g_bid_668, g_price_676, "HedgeRange-BUYPrincipal", g_magic_1004, 0, Blue); if (l_ticket_0 < 0) { Print(" GetLastError = ", GetLastError()); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_0 = 99; gi_unused_724 = l_ticket_0; } } g_index_200++; g_lots_124 = gda_584[g_index_200]; l_ticket_0 = -1; l_count_4 = 0; if (g_index_200 <= gi_884) { while (l_ticket_0 < 0) { RefreshRates(); l_ticket_0 = OrderSend(Symbol(), OP_SELLSTOP, g_lots_124, g_bid_776, 5, g_price_784, g_bid_776 - g_pips_744 * Point, "HedgeRange-S", g_magic_1004, 0, Red); if (l_ticket_0 < 0) { Print(" GetLastError = ", GetLastError(), " tp-UltimaHedgeSellSL = ", g_bid_776 - g_pips_744 * Point, " sl-UltimaHedgeSellTP = ", g_price_792); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_0 = 99; gd_unused_588 = l_ticket_0; } } } } void monitorar2() { int l_ticket_0 = -1; int l_count_4 = 0; if (g_index_200 < gi_884) { gi_unused_716 = 0; if (gi_708 == TRUE && Ask >= g_ask_620) { EsperarServidorDisponivel(); l_ticket_0 = -1; l_count_4 = 0; g_index_200++; g_lots_124 = gda_584[g_index_200]; if (g_index_200 <= gi_884) { while (l_ticket_0 < 0) { RefreshRates(); l_ticket_0 = OrderSend(Symbol(), OP_SELLSTOP, g_lots_124, g_bid_776, 5, g_price_784, g_bid_776 - g_pips_744 * Point, "HedgeRange-B", g_magic_1004, 0, Red); if (l_ticket_0 < 0) { Print(" GetLastError = ", GetLastError(), " tp-UltimaHedgeSellSL = ", g_bid_776 - g_pips_744 * Point, " sl-UltimaHedgeSellTP = ", g_price_792); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_0 = 99; gd_unused_588 = l_ticket_0; } } gi_708 = FALSE; } if (Bid <= g_bid_668 && gi_708 == FALSE) { if (g_index_200 < gi_884) { EsperarServidorDisponivel(); l_ticket_0 = -1; l_count_4 = 0; g_index_200++; g_lots_124 = gda_584[g_index_200]; if (g_index_200 <= gi_884) { while (l_ticket_0 < 0) { RefreshRates(); l_ticket_0 = OrderSend(Symbol(), OP_BUYSTOP, g_lots_124, g_ask_620, 5, g_bid_668, g_price_676, "HedgeRange-B", g_magic_1004, 0, Blue); if (l_ticket_0 < 0) { Print(" GetLastError = ", GetLastError()); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_0 = 99; gd_unused_588 = l_ticket_0; } } gi_708 = TRUE; } } } } void d1sellgbp() { int l_ticket_0 = -1; int l_count_4 = 0; gi_unused_800 = 0; Print(" 1ST Sell Trade "); if (g_index_200 < gi_884) { g_pips_744 = NormalizeDouble((g_ask_752 - Bid) / 2.0 / Point + gi_920, 0); g_price_116 = Bid - g_pips_744 * Point; Print(" CalculoTP = ", g_pips_744, " tpH = ", g_price_116, " bid = ", Bid); EsperarServidorDisponivel(); g_ask_620 = Bid; g_ask_660 = g_ask_752; g_price_684 = g_price_116; gd_612 = 1; gi_632 = TRUE; gi_708 = FALSE; l_ticket_0 = -1; l_count_4 = 0; g_lots_124 = gda_584[g_index_200]; if (g_index_200 <= gi_884) { while (l_ticket_0 < 0) { RefreshRates(); l_ticket_0 = OrderSend(Symbol(), OP_SELL, g_lots_124, Bid, 5, g_ask_660, g_price_684, "HedgeRange-SellPrincipal", g_magic_1004, 0, Red); if (l_ticket_0 < 0) { Print(" GetLastError = ", GetLastError()); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_0 = 99; gi_unused_720 = l_ticket_0; } } g_index_200++; g_lots_124 = gda_584[g_index_200]; if (g_index_200 < gi_884) { EsperarServidorDisponivel(); l_ticket_0 = -1; l_count_4 = 0; if (g_index_200 <= gi_884) { while (l_ticket_0 < 0) { RefreshRates(); l_ticket_0 = OrderSend(Symbol(), OP_BUYSTOP, g_lots_124, g_ask_660, 5, g_ask_620, g_ask_660 + g_pips_744 * Point, "HedgeRange-B", g_magic_1004, 0, Blue); if (l_ticket_0 < 0) { Print(" GetLastError = ", GetLastError(), " UltimaHedgeBuySL = ", g_price_760, " UltimaHedgeBuyTP = ", g_price_768, " ceu = ", g_ask_660); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_0 = 99; gd_unused_588 = l_ticket_0; } } } } } void monitorar() { int l_ticket_0 = -1; int l_count_4 = 0; gi_unused_712 = 0; if (gi_708 == TRUE && Bid <= g_ask_620) { if (g_index_200 >= gi_884) return; g_index_200++; g_lots_124 = gda_584[g_index_200]; EsperarServidorDisponivel(); l_ticket_0 = -1; l_count_4 = 0; if (g_index_200 <= gi_884) { while (l_ticket_0 < 0) { RefreshRates(); l_ticket_0 = OrderSend(Symbol(), OP_BUYSTOP, g_lots_124, g_ask_660, 5, g_price_760, g_ask_660 + g_pips_744 * Point, "HedgeRange-B", g_magic_1004, 0, Blue); if (l_ticket_0 < 0) { Print(" GetLastError = ", GetLastError(), " UltimaHedgeBuySL = ", g_price_760, " UltimaHedgeBuyTP = ", g_price_768, " ceu = ", g_ask_660); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_0 = 99; gd_unused_588 = l_ticket_0; } } gi_708 = FALSE; } if (Ask >= g_ask_660 && gi_708 == FALSE) { if (g_index_200 < gi_884) { g_index_200++; g_lots_124 = gda_584[g_index_200]; EsperarServidorDisponivel(); l_ticket_0 = -1; l_count_4 = 0; if (g_index_200 <= gi_884) { while (l_ticket_0 < 0) { RefreshRates(); l_ticket_0 = OrderSend(Symbol(), OP_SELLSTOP, g_lots_124, g_ask_620, 5, g_ask_660, g_price_684, "HedgeRange-S", g_magic_1004, 0, Red); if (l_ticket_0 < 0) { Print(" GetLastError = ", GetLastError()); l_count_4++; } while (IsTradeContextBusy()) Sleep(250); if (l_count_4 > 10) l_ticket_0 = 99; gd_unused_588 = l_ticket_0; } } gi_708 = TRUE; g_ord_total_236 = OrdersTotal(); } } } void close_agendadas() { EsperarServidorDisponivel(); g_ord_total_236 = OrdersTotal(); for (g_pos_240 = g_ord_total_236; g_pos_240 >= 0; g_pos_240--) { OrderSelect(g_pos_240, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_1004 && OrderComment() != gs_fedora_1008) { if (OrderType() == OP_SELLSTOP) { OrderDelete(OrderTicket()); if (gi_1020 == TRUE) Print(",delete 8 erro = : ", GetLastError()); } } } g_ord_total_236 = OrdersTotal(); for (g_pos_240 = g_ord_total_236; g_pos_240 >= 0; g_pos_240--) { OrderSelect(g_pos_240, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_1004 && OrderComment() != gs_fedora_1008) { if (OrderType() == OP_BUYSTOP) { OrderDelete(OrderTicket()); if (gi_1020 == TRUE) Print(",delete 9 erro = : ", GetLastError()); } } } } int LastTradeProf(int a_magic_0) { int li_ret_4 = 0; int l_hist_total_8 = OrdersHistoryTotal(); int l_ticket_12 = 0; if (l_hist_total_8 <= 0) li_ret_4 = 0; if (l_hist_total_8 > 0) { for (int l_hist_total_16 = l_hist_total_8; l_hist_total_16 >= 0; l_hist_total_16--) { if (OrderSelect(l_hist_total_16, SELECT_BY_POS, MODE_HISTORY)) if (OrderSymbol() == Symbol() && OrderMagicNumber() == a_magic_0 && OrderTicket() > l_ticket_12) l_ticket_12 = OrderTicket(); } } OrderSelect(l_ticket_12, SELECT_BY_TICKET, MODE_HISTORY); if (OrderCloseTime() != 0 && OrderProfit() > 0.0 && OrderTicket() != g_ticket_696) { g_ticket_696 = OrderTicket(); li_ret_4 = 1; g_cmd_700 = OrderType(); } OrderSelect(l_ticket_12, SELECT_BY_TICKET, MODE_HISTORY); if (OrderCloseTime() != 0 && OrderProfit() < 0.0 && OrderTicket() != g_ticket_696) { g_ticket_696 = OrderTicket(); li_ret_4 = -1; if (OrderType() == OP_SELL) g_cmd_700 = 1; else g_cmd_700 = 0; } return (li_ret_4); } bool ExisteHedgeCiclo() { for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_1004 && OrderComment() != gs_fedora_1008) return (TRUE); } return (FALSE); }