Time: 2010-02-27 | Download file:Vril-X1~.mq4
/* Generated by EX4-TO-MQ4 decompiler V4.0.228.1e [-] Website: http://purebeam.biz E-mail : purebeam@gmail.com */ extern string Expert_Name = "vril-x1"; extern int Magic = 111111; extern int Slippage = 3; extern string Main_data = " Trade Volume & Trade Method"; extern double Lots = 0.1; extern int MaxOrders = 10; extern double TakeProfit = 0.0; extern double ProfitTarget = 0.0; extern double MinProfit = 1.0; extern double ProfitMode = 0.0; extern double StopLoss = 100.0; extern int TrailingMode = 2; extern double TrailingStop = 0.0; extern double StopDeviation = 1.0; extern double BreakEven = 0.0; extern double PipsLock = 0.0; extern int ExitMode = 10; extern double MaxSpread = 0.0; extern int ECN_Mode = 1; extern int ReverseLogic = 0; extern string Time_Inputs = " Timing parameters "; extern int MainTimeFrame = -1; extern int StartHour = 6; extern int StartMinute = 0; extern int EndHour = 22; extern int EndMinute = 0; extern int MonStartHour = 8; extern int MonStartMinute = 0; extern int FriEndHour = 18; extern int FriEndMinute = 0; extern int NonTradeDay = 0; extern int CloseTimeMode = 0; extern int CloseHour = 24; extern int CloseMinute = 0; extern int FriCloseHour = 20; extern int FriCloseMinute = 55; extern double ProcessTime = 3.0; extern string TS_Inputs = " TickSmoother parameters:"; extern int TS_TimeFrame = -1; extern int TS_Price = 0; extern int TS_FastMA = 9; extern int TS_SlowMA = 20; extern int TS_ConfMA1 = 55; extern int TS_ConfMA2 = 120; extern int TS_MA_Mode = 1; extern int TS_NumTicks = 0; extern int TS_NumSecs = 10; extern int TS_MaxBars = 500; extern int TS_Shift = 1; extern int TS_Mode = 6; extern string MC_Inputs = " MAs Confirmation parameters:"; extern int MC_TimeFrame = 15; extern int MC_Price = 0; extern int MC_FastMA = 9; extern int MC_SlowMA = 20; extern int MC_ConfMA1 = 55; extern int MC_ConfMA2 = 120; extern int MC_MA_Mode = 1; extern int MC_Shift = 0; extern int MC_Mode = 3; extern string MM_inputs = " MoneyManagement by L.Williams "; extern int MM = 1; extern double MaxRisk = 0.03; extern double MaxLoss = 0.0; extern double MaxLots = 1.0; extern double MGMode = 1.0; extern double MGRatio = 2.0; extern double MGStep = 15.0; extern double MGPips = 15.0; int gi_unused_452 = 0; int g_count_456 = 0; int gi_460 = 5; int g_datetime_464; int g_datetime_468; double gd_472; double gd_480; double gd_488; double gd_496; double gd_504; double gd_512; double gd_520; double gd_528; double g_ima_536; double g_ima_544; double g_ima_552; double g_ima_560; double g_ima_568; double g_ima_576; double g_ima_584; double g_ima_592; double gd_600; double gd_608; double g_lotstep_616; double g_lotsize_624; double gd_632; double gd_640; double gd_648; int gi_656; double gda_660[]; datetime g_time_664; double gd_668; double gd_676; double gd_684; int gi_692 = 0; int g_datetime_696; void ads() { SetLab("ads01", 20, 25, 3, "Vril-X1", 11, "Arial", Lime); SetLab("ads02", 20, 5, 3, "vril-x.narod2.ru", 11, "Arial", Aqua); } void SetLab(string a_name_0, int a_x_8, int a_y_12, int a_corner_16, string a_text_20, int a_fontsize_28, string a_fontname_32, color a_color_40 = -1) { ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0); ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8); ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12); ObjectSet(a_name_0, OBJPROP_CORNER, a_corner_16); ObjectSetText(a_name_0, a_text_20, a_fontsize_28, a_fontname_32, a_color_40); } int init() { if (MainTimeFrame == 0) MainTimeFrame = Period(); g_datetime_464 = iTime(Symbol(), MainTimeFrame, 0); g_datetime_468 = iTime(Symbol(), MainTimeFrame, 1); gd_608 = MarketInfo(Symbol(), MODE_MAXLOT); gd_600 = MarketInfo(Symbol(), MODE_MINLOT); g_lotstep_616 = MarketInfo(Symbol(), MODE_LOTSTEP); g_lotsize_624 = MarketInfo(Symbol(), MODE_LOTSIZE); gd_632 = MarketInfo(Symbol(), MODE_TICKVALUE) / MathPow(10, Digits % 2); gd_648 = MarketInfo(Symbol(), MODE_STOPLEVEL) * MathPow(10, Digits % 2); gd_668 = MarketInfo(Symbol(), MODE_POINT) * MathPow(10, Digits % 2); return (0); } int ScanTrades(int ai_0, int ai_4) { int ord_total_8 = OrdersTotal(); int count_12 = 0; bool li_16 = FALSE; int li_20 = 0; for (int pos_24 = 0; pos_24 < ord_total_8; pos_24++) { OrderSelect(pos_24, SELECT_BY_POS); if (ai_0 != 0) { if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP) li_20 = 1; if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP) li_20 = 2; } else li_20 = 0; if (ai_4 == 0) li_16 = OrderType() <= OP_SELLSTOP; if (ai_4 == 1) li_16 = OrderType() <= OP_SELL; if (ai_4 == 2) li_16 = OrderType() > OP_SELL && OrderType() <= OP_SELLSTOP; if (OrderSymbol() == Symbol() && li_16 && li_20 == ai_0 && OrderMagicNumber() == Magic) count_12++; } return (count_12); } int TimeCondition() { bool bool_0 = FALSE; int str2time_4 = StrToTime(StartHour + ":" + StartMinute); int str2time_8 = StrToTime(EndHour + ":" + EndMinute); if (MonStartHour >= 0 && DayOfWeek() == 1) str2time_4 = StrToTime(MonStartHour + ":" + MonStartMinute); if (FriEndHour >= 0 && DayOfWeek() == 5) str2time_8 = StrToTime(FriEndHour + ":" + FriEndMinute); if (DayOfWeek() != NonTradeDay) { if (StartHour < EndHour) bool_0 = TimeCurrent() >= str2time_4 && TimeCurrent() < str2time_8; else if (StartHour > EndHour) bool_0 = (TimeCurrent() >= str2time_4 && TimeHour(TimeCurrent()) < 24) || (TimeHour(TimeCurrent()) >= 0 && TimeCurrent() < str2time_8); } return (bool_0); } double TickSmoother(int ai_0, int a_timeframe_4, int ai_8, int ai_12, int a_period_16, int a_ma_method_20, int ai_24, int ai_28, int ai_32, int ai_36) { double ibands_40; double ibands_48; bool li_ret_56 = FALSE; if (TS_TimeFrame < 0) { gd_472 = iCustom(NULL, 0, "TickSmoother_v2.1", ai_8, ai_12, a_period_16, a_ma_method_20, ai_24, ai_28, ai_32, 3, ai_36); gd_488 = iCustom(NULL, 0, "TickSmoother_v2.1", ai_8, ai_12, a_period_16, a_ma_method_20, ai_24, ai_28, ai_32, 4, ai_36); gd_480 = iCustom(NULL, 0, "TickSmoother_v2.1", ai_8, ai_12, a_period_16, a_ma_method_20, ai_24, ai_28, ai_32, 5, ai_36); gd_496 = iCustom(NULL, 0, "TickSmoother_v2.1", ai_8, ai_12, a_period_16, a_ma_method_20, ai_24, ai_28, ai_32, 3, ai_36 + 1); gd_512 = iCustom(NULL, 0, "TickSmoother_v2.1", ai_8, ai_12, a_period_16, a_ma_method_20, ai_24, ai_28, ai_32, 4, ai_36 + 1); gd_504 = iCustom(NULL, 0, "TickSmoother_v2.1", ai_8, ai_12, a_period_16, a_ma_method_20, ai_24, ai_28, ai_32, 5, ai_36 + 1); if (TS_ConfMA1 > 0 && TS_ConfMA2 > 0) { gd_520 = iCustom(NULL, 0, "TickSmoother_v2.1", ai_8, TS_ConfMA1, TS_ConfMA2, a_ma_method_20, ai_24, ai_28, ai_32, 4, ai_36); gd_528 = iCustom(NULL, 0, "TickSmoother_v2.1", ai_8, TS_ConfMA1, TS_ConfMA2, a_ma_method_20, ai_24, ai_28, ai_32, 5, ai_36); } } else { gd_472 = iMA(NULL, a_timeframe_4, 1, 0, MODE_SMA, ai_8, ai_36); gd_488 = iMA(NULL, a_timeframe_4, ai_12, 0, a_ma_method_20, ai_8, ai_36); gd_480 = iMA(NULL, a_timeframe_4, a_period_16, 0, a_ma_method_20, ai_8, ai_36); gd_496 = iMA(NULL, a_timeframe_4, 1, 0, MODE_SMA, ai_8, ai_36 + 1); gd_512 = iMA(NULL, a_timeframe_4, ai_12, 0, a_ma_method_20, ai_8, ai_36 + 1); gd_504 = iMA(NULL, a_timeframe_4, a_period_16, 0, a_ma_method_20, ai_8, ai_36 + 1); if (TS_ConfMA1 > 0 && TS_ConfMA2 > 0) { gd_520 = iMA(NULL, a_timeframe_4, TS_ConfMA1, 0, a_ma_method_20, ai_8, ai_36); gd_528 = iMA(NULL, a_timeframe_4, TS_ConfMA2, 0, a_ma_method_20, ai_8, ai_36); } } double ld_60 = 0.95 * iClose(NULL, 0, 0); bool bool_68 = gd_472 > ld_60 && gd_488 > ld_60 && gd_480 > ld_60 && gd_496 > ld_60 && gd_512 > ld_60 && gd_504 > ld_60; bool bool_72 = gd_520 > ld_60 && gd_528 > ld_60; if (gd_488 > gd_480 && gd_512 < gd_504 && iTime(NULL, a_timeframe_4, 0) != g_datetime_696) { gi_692 = 1; g_datetime_696 = iTime(NULL, a_timeframe_4, 0); } if (gd_488 < gd_480 && gd_512 > gd_504 && iTime(NULL, a_timeframe_4, 0) != g_datetime_696) { gi_692 = -1; g_datetime_696 = iTime(NULL, a_timeframe_4, 0); } if (ai_0 == 1 && bool_68) { if (gd_472 > gd_488 && gd_488 > gd_480) li_ret_56 = ai_0; if (gd_472 < gd_488 && gd_488 < gd_480) li_ret_56 = -ai_0; } else { if (ai_0 == 2 && bool_68) { if (gd_472 > gd_488 && gd_496 < gd_512 && gd_488 > gd_480) li_ret_56 = ai_0; if (gd_472 < gd_488 && gd_496 > gd_512 && gd_488 < gd_480) li_ret_56 = -ai_0; } else { if (ai_0 == 3 && bool_68 && bool_72) { if (gd_472 > gd_488 && gd_488 > gd_480 && gd_480 > gd_520 && gd_520 > gd_528) li_ret_56 = ai_0; if (gd_472 < gd_488 && gd_488 < gd_480 && gd_480 < gd_520 && gd_520 < gd_528) li_ret_56 = -ai_0; } else { if (ai_0 == 4 && bool_68 && bool_72) { if (gd_472 > gd_488 && gd_496 < gd_512 && gd_488 > gd_480 && gd_480 > gd_520 && gd_520 > gd_528) li_ret_56 = ai_0; if (gd_472 < gd_488 && gd_496 > gd_512 && gd_488 < gd_480 && gd_480 < gd_520 && gd_520 < gd_528) li_ret_56 = -ai_0; } else { if (ai_0 == 5 && bool_68 && bool_72) { ibands_40 = iBands(NULL, a_timeframe_4, a_period_16, 1, 0, ai_8, MODE_UPPER, 0); ibands_48 = iBands(NULL, a_timeframe_4, a_period_16, 1, 0, ai_8, MODE_LOWER, 0); if (gd_472 > gd_488 && gd_488 > gd_480 && gd_480 > gd_520 && gd_520 > gd_528 && gd_472 < ibands_40 && gi_692 == 1) li_ret_56 = ai_0; if (gd_472 < gd_488 && gd_488 < gd_480 && gd_480 < gd_520 && gd_520 < gd_528 && gd_472 > ibands_48 && gi_692 == -1) li_ret_56 = -ai_0; } else { if (ai_0 == 6 && bool_68 && bool_72) { if (gd_472 > gd_488 && gd_488 > gd_480 && gd_512 < gd_504 && gd_480 > gd_520 && gd_520 > gd_528) li_ret_56 = ai_0; if (gd_472 < gd_488 && gd_488 < gd_480 && gd_512 > gd_504 && gd_480 < gd_520 && gd_520 < gd_528) li_ret_56 = -ai_0; } else { if (ai_0 == 7) { if (iRSI(NULL, a_timeframe_4, 2, PRICE_CLOSE, 1) < 30.0) li_ret_56 = ai_0; if (iRSI(NULL, a_timeframe_4, 2, PRICE_CLOSE, 1) > 70.0) li_ret_56 = -ai_0; } else if (ai_0 == 0) li_ret_56 = FALSE; } } } } } } return (li_ret_56); } double MA_Confirm(int ai_0, int a_timeframe_4, int a_applied_price_8, int a_period_12, int a_period_16, int a_ma_method_20, int ai_24) { bool bool_28; double ibands_32; double ibands_40; double iao_48; double iao_56; bool li_ret_64 = FALSE; g_ima_536 = iMA(NULL, a_timeframe_4, 1, 0, MODE_SMA, a_applied_price_8, ai_24); g_ima_552 = iMA(NULL, a_timeframe_4, a_period_12, 0, a_ma_method_20, a_applied_price_8, ai_24); g_ima_544 = iMA(NULL, a_timeframe_4, a_period_16, 0, a_ma_method_20, a_applied_price_8, ai_24); g_ima_560 = iMA(NULL, a_timeframe_4, 1, 0, MODE_SMA, a_applied_price_8, ai_24 + 1); g_ima_576 = iMA(NULL, a_timeframe_4, a_period_12, 0, a_ma_method_20, a_applied_price_8, ai_24 + 1); g_ima_568 = iMA(NULL, a_timeframe_4, a_period_16, 0, a_ma_method_20, a_applied_price_8, ai_24 + 1); double ld_68 = 0.95 * Close[0]; bool bool_76 = g_ima_536 > ld_68 && g_ima_552 > ld_68 && g_ima_544 > ld_68 && g_ima_560 > ld_68 && g_ima_576 > ld_68 && g_ima_568 > ld_68; if (MC_ConfMA1 > 0 && MC_ConfMA2 > 0) { g_ima_584 = iMA(NULL, a_timeframe_4, MC_ConfMA1, 0, a_ma_method_20, a_applied_price_8, ai_24); g_ima_592 = iMA(NULL, a_timeframe_4, MC_ConfMA2, 0, a_ma_method_20, a_applied_price_8, ai_24); bool_28 = g_ima_584 > ld_68 && g_ima_592 > ld_68; } if (ai_0 == 1 && bool_76) { if (g_ima_536 > g_ima_552 && g_ima_552 > g_ima_544) li_ret_64 = ai_0; if (g_ima_536 < g_ima_552 && g_ima_552 < g_ima_544) li_ret_64 = -ai_0; } else { if (ai_0 == 2 && bool_76) { if (g_ima_536 > g_ima_552 && g_ima_560 < g_ima_576 && g_ima_552 > g_ima_544) li_ret_64 = ai_0; if (g_ima_536 < g_ima_552 && g_ima_560 > g_ima_576 && g_ima_552 < g_ima_544) li_ret_64 = -ai_0; } else { if (ai_0 == 3 && bool_76 && bool_28) { if (g_ima_536 > g_ima_552 && g_ima_552 > g_ima_544 && g_ima_544 > g_ima_584 && g_ima_584 > g_ima_592) li_ret_64 = ai_0; if (g_ima_536 < g_ima_552 && g_ima_552 < g_ima_544 && g_ima_544 < g_ima_584 && g_ima_584 < g_ima_592) li_ret_64 = -ai_0; } else { if (ai_0 == 4 && bool_76 && bool_28) { if (g_ima_552 > g_ima_544 && g_ima_544 > g_ima_584 && g_ima_584 > g_ima_592) li_ret_64 = ai_0; if (g_ima_552 < g_ima_544 && g_ima_544 < g_ima_584 && g_ima_584 < g_ima_592) li_ret_64 = -ai_0; } else { if (ai_0 == 5 && bool_76) { if (g_ima_536 > g_ima_552 && g_ima_552 > g_ima_544 && g_ima_576 < g_ima_568) li_ret_64 = ai_0; if (g_ima_536 < g_ima_552 && g_ima_552 < g_ima_544 && g_ima_576 > g_ima_568) li_ret_64 = -ai_0; } else { if (ai_0 == 6 && bool_76) { if (g_ima_536 > g_ima_552 && g_ima_552 > g_ima_544 && g_ima_576 < g_ima_568) li_ret_64 = -ai_0; if (g_ima_536 < g_ima_552 && g_ima_552 < g_ima_544 && g_ima_576 > g_ima_568) li_ret_64 = ai_0; } else { if (ai_0 == 7 && bool_76 && bool_28) { ibands_32 = iBands(NULL, a_timeframe_4, a_period_16, 1, 0, a_applied_price_8, MODE_UPPER, 0); ibands_40 = iBands(NULL, a_timeframe_4, a_period_16, 1, 0, a_applied_price_8, MODE_LOWER, 0); if (g_ima_552 > g_ima_544 && g_ima_544 > g_ima_584 && g_ima_584 > g_ima_592 && g_ima_536 < ibands_32) li_ret_64 = ai_0; if (g_ima_552 < g_ima_544 && g_ima_544 < g_ima_584 && g_ima_584 < g_ima_592 && g_ima_536 > ibands_40) li_ret_64 = -ai_0; } else { if (ai_0 == 8 && bool_76 && bool_28) { ibands_32 = iBands(NULL, a_timeframe_4, a_period_16, 1, 0, a_applied_price_8, MODE_UPPER, 0); ibands_40 = iBands(NULL, a_timeframe_4, a_period_16, 1, 0, a_applied_price_8, MODE_LOWER, 0); iao_48 = iAO(NULL, a_timeframe_4, ai_24); iao_56 = iAO(NULL, a_timeframe_4, ai_24 + 1); if (g_ima_552 > g_ima_544 && g_ima_544 > g_ima_584 && g_ima_584 > g_ima_592 && g_ima_536 < ibands_32 && iao_48 > iao_56) li_ret_64 = ai_0; if (g_ima_552 < g_ima_544 && g_ima_544 < g_ima_584 && g_ima_584 < g_ima_592 && g_ima_536 > ibands_40 && iao_48 < iao_56) li_ret_64 = -ai_0; } else if (ai_0 == 0) li_ret_64 = FALSE; } } } } } } } return (li_ret_64); } int TradeSignal() { bool li_0; bool li_4; int li_ret_8 = 0; if (TS_Mode > 0) li_0 = TickSmoother(TS_Mode, TS_TimeFrame, TS_Price, TS_FastMA, TS_SlowMA, TS_MA_Mode, TS_NumTicks, TS_NumSecs, TS_MaxBars, TS_Shift); else li_0 = FALSE; if (MC_Mode > 0) li_4 = MA_Confirm(MC_Mode, MC_TimeFrame, MC_Price, MC_FastMA, MC_SlowMA, MC_MA_Mode, MC_Shift); else li_4 = FALSE; if (li_0 == TS_Mode && li_4 == MC_Mode) li_ret_8 = 1; if (li_0 == (-TS_Mode) && li_4 == (-MC_Mode)) li_ret_8 = -1; return (li_ret_8); } bool MoneyManagement() { double ld_0; double ld_8; if (gd_600 < 0.0 || gd_608 <= 0.0 || g_lotstep_616 <= 0.0) { Print("CalculateVolume: invalid MarketInfo() results [", gd_600, ",", gd_608, ",", g_lotstep_616, "]"); return (FALSE); } if (AccountLeverage() <= 0) { Print("CalculateVolume: invalid AccountLeverage() [", AccountLeverage(), "]"); return (FALSE); } if (MM == 1) ld_0 = NormalizeDouble(AccountFreeMargin() * MaxRisk * AccountLeverage() / g_lotsize_624, 2); else { if (MM == 2 && MaxLoss > 0.0) ld_0 = NormalizeDouble(AccountFreeMargin() * MaxRisk / MaxLoss, 2); else ld_0 = Lots; } ld_0 = NormalizeDouble(ld_0 / g_lotstep_616, 0) * g_lotstep_616; if (MaxLots > 0.0) gd_608 = MaxLots; if (ld_0 < gd_600) ld_0 = gd_600; if (ld_0 <= gd_608) { gi_656 = 1; ArrayResize(gda_660, gi_656); gda_660[gi_656 - 1] = ld_0; if (ld_0 < gd_600) gda_660[gi_656 - 1] = gd_600; } else { if (ld_0 > gd_608) { gi_656 = MathFloor(ld_0 / gd_608) + 1.0; if (gi_656 > MaxOrders) gi_656 = MaxOrders; ArrayResize(gda_660, gi_656); ld_8 = 0; for (int index_16 = 0; index_16 < gi_656 - 1; index_16++) { gda_660[index_16] = MathCeil(ld_0 / g_lotstep_616 / gi_656) * g_lotstep_616; if (gda_660[index_16] > gd_608) gda_660[index_16] = gd_608; ld_8 += gda_660[index_16]; } gda_660[gi_656 - 1] = ld_0 - ld_8; if (gda_660[gi_656 - 1] > gd_608) gda_660[gi_656 - 1] = gd_608; } } if (gi_656 > 0) return (TRUE); return (FALSE); } void TrailStop() { int error_0; int cmd_4; double price_8; double price_16; bool bool_24 = FALSE; double ld_28 = 0; int ord_total_36 = OrdersTotal(); for (int pos_40 = 0; pos_40 < ord_total_36; pos_40++) { OrderSelect(pos_40, SELECT_BY_POS); cmd_4 = OrderType(); if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { if (cmd_4 == OP_BUY) { if (BreakEven > 0.0 && g_count_456 < ord_total_36) { ld_28 = (MarketInfo(Symbol(), MODE_BID) - OrderOpenPrice()) / gd_668; if (ld_28 >= BreakEven && OrderStopLoss() <= OrderOpenPrice() + PipsLock * gd_668) { price_8 = NormalizeDouble(OrderOpenPrice() + PipsLock * gd_668, Digits); g_count_456++; } } else { if (TrailingMode == 1 && TrailingStop > 0.0) price_8 = NormalizeDouble(MarketInfo(Symbol(), MODE_BID) - TrailingStop * gd_668, Digits); else if (TrailingMode == 2 && gd_684 > 0.0) price_8 = NormalizeDouble((1.0 - StopDeviation / 100.0) * gd_684, Digits); } if (NormalizeDouble(OrderOpenPrice(), Digits) <= price_8) { if (price_8 > NormalizeDouble(OrderStopLoss(), Digits) || OrderStopLoss() == 0.0) { for (int count_44 = 0; count_44 < gi_460; count_44++) { bool_24 = OrderModify(OrderTicket(), OrderOpenPrice(), price_8, OrderTakeProfit(), 0, Lime); error_0 = GetLastError(); if (error_0 == 0/* NO_ERROR */) break; Sleep(5000); RefreshRates(); } } } } if (cmd_4 == OP_SELL) { if (BreakEven > 0.0 && g_count_456 > (-ord_total_36)) { ld_28 = (OrderOpenPrice() - MarketInfo(Symbol(), MODE_ASK)) / gd_668; if (ld_28 >= BreakEven && OrderStopLoss() >= OrderOpenPrice() - PipsLock * gd_668 || OrderStopLoss() == 0.0) { price_16 = NormalizeDouble(OrderOpenPrice() - PipsLock * gd_668, Digits); g_count_456--; } } else { if (TrailingMode == 1 && TrailingStop > 0.0) price_16 = NormalizeDouble(MarketInfo(Symbol(), MODE_ASK) + TrailingStop * gd_668, Digits); else if (TrailingMode == 2 && gd_676 > 0.0) price_16 = NormalizeDouble((StopDeviation / 100.0 + 1.0) * gd_676, Digits); } if (NormalizeDouble(OrderOpenPrice(), Digits) >= price_16 && price_16 > 0.0) { if (price_16 < NormalizeDouble(OrderStopLoss(), Digits) || OrderStopLoss() == 0.0) { for (count_44 = 0; count_44 < gi_460; count_44++) { bool_24 = OrderModify(OrderTicket(), OrderOpenPrice(), price_16, OrderTakeProfit(), 0, Orange); error_0 = GetLastError(); if (error_0 == 0/* NO_ERROR */) break; Sleep(5000); RefreshRates(); } } } } } } } void SellOrdOpen(double ad_0) { double ld_8; double ld_16; double bid_24; double ld_unused_32; double price_40; double price_48; double lots_56; int ticket_64 = 0; int li_68 = 1; int cmd_72 = 1; if (MoneyManagement()) { for (int index_76 = 0; index_76 < gi_656; index_76++) { bid_24 = Bid; ld_unused_32 = Bid; if (StopLoss > 0.0) price_40 = bid_24 + StopLoss * gd_668; else { if (TrailingMode == 2 && gd_676 > 0.0) price_40 = NormalizeDouble((StopDeviation / 100.0 + 1.0) * gd_676, Digits); else price_40 = 0; } if (StopLoss > 0.0 && price_40 - Ask < 10.0 * gd_668) price_40 = bid_24 + 10.0 * gd_668; if (MM == 2 && price_40 > 0.0) MaxLoss = gd_632 * (price_40 - Bid) / gd_668; if (TakeProfit > 0.0) price_48 = bid_24 - TakeProfit * gd_668; else price_48 = 0; if (ad_0 == 0.0) lots_56 = gda_660[index_76]; else if (ad_0 > 0.0) lots_56 = ad_0 * MaxLots(2); if (ECN_Mode == 1) { ld_8 = 0; ld_16 = 0; } else { ld_8 = price_40; ld_16 = price_48; } while (ticket_64 <= 0 && li_68 <= gi_460) { ticket_64 = OrderSend(Symbol(), cmd_72, lots_56, NormalizeDouble(bid_24, Digits), Slippage, NormalizeDouble(ld_8, Digits), NormalizeDouble(ld_16, Digits), Expert_Name + " SELL", Magic, 0, Red); if (ticket_64 > 0) { if (OrderSelect(ticket_64, SELECT_BY_TICKET, MODE_TRADES)) { g_count_456 = 0; gi_692 = 0; } if (ECN_Mode == 1 && price_40 > 0.0 || price_48 > 0.0) OrderModify(ticket_64, OrderOpenPrice(), price_40, price_48, 0, Fuchsia); } else { if (ticket_64 < 0) { Sleep(5000); RefreshRates(); li_68++; if (GetLastError() > 0/* NO_ERROR */) Print("SELL : OrderSend failed with error #", GetLastError()); } } } } } } void BuyOrdOpen(double ad_0) { double ld_8; double ld_16; double ask_24; double ld_unused_32; double price_40; double price_48; double lots_56; int ticket_64 = 0; int li_68 = 1; int cmd_72 = 0; if (MoneyManagement()) { for (int index_76 = 0; index_76 < gi_656; index_76++) { ask_24 = Ask; ld_unused_32 = Ask; if (StopLoss > 0.0) price_40 = ask_24 - StopLoss * gd_668; else { if (TrailingMode == 2 && gd_684 > 0.0) price_40 = NormalizeDouble((1.0 - StopDeviation / 100.0) * gd_684, Digits); else price_40 = 0; } if (StopLoss > 0.0 && Bid - price_40 < 10.0 * gd_668) price_40 = ask_24 - 10.0 * gd_668; if (MM == 2 && price_40 > 0.0) MaxLoss = gd_632 * (Ask - price_40) / gd_668; if (TakeProfit > 0.0) price_48 = ask_24 + TakeProfit * gd_668; else price_48 = 0; if (ad_0 == 0.0) lots_56 = gda_660[index_76]; else if (ad_0 > 0.0) lots_56 = ad_0 * MaxLots(1); if (ECN_Mode == 1) { ld_8 = 0; ld_16 = 0; } else { ld_8 = price_40; ld_16 = price_48; } while (ticket_64 <= 0 && li_68 <= gi_460) { ticket_64 = OrderSend(Symbol(), cmd_72, lots_56, NormalizeDouble(ask_24, Digits), Slippage, NormalizeDouble(ld_8, Digits), NormalizeDouble(ld_16, Digits), Expert_Name + " BUY", Magic, 0, Blue); if (ticket_64 > 0) { if (OrderSelect(ticket_64, SELECT_BY_TICKET, MODE_TRADES)) { g_count_456 = 0; gi_692 = 0; } if (ECN_Mode == 1 && price_40 > 0.0 || price_48 > 0.0) OrderModify(ticket_64, OrderOpenPrice(), price_40, price_48, 0, Aqua); } else { if (ticket_64 < 0) { Sleep(5000); RefreshRates(); li_68++; if (GetLastError() > 0/* NO_ERROR */) Print("BUY : OrderSend failed with error #", GetLastError()); } } } } } } void CloseOrder(int ai_0) { bool li_4 = FALSE; int ord_total_8 = OrdersTotal(); for (int ord_total_12 = OrdersTotal(); ord_total_12 >= 0; ord_total_12--) { OrderSelect(ord_total_12, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol() == Symbol()) { if (ai_0 == 0 || ai_0 == 1 && OrderType() == OP_BUY) { li_4 = CloseAtMarket(OrderTicket(), OrderLots(), Aqua); return; } if (ai_0 == 0 || ai_0 == 2 && OrderType() == OP_SELL) { li_4 = CloseAtMarket(OrderTicket(), OrderLots(), Pink); return; } } } } int CloseAtMarket(int a_ticket_0, double a_lots_4, color a_color_12) { bool ord_close_16 = FALSE; for (int count_20 = 0; !ord_close_16 && count_20 < gi_460; count_20++) { RefreshRates(); ord_close_16 = OrderClose(a_ticket_0, a_lots_4, OrderClosePrice(), Slippage, a_color_12); } if (!ord_close_16) Print("Error closing order : ", GetLastError()); return (ord_close_16); } double TotalProfit(int ai_0, int ai_4, int ai_8, int ai_12) { int li_16; int li_20; int cmd_24; bool li_28; bool li_32; double ld_ret_36 = 0; double ld_ret_44 = 0; double ld_ret_52 = 0; double ld_ret_60 = 0; double ld_ret_68 = 0; if (ai_8 == 0) { li_16 = OrdersTotal(); li_20 = 0; } else { li_16 = OrdersHistoryTotal(); li_20 = 1; } for (int pos_76 = 0; pos_76 < li_16; pos_76++) { OrderSelect(pos_76, SELECT_BY_POS, li_20); cmd_24 = OrderType(); li_28 = FALSE; li_32 = FALSE; if (Magic > 0 && OrderMagicNumber() == Magic && OrderSymbol() == Symbol()) li_28 = TRUE; else if (Magic == 0) li_28 = TRUE; if (ai_12 > 0) { if (ai_12 == StrToTime(TimeToStr(OrderOpenTime(), TIME_DATE))) li_32 = TRUE; } else if (ai_12 == 0) li_32 = TRUE; if (li_28 && li_32) { if (cmd_24 == OP_BUY && ai_0 == 1 || ai_0 == 0) { ld_ret_36 = (OrderClosePrice() - OrderOpenPrice()) / gd_668; ld_ret_44 = OrderProfit() + OrderSwap() + OrderCommission(); ld_ret_52 += ld_ret_36; ld_ret_60 += ld_ret_44; if (ai_4 == 4 && OrderLots() == MaxLots(1)) ld_ret_68 = ld_ret_36; } if (cmd_24 == OP_SELL && ai_0 == 2 || ai_0 == 0) { ld_ret_36 = (OrderOpenPrice() - OrderClosePrice()) / gd_668; ld_ret_44 = OrderProfit() + OrderSwap() + OrderCommission(); ld_ret_52 += ld_ret_36; ld_ret_60 += ld_ret_44; if (ai_4 == 4 && OrderLots() == MaxLots(2)) ld_ret_68 = ld_ret_36; } } } if (ai_4 == 0) return (ld_ret_36); if (ai_4 == 1) return (ld_ret_44); if (ai_4 == 2) return (ld_ret_52); if (ai_4 == 3) return (ld_ret_60); if (ai_4 == 4) return (ld_ret_68); return (0.0); } double MaxLots(int ai_0) { int ord_total_4 = OrdersTotal(); double ld_ret_8 = 0; for (int pos_16 = 0; pos_16 < ord_total_4; pos_16++) { if (!(OrderSelect(pos_16, SELECT_BY_POS))) break; if (OrderMagicNumber() == Magic && OrderSymbol() == Symbol()) { if (OrderType() == OP_BUY && ai_0 == 1 || ai_0 == 0) ld_ret_8 = MathMax(ld_ret_8, OrderLots()); if (OrderType() == OP_SELL && ai_0 == 2 || ai_0 == 0) ld_ret_8 = MathMax(ld_ret_8, OrderLots()); } } return (ld_ret_8); } void ChartComment() { string ls_0 = ""; string ls_8 = "----------------------------------------\n"; string ls_16 = "\n"; double ld_24 = TotalProfit(0, 2, 0, 0); double ld_32 = TotalProfit(0, 3, 0, 0); double ld_40 = TotalProfit(0, 3, 1, StrToTime(TimeToStr(TimeCurrent(), TIME_DATE))); double ld_48 = ld_40 + ld_32; ls_0 = ls_8; ls_0 = ls_0 + "Expert Name : " + Expert_Name + ls_16; ls_0 = ls_0 + "Time: Current= " + TimeToStr(TimeCurrent()) + ls_16; ls_0 = ls_0 + "Orders: Open= " + ScanTrades(0, 1) + " Pending= " + ScanTrades(0, 2) + " All= " + ScanTrades(0, 0) + ls_16; ls_0 = ls_0 + "Current Profit(pips)= " + DoubleToStr(ld_24, 1) + ls_16; ls_0 = ls_0 + "Current Profit(USD) = " + DoubleToStr(ld_32, 2) + ls_16; ls_0 = ls_0 + "Daily Profit(USD): Closed= " + DoubleToStr(ld_40, 2) + " Open= " + DoubleToStr(ld_32, 2) + " Summary = " + DoubleToStr(ld_48, 2) + ls_16; ls_0 = ls_0 + ls_8; ls_0 = ls_0 + "Fast0=" + DoubleToStr(gd_488, Digits) + " Slow0=" + DoubleToStr(gd_480, Digits) + " Close0=" + DoubleToStr(gd_472, Digits) + ls_16; ls_0 = ls_0 + "Fast1=" + DoubleToStr(gd_512, Digits) + " Slow1=" + DoubleToStr(gd_504, Digits) + " Close1=" + DoubleToStr(gd_496, Digits) + ls_16; if (TS_ConfMA1 > 0 && TS_ConfMA2 > 0) ls_0 = ls_0 + "Conf1=" + DoubleToStr(gd_520, Digits) + " Conf2=" + DoubleToStr(gd_528, Digits) + ls_16; Comment(ls_0); } int deinit() { return (0); } int start() { int li_0; int li_4; int li_8; int li_12; double ld_16; double ld_24; double ld_32; double ibands_40; double ibands_48; double ibands_56; double ibands_64; bool li_72; double ld_76; double ld_84; if (iBars(Symbol(), MainTimeFrame) < 100 || (!IsTradeAllowed())) return (0); ads(); if (MainTimeFrame >= 0) g_datetime_464 = iTime(Symbol(), MainTimeFrame, 0); else { g_datetime_464 = iTime(Symbol(), 0, 0); g_datetime_468 = iTime(Symbol(), 0, 1); } int str2time_92 = StrToTime(CloseHour + ":" + CloseMinute); if (FriCloseHour >= 0 && DayOfWeek() == 5 && FriCloseHour > StartHour) str2time_92 = StrToTime(FriCloseHour + ":" + FriCloseMinute); gd_640 = NormalizeDouble((Ask - Bid) / gd_668, 1); ChartComment(); if (g_datetime_464 != g_datetime_468) { li_0 = ScanTrades(1, 0); li_4 = ScanTrades(2, 0); li_8 = li_0 + li_4; if (TS_Mode != 0 || MC_Mode != 0) li_12 = TradeSignal(); } if (li_8 == 0 && (!TimeCondition())) return (0); if (li_8 > 0) { if (ExitMode == 1) { if (li_4 > 0 && gd_488 > gd_480 && gd_480 > 0.0) { Print("Sell Close 1"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && gd_488 < gd_480 && gd_480 > 0.0) { Print("Buy Close 1"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 2) { if (li_4 > 0 && gd_496 < gd_512 && gd_472 > gd_488 && gd_488 > 0.0 && gd_512 > 0.0) { Print("Sell Close 2"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && gd_496 > gd_512 && gd_472 < gd_488) { Print("Buy Close 2"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 3) { ld_16 = TotalProfit(0, 1, 0, 0); if (li_4 > 0 && (gd_496 < gd_512 && gd_472 > gd_488 && gd_488 > 0.0 && gd_512 > 0.0 && ld_16 > 0.0) || gd_472 >= gd_520) { Print("Sell Close 3"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && (gd_496 > gd_512 && gd_472 < gd_488 && ld_16 > 0.0) || gd_472 <= gd_520) { Print("Buy Close 3"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 4) { ld_24 = TotalProfit(1, 1, 0, 0); ld_32 = TotalProfit(2, 1, 0, 0); if (li_4 > 0 && (gd_472 > gd_488 && gd_488 > 0.0 && ld_32 > 0.0) || gd_472 >= gd_528) { Print("Sell Close 4"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && (gd_472 < gd_488 && ld_24 > 0.0) || gd_472 <= gd_528) { Print("Buy Close 4"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 5) { ld_24 = TotalProfit(1, 1, 0, 0); ld_32 = TotalProfit(2, 1, 0, 0); if (li_4 > 0 && (gd_472 > gd_488 && gd_488 > 0.0 && ld_32 > 0.0) || gd_472 >= g_ima_592) { Print("Sell Close 5"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && (gd_472 < gd_488 && ld_24 > 0.0) || gd_472 <= g_ima_592) { Print("Buy Close 5"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 6) { ld_24 = TotalProfit(1, 1, 0, 0); ld_32 = TotalProfit(2, 1, 0, 0); if (li_4 > 0 && (g_ima_536 > g_ima_552 && g_ima_552 > 0.0 && ld_32 > 0.0) || g_ima_536 >= g_ima_592) { Print("Sell Close 6"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && (g_ima_536 < g_ima_552 && ld_24 > 0.0) || g_ima_536 <= g_ima_592) { Print("Buy Close 6"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 7) { ld_24 = TotalProfit(1, 1, 0, 0); ld_32 = TotalProfit(2, 1, 0, 0); if (li_4 > 0 && (g_ima_536 > g_ima_552 && g_ima_552 > 0.0 && ld_32 > 0.0)) { Print("Sell Close 7"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && (g_ima_536 < g_ima_552 && ld_24 > 0.0)) { Print("Buy Close 7"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 8) { ld_24 = TotalProfit(1, 1, 0, 0); ld_32 = TotalProfit(2, 1, 0, 0); if (li_4 > 0 && (g_ima_552 > g_ima_576 && g_ima_576 > 0.0 && ld_32 > 0.0)) { Print("Sell Close 8"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && (g_ima_552 < g_ima_576 && ld_24 > 0.0)) { Print("Buy Close 8"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 9) { ld_24 = TotalProfit(1, 1, 0, 0); ld_32 = TotalProfit(2, 1, 0, 0); ibands_40 = iBands(NULL, MC_TimeFrame, MC_SlowMA, 2, 0, TS_Price, MODE_UPPER, 0); ibands_48 = iBands(NULL, MC_TimeFrame, MC_SlowMA, 2, 0, TS_Price, MODE_LOWER, 0); if (li_4 > 0 && ((gd_472 > gd_488 && gd_488 > 0.0) || gd_472 < ibands_48 && ld_32 > 0.0)) { Print("Sell Close 9"); while (ScanTrades(2, 0) > 0) CloseOrder(2); } if (li_0 > 0 && (gd_472 < gd_488 || gd_472 > ibands_40 && ld_24 > 0.0)) { Print("Buy Close 9"); while (ScanTrades(1, 0) > 0) CloseOrder(1); } } else { if (ExitMode == 10) { ld_24 = TotalProfit(1, 0, 0, 0); ld_32 = TotalProfit(2, 0, 0, 0); ibands_56 = iBands(NULL, TS_TimeFrame, TS_SlowMA, 2, 0, TS_Price, MODE_UPPER, 1); ibands_64 = iBands(NULL, TS_TimeFrame, TS_SlowMA, 2, 0, TS_Price, MODE_LOWER, 1); ibands_40 = iBands(NULL, MC_TimeFrame, MC_SlowMA, 2, 0, MC_Price, MODE_UPPER, 0); ibands_48 = iBands(NULL, MC_TimeFrame, MC_SlowMA, 2, 0, MC_Price, MODE_LOWER, 0); if (li_4 > 0 && (gd_488 > gd_480 || iLow(NULL, MC_TimeFrame, 0) <= ibands_48 || iLow(NULL, TS_TimeFrame, 1) <= ibands_64 && ld_32 >= MinProfit)) { Print("Sell Close 10"); CloseOrder(2); } if (li_0 > 0 && (gd_488 < gd_480 || iHigh(NULL, MC_TimeFrame, 0) >= ibands_40 || iHigh(NULL, TS_TimeFrame, 1) >= ibands_56 && ld_24 >= MinProfit)) { Print("Buy Close 10"); CloseOrder(1); } } else { if (ExitMode == 11) { if (li_8 > 0 && TotalProfit(0, 0, 0, 0) >= MGPips) while (ScanTrades(0, 0) > 0) CloseOrder(0); } else { if (ExitMode == 12) if (li_8 > 0 && TotalProfit(0, ProfitMode, 0, 0) > ProfitTarget) while (ScanTrades(0, 0) > 0) CloseOrder(0); } } } } } } } } } } } if (CloseTimeMode > 0 && TimeCurrent() >= str2time_92 && TimeCurrent() < str2time_92 + 60.0 * ProcessTime) while (ScanTrades(0, 0) > 0) CloseOrder(0); } if (MaxSpread > 0.0) li_72 = gd_640 <= MaxSpread; else li_72 = TRUE; li_8 = ScanTrades(0, 0); if (li_8 < MaxOrders) { if (TimeCondition() && li_72 && Time[0] != g_time_664 && li_12 != 0) { if ((li_12 > 0 && MGMode == 0.0) || (li_12 > 0 && MGMode > 0.0 && li_8 < 1)) { if (ReverseLogic > 0) SellOrdOpen(0); else BuyOrdOpen(0); } if ((li_12 < 0 && MGMode == 0.0) || (li_12 < 0 && MGMode > 0.0 && li_8 < 1)) { if (ReverseLogic > 0) BuyOrdOpen(0); else SellOrdOpen(0); } g_time_664 = Time[0]; } if (MGMode > 0.0 && li_8 > 0) { ld_76 = TotalProfit(1, 0, 0, 0); ld_84 = TotalProfit(2, 0, 0, 0); if (AccountFreeMargin() > AccountBalance() / 2.0) { if (ld_76 <= -MGStep) BuyOrdOpen(MGRatio); if (ld_84 <= -MGStep) SellOrdOpen(MGRatio); } } } if (li_8 > 0) { if (ProfitTarget > 0.0 && TotalProfit(0, ProfitMode, 0, 0) >= ProfitTarget) while (ScanTrades(0, 0) > 0) CloseOrder(0); if (BreakEven > 0.0 || TrailingMode > 0) TrailStop(); } g_datetime_468 = g_datetime_464; return (0); }