#property copyright "Copyright © 2009, Max Ong" #property link "http://www.kaizentraders.com/" bool gi_76 = FALSE; bool gi_80 = FALSE; extern string Commentary = "********** Commentary Panel **********"; extern bool DisplayCommentary = TRUE; extern bool DeleteObjects = FALSE; extern string ShutdownAndHibernation = "********** Manual Shutdown and Hibernation **********"; extern bool Email = TRUE; extern bool ShowAlert = TRUE; extern bool ManualShutdown = FALSE; extern bool EquityHibernation = FALSE; extern double TargetEquity = 30000.0; extern bool TimeHibernation = FALSE; extern string CapitalManagement = "********** Capital Management **********"; extern bool UseCapitalManagement = FALSE; extern bool ActiveIsolation = TRUE; extern bool ResetCapital = FALSE; extern double Capital = 10000.0; extern double EquityFacility = 0.0; extern int MaxOrderNumber = 1000; extern int SpreadLimit = 0; extern int Slippage = 3; extern double Tolerance = -0.01; extern bool DisplayArrows = TRUE; extern string TradeManagement = "********** Trade Management **********"; extern bool HedgeMode = FALSE; extern bool FirstTradeCycle = TRUE; extern int FirstTradeCycleDirection = 0; extern bool SecondTradeCycle = FALSE; extern int SecondTradeCycleDirection = 0; extern double AntiProgressionPercent = 5.0; extern bool GlobalBreakeven = FALSE; extern int SeedMagicNumber = 3321; extern string SymbolSuffix = ""; extern string TabID = ""; extern string TimeAndPeriodManagement = "********** Time and Period Management **********"; extern bool TimeFilter = FALSE; extern string StartTrading = "10:00"; extern string StopTrading = "20:00"; extern bool TradeOnMonday = TRUE; extern bool TradeOnTuesday = TRUE; extern bool TradeOnWednesday = TRUE; extern bool TradeOnThursday = TRUE; extern bool TradeOnFriday = TRUE; extern string EntryPeriodTimeFrame = "M15"; extern string ExitPeriodTimeFrame = "M15"; extern int TimeDelay = 1; extern string VolatilityScreenSettings = "=== Volatility Screen Settings ===="; extern bool VolatilityScreen = TRUE; extern double VolatilityMultiplier = 2.0; extern string FirstTradeCycleSettings = "********** Settings for First Trade Cycle **********"; extern double TC1BuyStakePercent = 0.01; extern double TC1SellStakePercent = 0.02; extern double TC1BuyLotSize = 0.01; extern double TC1SellLotSize = 0.02; extern int TC1GridSpacing = 76; extern int TC1GridIncrement = 10; extern int TC1AddGainPoint = 4; extern double TC1BuyMultiplier = 1.0; extern double TC1SellMultiplier = 1.5; extern string SecondTradeCycleSettings = "********** Settings for Second Trade Cycle **********"; extern double TC2BuyStakePercent = 0.02; extern double TC2SellStakePercent = 0.01; extern double TC2BuyLotSize = 0.02; extern double TC2SellLotSize = 0.01; extern int TC2GridSpacing = 76; extern int TC2GridIncrement = 10; extern int TC2AddGainPoint = 4; extern double TC2BuyMultiplier = 1.5; extern double TC2SellMultiplier = 1.0; double gd_480 = 30000.0; string gs_488 = "H1"; int g_period_496 = 6; int gi_500 = 15; double gd_504 = 2.0; int g_period_512 = 20; double gd_516 = 2.0; bool gi_unused_524 = TRUE; bool gi_528 = TRUE; bool gi_532 = TRUE; double gd_536; int g_spread_544 = 0; double gd_548 = 0.0; double gd_556; double gd_564; double gd_unused_572 = 0.0; double gd_unused_580 = 0.0; double gd_unused_588 = 0.0; double gd_unused_596 = 0.0; int gi_604 = 0; int gi_608 = 0; int gi_612 = 0; int gi_616 = 0; int gi_620 = 0; int gi_624 = 0; int gi_628 = 0; int gi_632 = 0; double g_minlot_636 = 0.0; double g_maxlot_644 = 0.0; double g_lotstep_652 = 0.0; double g_lotsize_660 = 0.0; int gi_668 = 0; int gi_672 = 0; int gi_676 = 0; int gi_680 = 0; double g_ord_open_price_684 = 0.0; double g_ord_open_price_692 = 0.0; double g_ord_open_price_700 = 0.0; double g_ord_open_price_708 = 0.0; int g_cmd_716 = OP_BUY; int g_cmd_720 = OP_BUY; int g_cmd_724 = OP_BUY; int g_cmd_728 = OP_BUY; int g_magic_732; int g_magic_736; int g_magic_740; int g_magic_744; int g_magic_748; int g_magic_752; int g_magic_756; int g_magic_760; int g_file_764; double gd_768; double gd_776; int init() { g_magic_732 = SeedMagicNumber + 1; g_magic_736 = SeedMagicNumber + 2; g_magic_740 = SeedMagicNumber + 3; g_magic_744 = SeedMagicNumber + 4; g_magic_748 = SeedMagicNumber + 5; g_magic_752 = SeedMagicNumber + 6; g_magic_756 = SeedMagicNumber + 7; g_magic_760 = SeedMagicNumber + 8; if (ScanLastAccountBalance() > 0.0) gd_768 = ScanLastAccountBalance(); else gd_768 = MaxAccountBalance(); if (Symbol() == "USDJPY" || Symbol() == "USDJPY" + SymbolSuffix || Symbol() == "EURJPY" || Symbol() == "EURJPY" + SymbolSuffix || Symbol() == "GBPJPY" || Symbol() == "GBPJPY" + SymbolSuffix || Symbol() == "CHFJPY" || Symbol() == "CHFJPY" + SymbolSuffix || Symbol() == "AUDJPY" || Symbol() == "AUDJPY" + SymbolSuffix || Symbol() == "NZDJPY" || Symbol() == "NZDJPY" + SymbolSuffix) { if (MarketInfo(Symbol(), MODE_DIGITS) == 3.0) { gd_536 = 10.0 * MarketInfo(Symbol(), MODE_POINT); Slippage = 10 * Slippage; } } if (Symbol() == "EURUSD" || Symbol() == "EURUSD" + SymbolSuffix || Symbol() == "GBPUSD" || Symbol() == "GBPUSD" + SymbolSuffix || Symbol() == "USDCHF" || Symbol() == "USDCHF" + SymbolSuffix || Symbol() == "USDCAD" || Symbol() == "USDCAD" + SymbolSuffix || Symbol() == "AUDUSD" || Symbol() == "AUDUSD" + SymbolSuffix || Symbol() == "NZDUSD" || Symbol() == "NZDUSD" + SymbolSuffix || Symbol() == "EURGBP" || Symbol() == "EURGBP" + SymbolSuffix || Symbol() == "EURCHF" || Symbol() == "EURCHF" + SymbolSuffix || Symbol() == "EURCAD" || Symbol() == "EURCAD" + SymbolSuffix || Symbol() == "EURAUD" || Symbol() == "EURAUD" + SymbolSuffix || Symbol() == "GBPCHF" || Symbol() == "GBPCHF" + SymbolSuffix || Symbol() == "AUDNZD" || Symbol() == "AUDNZD" + SymbolSuffix || Symbol() == "AUDCAD" || Symbol() == "AUDCAD" + SymbolSuffix) { if (MarketInfo(Symbol(), MODE_DIGITS) == 5.0) { gd_536 = 10.0 * MarketInfo(Symbol(), MODE_POINT); Slippage = 10 * Slippage; } } if (MarketInfo(Symbol(), MODE_DIGITS) == 2.0 || MarketInfo(Symbol(), MODE_DIGITS) == 4.0) { gd_536 = 1.0 * MarketInfo(Symbol(), MODE_POINT); Slippage = 1 * Slippage; } if (ObjectFind("Expert") != 0) ObjectDelete("Expert"); if (ObjectFind("Build") != 0) ObjectDelete("Build"); if (ObjectFind("Expiry") != 0) ObjectDelete("Expiry"); if (ObjectFind("DemoAuthorization") != 0) ObjectDelete("DemoAuthorization"); if (ObjectFind("PwdAuthorization") != 0) ObjectDelete("PwdAuthorization"); if (ObjectFind("AcAuthorization1") != 0) ObjectDelete("AcAuthorization1"); if (ObjectFind("AcAuthorization2") != 0) ObjectDelete("AcAuthorization2"); if (ObjectFind("EquityHibernate1") != 0) ObjectDelete("EquityHibernate1"); if (ObjectFind("EquityHibernate2") != 0) ObjectDelete("EquityHibernate2"); if (ObjectFind("TimeHibernate1") != 0) ObjectDelete("TimeHibernate1"); if (ObjectFind("TimeHibernate2") != 0) ObjectDelete("TimeHibernate2"); if (ObjectFind("ManualShut") != 0) ObjectDelete("ManualShut"); if (ObjectFind("CharacterLength") != 0) ObjectDelete("CharacterLength"); if (ObjectFind("TC1BuyStake") != 0) ObjectDelete("TC1BuyStake"); if (ObjectFind("TC1SellStake") != 0) ObjectDelete("TC1SellStake"); if (ObjectFind("TC2BuyStake") != 0) ObjectDelete("TC2BuyStake"); if (ObjectFind("TC2SellStake") != 0) ObjectDelete("TC2SellStake"); return (0); } int deinit() { if (DeleteObjects) { ObjectDelete("Expert"); ObjectDelete("Build"); ObjectDelete("Expiry"); ObjectDelete("DemoAuthorization"); ObjectDelete("PwdAuthorization"); ObjectDelete("AcAuthorization1"); ObjectDelete("AcAuthorization2"); ObjectDelete("EquityHibernate1"); ObjectDelete("EquityHibernate2"); ObjectDelete("TimeHibernate1"); ObjectDelete("TimeHibernate2"); ObjectDelete("ManualShut"); ObjectDelete("CharacterLength"); ObjectDelete("TC1BuyStake"); ObjectDelete("TC1SellStake"); ObjectDelete("TC2BuyStake"); ObjectDelete("TC2SellStake"); } return (0); } int start() { if (CheckAuthorization() != 1) { DisplayText("AcAuthorization1", "Your live account trading authorization failed.", "Vernada", 14, Red, 275, 15); DisplayText("AcAuthorization2", "Please contact max@forexzen.com", "Vernada", 14, Red, 275, 35); return; } if (gi_76) { if (!IsDemo()) { DisplayText("DemoAuthorization", "Trading authorized only for demo accounts.", "Vernada", 14, Red, 275, 15); return; } } if (EquityHibernation) { if (AccountBalance() >= TargetEquity && ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() + ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders() == 0) { DisplayText("EquityHibernate1", "Target Equity has now been reached, and", "Vernada", 14, Red, 275, 15); DisplayText("EquityHibernate2", "EA has entered Hibernation", "Vernada", 14, Red, 275, 35); return; } } if (AccountBalance() >= gd_480 && ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() + ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders() == 0) { DisplayText("EquityHibernate1", "Cap limit has now been reached, and", "Vernada", 14, Red, 275, 15); DisplayText("EquityHibernate2", "EA has entered Hibernation", "Vernada", 14, Red, 275, 35); return; } if (TimeHibernation() == 1) { DisplayText("TimeHibernate1", "Trading on this chart has now reached profit", "Vernada", 14, Red, 275, 15); DisplayText("TimeHibernate2", "target, and EA has entered Hibernation", "Vernada", 14, Red, 275, 35); if (Email && gi_528) HibernationMail(); gi_528 = FALSE; if (ShowAlert && gi_532) { Alert("Your EA is now in hibernation. Please check if you would like to reset the EA" + "\n" + "Date: " + Year() + "." + Month() + "." + Day() + "\n" + "Time: " + CurrentTime() + "\n" + "Account Number: " + DoubleToStr(AccountNumber(), 0) + "\n" + "Instrument: " + Symbol()); } gi_532 = FALSE; return; } if (ManualShutdown) { EmergencyExit(); DisplayText("ManualShut", "EA has been manually shutdown", "Vernada", 14, Red, 275, 15); ManualShutDownMail(); return; } if (StringLen(TabID) > 31) { DisplayText("CharacterLength", "Please reduce the number of characters in the TabID field.", "Vernada", 14, Red, 275, 15); return; } if (ResetCapital) ResetAccountBalance(); if (GlobalBreakeven) if (AccountBalance() >= ScanLastAccountBalance()) EmergencyExit(); Comments(); if (ScanAllOrders() == 0) { g_file_764 = FileOpen("HH" + AccountNumber() + Symbol() + TabID + ".csv", FILE_CSV|FILE_WRITE, ";"); if (ActiveIsolation) { if (g_file_764 > 0) { FileWrite(g_file_764, MathMax(gd_768, MaxAccountBalance())); FileClose(g_file_764); } } if (!ActiveIsolation) { if (g_file_764 > 0) { FileWrite(g_file_764, AccountBalance()); FileClose(g_file_764); } } } if (HedgeMode) { if (FirstTradeCycle && !SecondTradeCycle) { if (ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders() == 0) { if (TimeFilter) { if (StrToTime(CurrentTime()) >= StrToTime(StartTrading) && StrToTime(CurrentTime()) <= StrToTime(StopTrading)) { TC1Buy(); TC1Sell(); } } if (!TimeFilter) { TC1Buy(); TC1Sell(); } } } if (FirstTradeCycle && !SecondTradeCycle) { if (ScanTC1SellLastPrice() != 0.0 && GetPrice(1, 0, 0) + (TC1GridSpacing + (ScanTC1SellOrders() + 1) * TC1AddGainPoint) * gd_536 <= ScanTC1SellLastPrice() && ActivePerformance() >= Tolerance && ExitPeriodFilter() && StrToTime(CurrentTime()) - ScanOrderOpenTime() >= 60 * TimeDelay) { while (ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() > 0) CloseTC1CycleOrders(); FirstTradeCycle = FALSE; SecondTradeCycle = TRUE; } } if (SecondTradeCycle && !FirstTradeCycle) { if (ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() == 0) { if (TimeFilter) { if (StrToTime(CurrentTime()) >= StrToTime(StartTrading) && StrToTime(CurrentTime()) <= StrToTime(StopTrading)) { TC2Buy(); TC2Sell(); } } if (!TimeFilter) { TC2Buy(); TC2Sell(); } } } if (SecondTradeCycle && !FirstTradeCycle) { if (ScanTC2BuyLastPrice() != 0.0 && GetPrice(2, 0, 0) - (TC2GridSpacing + (ScanTC2BuyOrders() + 1) * TC2AddGainPoint) * gd_536 >= ScanTC2BuyLastPrice() && ActivePerformance() >= Tolerance && ExitPeriodFilter() && StrToTime(CurrentTime()) - ScanOrderOpenTime() >= 60 * TimeDelay) { while (ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders() > 0) CloseTC2CycleOrders(); SecondTradeCycle = FALSE; FirstTradeCycle = TRUE; } } } if (!HedgeMode) { if (FirstTradeCycle && !SecondTradeCycle) { if (ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders() == 0) { if (TimeFilter) { if (StrToTime(CurrentTime()) >= StrToTime(StartTrading) && StrToTime(CurrentTime()) <= StrToTime(StopTrading)) { if (FirstTradeCycleDirection == 1) TC1Buy(); else { if (FirstTradeCycleDirection != 2) return; TC1Sell(); } } } if (!TimeFilter) { if (FirstTradeCycleDirection == 1) TC1Buy(); else { if (FirstTradeCycleDirection != 2) return; TC1Sell(); } } } } if (FirstTradeCycle && !SecondTradeCycle) { if (ScanTC1SellLastPrice() != 0.0 && GetPrice(1, 0, 0) + (TC1GridSpacing + (ScanTC1SellOrders() + 1) * TC1AddGainPoint) * gd_536 <= ScanTC1SellLastPrice() && ActivePerformance() >= Tolerance && ExitPeriodFilter() && StrToTime(CurrentTime()) - ScanOrderOpenTime() >= 60 * TimeDelay) { while (ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() > 0) CloseTC1CycleOrders(); FirstTradeCycle = FALSE; SecondTradeCycle = TRUE; } } if (SecondTradeCycle && !FirstTradeCycle) { if (ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() == 0) { if (TimeFilter) { if (StrToTime(CurrentTime()) >= StrToTime(StartTrading) && StrToTime(CurrentTime()) <= StrToTime(StopTrading)) { if (SecondTradeCycleDirection == 1) TC2Buy(); else { if (SecondTradeCycleDirection != 2) return; TC2Sell(); } } } if (!TimeFilter) { if (SecondTradeCycleDirection == 1) TC2Buy(); else { if (SecondTradeCycleDirection != 2) return; TC2Sell(); } } } } if (SecondTradeCycle && !FirstTradeCycle) { if (ScanTC2BuyLastPrice() != 0.0 && GetPrice(2, 0, 0) - (TC2GridSpacing + (ScanTC2BuyOrders() + 1) * TC2AddGainPoint) * gd_536 >= ScanTC2BuyLastPrice() && ActivePerformance() >= Tolerance && ExitPeriodFilter() && StrToTime(CurrentTime()) - ScanOrderOpenTime() >= 60 * TimeDelay) { while (ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders() > 0) CloseTC2CycleOrders(); SecondTradeCycle = FALSE; FirstTradeCycle = TRUE; } } } return (0); } int CheckAuthorization() { bool li_ret_0 = FALSE; int l_acc_number_4 = AccountNumber(); if (gi_80 == FALSE) li_ret_0 = TRUE; if (gi_80 == TRUE) { if (l_acc_number_4 == 123434) li_ret_0 = TRUE; if (l_acc_number_4 == 232324) li_ret_0 = TRUE; if (l_acc_number_4 == 454645) li_ret_0 = TRUE; } return (li_ret_0); } int CheckTradingDays() { bool li_ret_0 = FALSE; if (TradeOnMonday && DayOfWeek() == 1) li_ret_0 = TRUE; if (TradeOnTuesday && DayOfWeek() == 2) li_ret_0 = TRUE; if (TradeOnWednesday && DayOfWeek() == 3) li_ret_0 = TRUE; if (TradeOnThursday && DayOfWeek() == 4) li_ret_0 = TRUE; if (TradeOnFriday && DayOfWeek() == 5) li_ret_0 = TRUE; return (li_ret_0); } void Volatility_Screen(double &a_ima_0, double &ad_8, double &ad_16, double &a_ima_24, double &ad_32, double &ad_40) { a_ima_0 = iMA(Symbol(), txt2tf(gs_488), g_period_496, 0, MODE_EMA, PRICE_CLOSE, 0); ad_8 = a_ima_0 + gd_504 * atr(gi_500); ad_16 = a_ima_0 - gd_504 * atr(gi_500); a_ima_24 = iMA(Symbol(), txt2tf(gs_488), g_period_512, 0, MODE_SMA, PRICE_CLOSE, 0); ad_32 = a_ima_24 + bb(g_period_512, gd_516, a_ima_24); ad_40 = a_ima_24 - bb(g_period_512, gd_516, a_ima_24); } double atr(int ai_0) { double ld_4 = 0; int li_12 = 0; if (iBars(Symbol(), txt2tf(gs_488)) <= ai_0) return (0); for (li_12 = ai_0 - 1; li_12 >= 0; li_12--) { ld_4 += MathMax(iHigh(Symbol(), txt2tf(gs_488), li_12), iClose(Symbol(), txt2tf(gs_488), li_12 + 1)) - MathMin(iLow(Symbol(), txt2tf(gs_488), li_12), iClose(Symbol(), txt2tf(gs_488), li_12 + 1)); } return (ld_4 / ai_0); } double bb(int ai_0, int ai_4, double ad_8) { double ld_28; double ld_16 = 0.0; int li_24 = 0; if (iBars(Symbol(), txt2tf(gs_488)) <= ai_0) return (0); for (li_24 = ai_0 - 1; li_24 >= 0; li_24--) { ld_28 = iClose(Symbol(), txt2tf(gs_488), li_24) - ad_8; ld_16 += ld_28 * ld_28; } return (ai_4 * MathSqrt(ld_16 / ai_0)); } int TimeHibernation() { if (TimeHibernation) { if (ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC2BuyOrders() + ScanTC2SellOrders() != 0) return (0); return (1); } return (0); } void HibernationMail() { SendMail("Hedge Hulk" + " Hiberation", "Your EA now in hibernation. Please check if you would like to reset." + "\n" + "Date: " + Year() + "." + Month() + "." + Day() + "\n" + "Time: " + CurrentTime() + "\n" + "Account Number: " + DoubleToStr(AccountNumber(), 0) + "\n" + "Instrument: " + Symbol()); } string CurrentTime() { string ls_ret_0 = StringConcatenate(DoubleToStr(Hour(), 0), ":", DoubleToStr(Minute(), 0)); if (Hour() < 10) ls_ret_0 = "0" + ls_ret_0; if (Minute() == 0) ls_ret_0 = StringSubstr(ls_ret_0, 0, 2) + ":0" + StringSubstr(ls_ret_0, 3); return (ls_ret_0); } int SpreadLimit() { if (MarketInfo(Symbol(), MODE_DIGITS) == 3.0 || MarketInfo(Symbol(), MODE_DIGITS) == 5.0) { if (SpreadLimit <= 0) { if (Symbol() == "EURUSD" || Symbol() == "EURUSD" + SymbolSuffix) return (30); if (Symbol() == "USDJPY" || Symbol() == "USDJPY" + SymbolSuffix) return (40); if (Symbol() == "GBPUSD" || Symbol() == "GBPUSD" + SymbolSuffix) return (50); if (Symbol() == "USDCHF" || Symbol() == "USDCHF" + SymbolSuffix) return (50); if (Symbol() == "USDCAD" || Symbol() == "USDCAD" + SymbolSuffix) return (70); if (Symbol() == "AUDUSD" || Symbol() == "AUDUSD" + SymbolSuffix) return (70); if (Symbol() == "NZDUSD" || Symbol() == "NZDUSD" + SymbolSuffix) return (70); if (Symbol() == "EURGBP" || Symbol() == "EURGBP" + SymbolSuffix) return (40); if (Symbol() == "EURJPY" || Symbol() == "EURJPY" + SymbolSuffix) return (100); if (Symbol() == "EURCHF" || Symbol() == "EURCHF" + SymbolSuffix) return (70); if (Symbol() == "EURCAD" || Symbol() == "EURCAD" + SymbolSuffix) return (120); if (Symbol() == "EURAUD" || Symbol() == "EURAUD" + SymbolSuffix) return (120); if (Symbol() == "GBPCHF" || Symbol() == "GBPCHF" + SymbolSuffix) return (120); if (Symbol() == "GBPJPY" || Symbol() == "GBPJPY" + SymbolSuffix) return (100); if (Symbol() == "NZDJPY" || Symbol() == "NZDJPY" + SymbolSuffix) return (100); if (Symbol() == "AUDNZD" || Symbol() == "AUDNZD" + SymbolSuffix) return (100); if (Symbol() == "AUDCAD" || Symbol() == "AUDCAD" + SymbolSuffix) return (80); if (Symbol() == "AUDJPY" || Symbol() == "AUDJPY" + SymbolSuffix) return (80); if (Symbol() == "CHFJPY" || Symbol() == "CHFJPY" + SymbolSuffix) return (60); } } if (MarketInfo(Symbol(), MODE_DIGITS) == 2.0 || MarketInfo(Symbol(), MODE_DIGITS) == 4.0) { if (SpreadLimit <= 0) { if (Symbol() == "EURUSD" || Symbol() == "EURUSD" + SymbolSuffix) return (3); if (Symbol() == "USDJPY" || Symbol() == "USDJPY" + SymbolSuffix) return (4); if (Symbol() == "GBPUSD" || Symbol() == "GBPUSD" + SymbolSuffix) return (5); if (Symbol() == "USDCHF" || Symbol() == "USDCHF" + SymbolSuffix) return (5); if (Symbol() == "USDCAD" || Symbol() == "USDCAD" + SymbolSuffix) return (7); if (Symbol() == "AUDUSD" || Symbol() == "AUDUSD" + SymbolSuffix) return (7); if (Symbol() == "NZDUSD" || Symbol() == "NZDUSD" + SymbolSuffix) return (7); if (Symbol() == "EURGBP" || Symbol() == "EURGBP" + SymbolSuffix) return (4); if (Symbol() == "EURJPY" || Symbol() == "EURJPY" + SymbolSuffix) return (10); if (Symbol() == "EURCHF" || Symbol() == "EURCHF" + SymbolSuffix) return (7); if (Symbol() == "EURCAD" || Symbol() == "EURCAD" + SymbolSuffix) return (12); if (Symbol() == "EURAUD" || Symbol() == "EURAUD" + SymbolSuffix) return (12); if (Symbol() == "GBPCHF" || Symbol() == "GBPCHF" + SymbolSuffix) return (12); if (Symbol() == "GBPJPY" || Symbol() == "GBPJPY" + SymbolSuffix) return (10); if (Symbol() == "NZDJPY" || Symbol() == "NZDJPY" + SymbolSuffix) return (10); if (Symbol() == "AUDNZD" || Symbol() == "AUDNZD" + SymbolSuffix) return (10); if (Symbol() == "AUDCAD" || Symbol() == "AUDCAD" + SymbolSuffix) return (8); if (Symbol() == "AUDJPY" || Symbol() == "AUDJPY" + SymbolSuffix) return (8); if (Symbol() == "CHFJPY" || Symbol() == "CHFJPY" + SymbolSuffix) return (6); } } if (SpreadLimit > 0) return (SpreadLimit); return (0); } void Comments() { string ls_0 = ""; if (AccountEquity() - MaxAccountBalance() < gd_548) { gd_548 = AccountEquity() - MaxAccountBalance(); gd_564 = 100.0 * (gd_548 / MaxAccountBalance()); } if (100.0 * ((AccountEquity() - MaxAccountBalance()) / MaxAccountBalance()) < gd_556) gd_556 = 100.0 * ((AccountEquity() - MaxAccountBalance()) / MaxAccountBalance()); if (MarketInfo(Symbol(), MODE_SPREAD) > g_spread_544) g_spread_544 = MarketInfo(Symbol(), MODE_SPREAD); DisplayText("Expert", "Hedge Hulk", "ArialBold", 16, LightGreen, 5, 10); DisplayText("Build", " - " + "HH003", "ArialBold", 9, MediumSpringGreen, 115, 16); DisplayText("TC1BuyStake", "TC1 Initial Buy: " + DoubleToStr(BuyAutoLotSize(TC1BuyLotSize, TC1BuyStakePercent), 2) + " lot", "ArialBold", 10, Blue, 5, 35); DisplayText("TC1SellStake", "TC1 Initial Sell: " + DoubleToStr(SellAutoLotSize(TC1SellLotSize, TC1SellStakePercent), 2) + " lot", "ArialBold", 10, Red, 145, 35); DisplayText("TC2BuyStake", "TC2 Initial Buy: " + DoubleToStr(BuyAutoLotSize(TC2BuyLotSize, TC2BuyStakePercent), 2) + " lot", "ArialBold", 10, Blue, 5, 55); DisplayText("TC2SellStake", "TC2 Initial Sell: " + DoubleToStr(SellAutoLotSize(TC2SellLotSize, TC2SellStakePercent), 2) + " lot", "ArialBold", 10, Red, 145, 55); ls_0 = ls_0 + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n"; ls_0 = ls_0 + " " + "Creator: Max Ong" + "\n" + " " + "Property of http:www.kaizentraders.com" + "\n"; ls_0 = ls_0 + " " + "Server Date & Time: " + Year() + "." + Month() + "." + Day() + " " + CurrentTime() + "\n"; if (DisplayCommentary) { ls_0 = ls_0 + " " + "--------------------------------------------------------------------------" + "\n" + " " + "Trading Instrument: " + Symbol() + "\n" + " " + "Tab ID: " + TabID + "\n" + " " + "--------------------------------------------------------------------------" + "\n" + " " + "Leverage: " + AccountLeverage() + " " + " " + "Spread: " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD), 0) + " (Max: " + DoubleToStr(g_spread_544, 0) + ")" + "\n" + " " + "Swap Long: " + "$" + DoubleToStr(MarketInfo(Symbol(), MODE_SWAPLONG), 2) + "/lot" + " " + " " + "Swap Short: " + "$" + DoubleToStr(MarketInfo(Symbol(), MODE_SWAPSHORT), 2) + "/lot" + "\n" + " " + "--------------------------------------------------------------------------" + "\n" + " " + "Account Number: " + AccountNumber() + "\n" + " " + "--------------------------------------------------------------------------" + "\n" + " " + "Capital: " + "$" + DoubleToStr(Capital, 2) + " " + "Profit:" + " " + "$" + DoubleToStr(NormalizeDouble(AccountEquity() - Capital, 2), 2) + " " + "(" + DoubleToStr(NormalizeDouble(100.0 * ((AccountEquity() - Capital) / Capital), 2), 2) + "%" + ")" + "\n" + " " + "Current Performance: " + "$" + DoubleToStr(ScanTC1CycleProfit() + ScanTC2CycleProfit(), 2) + " " + "(" + DoubleToStr(ActivePerformance(), 2) + "%" + ")" + "\n" + " " + "Maximum Drawdown: " + "$" + DoubleToStr(gd_548, 2) + "\n" + " " + "Drawdown Percent: " + "Abs:" + DoubleToStr(gd_564, 2) + "%" + " " + "Rel: " + DoubleToStr(gd_556, 2) + "%" + "\n" + "\n" + " " + "Account Balance: " + "$" + DoubleToStr(AccountBalance(), 2) + "\n" + " " + "Account Equity: " + "$" + DoubleToStr(AccountEquity(), 2) + "\n" + " " + "Account Margin Used: " + "$" + DoubleToStr(AccountMargin(), 2) + "\n" + " " + "Account Free Margin: " + "$" + DoubleToStr(AccountFreeMargin(), 2) + "\n" + " " + "--------------------------------------------------------------------------" + "\n" + " " + "First Trade Cycle" + "\n" + " " + "--------------------------------------------------------------------------" + "\n" + " " + "First Buy: " + DoubleToStr(ScanTC1BuyFirstPrice(), MarketInfo(Symbol(), MODE_DIGITS)) + " " + " " + "First Sell: " + DoubleToStr(ScanTC1SellFirstPrice(), MarketInfo(Symbol(), MODE_DIGITS)) + "\n" + " " + "Last Buy: " + DoubleToStr(ScanTC1BuyLastPrice(), MarketInfo(Symbol(), MODE_DIGITS)) + " " + " " + "Last Sell: " + DoubleToStr(ScanTC1SellLastPrice(), MarketInfo(Symbol(), MODE_DIGITS)) + "\n" + " " + "Buy Orders: " + DoubleToStr(ScanTC1BuyOrders(), 0) + " orders" + " from " + DoubleToStr(ScanTC1BuyLots(), 2) + " lots" + "\n" + " " + "Sell Orders: " + DoubleToStr(ScanTC1SellOrders(), 0) + " orders" + " from " + DoubleToStr(ScanTC1SellLots(), 2) + " lots" + "\n" + " " + "--------------------------------------------------------------------------" + "\n" + " " + "Second Trade Cycle" + "\n" + " " + "--------------------------------------------------------------------------" + "\n" + " " + "First Buy: " + DoubleToStr(ScanTC2BuyFirstPrice(), MarketInfo(Symbol(), MODE_DIGITS)) + " " + " " + "First Sell: " + DoubleToStr(ScanTC2SellFirstPrice(), MarketInfo(Symbol(), MODE_DIGITS)) + "\n" + " " + "Last Buy: " + DoubleToStr(ScanTC2BuyLastPrice(), MarketInfo(Symbol(), MODE_DIGITS)) + " " + " " + "Last Sell: " + DoubleToStr(ScanTC2SellLastPrice(), MarketInfo(Symbol(), MODE_DIGITS)) + "\n" + " " + "Buy Orders: " + DoubleToStr(ScanTC2BuyOrders(), 0) + " orders" + " from " + DoubleToStr(ScanTC2BuyLots(), 2) + " lots" + "\n" + " " + "Sell Orders: " + DoubleToStr(ScanTC2SellOrders(), 0) + " orders" + " from " + DoubleToStr(ScanTC2SellLots(), 2) + " lots" + "\n"; ls_0 = ls_0 + " " + "--------------------------------------------------------------------------" + "\n"; } Comment(ls_0); } void DisplayText(string a_name_0, string a_text_8, string a_fontname_16, int a_fontsize_24, color a_color_28, int a_x_32, int a_y_36) { ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0); ObjectSetText(a_name_0, a_text_8, a_fontsize_24, a_fontname_16, a_color_28); ObjectSet(a_name_0, OBJPROP_CORNER, 0); ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_32); ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_36); } void EmergencyExit() { if (ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() > 0) while (ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() > 0) CloseTC1CycleOrders(); if (ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders() > 0) while (ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders() > 0) CloseTC2CycleOrders(); } double GetPrice(int ai_0, int a_timeframe_4, int ai_8) { switch (ai_0) { case 1: return (MarketInfo(Symbol(), MODE_ASK)); case 2: return (MarketInfo(Symbol(), MODE_BID)); case 3: return (iClose(Symbol(), a_timeframe_4, ai_8)); case 4: return (iHigh(Symbol(), a_timeframe_4, ai_8)); case 5: return (iLow(Symbol(), a_timeframe_4, ai_8)); } return (0.0); } double ScanTC1BuyFirstPrice() { double l_ord_open_price_0; for (int l_ord_total_8 = OrdersTotal(); l_ord_total_8 >= 0; l_ord_total_8--) { OrderSelect(l_ord_total_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_732 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_open_price_0 = OrderOpenPrice(); } return (l_ord_open_price_0); } double ScanTC1BuyLastPrice() { double l_ord_open_price_0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_732 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_open_price_0 = OrderOpenPrice(); } return (l_ord_open_price_0); } double ScanTC1SellFirstPrice() { double l_ord_open_price_0; for (int l_ord_total_8 = OrdersTotal(); l_ord_total_8 >= 0; l_ord_total_8--) { OrderSelect(l_ord_total_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_736 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_open_price_0 = OrderOpenPrice(); } return (l_ord_open_price_0); } double ScanTC1SellLastPrice() { double l_ord_open_price_0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_736 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_open_price_0 = OrderOpenPrice(); } return (l_ord_open_price_0); } double ScanTC2BuyFirstPrice() { double l_ord_open_price_0; for (int l_ord_total_8 = OrdersTotal(); l_ord_total_8 >= 0; l_ord_total_8--) { OrderSelect(l_ord_total_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_740 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_open_price_0 = OrderOpenPrice(); } return (l_ord_open_price_0); } double ScanTC2BuyLastPrice() { double l_ord_open_price_0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_740 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_open_price_0 = OrderOpenPrice(); } return (l_ord_open_price_0); } double ScanTC2SellFirstPrice() { double l_ord_open_price_0; for (int l_ord_total_8 = OrdersTotal(); l_ord_total_8 >= 0; l_ord_total_8--) { OrderSelect(l_ord_total_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_744 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_open_price_0 = OrderOpenPrice(); } return (l_ord_open_price_0); } double ScanTC2SellLastPrice() { double l_ord_open_price_0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_744 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_open_price_0 = OrderOpenPrice(); } return (l_ord_open_price_0); } double ScanTC1BuyLots() { double ld_ret_0 = 0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_732 || OrderMagicNumber() == g_magic_748 && OrderSymbol() == Symbol() && OrderComment() == TabID) ld_ret_0 += OrderLots(); } return (ld_ret_0); } double ScanTC1SellLots() { double ld_ret_0 = 0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_736 || OrderMagicNumber() == g_magic_752 && OrderSymbol() == Symbol() && OrderComment() == TabID) ld_ret_0 += OrderLots(); } return (ld_ret_0); } double ScanTC2BuyLots() { double ld_ret_0 = 0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_740 || OrderMagicNumber() == g_magic_756 && OrderSymbol() == Symbol() && OrderComment() == TabID) ld_ret_0 += OrderLots(); } return (ld_ret_0); } double ScanTC2SellLots() { double ld_ret_0 = 0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_744 || OrderMagicNumber() == g_magic_760 && OrderSymbol() == Symbol() && OrderComment() == TabID) ld_ret_0 += OrderLots(); } return (ld_ret_0); } double ScanTC1CycleProfit() { double ld_0 = 0; double ld_8 = 0; for (int l_pos_16 = 0; l_pos_16 < OrdersTotal(); l_pos_16++) { OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_732 || OrderMagicNumber() == g_magic_748 && OrderSymbol() == Symbol() && OrderComment() == TabID) ld_0 += OrderProfit() + OrderSwap() + OrderCommission(); if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_736 || OrderMagicNumber() == g_magic_752 && OrderSymbol() == Symbol() && OrderComment() == TabID) ld_8 += OrderProfit() + OrderSwap() + OrderCommission(); } return (ld_0 + ld_8); } double ScanTC2CycleProfit() { double ld_0 = 0; double ld_8 = 0; for (int l_pos_16 = 0; l_pos_16 < OrdersTotal(); l_pos_16++) { OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_740 || OrderMagicNumber() == g_magic_756 && OrderSymbol() == Symbol() && OrderComment() == TabID) ld_0 += OrderProfit() + OrderSwap() + OrderCommission(); if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_744 || OrderMagicNumber() == g_magic_760 && OrderSymbol() == Symbol() && OrderComment() == TabID) ld_8 += OrderProfit() + OrderSwap() + OrderCommission(); } return (ld_0 + ld_8); } void CloseTC1CycleOrders() { color l_color_0; color l_color_4; int l_cmd_16; bool l_ord_close_20; if (DisplayArrows) { l_color_0 = ForestGreen; l_color_4 = OrangeRed; } else { l_color_0 = CLR_NONE; l_color_4 = CLR_NONE; } int 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); l_cmd_16 = OrderType(); l_ord_close_20 = FALSE; switch (l_cmd_16) { case OP_BUY: if (OrderMagicNumber() == g_magic_732 || OrderMagicNumber() == g_magic_748 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_close_20 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, l_color_0); break; case OP_SELL: if (OrderMagicNumber() == g_magic_736 || OrderMagicNumber() == g_magic_752 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_close_20 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, l_color_4); } if (l_ord_close_20 == 0) { Print("Order ", OrderTicket(), " failed to close. Error:", GetLastError()); Sleep(3000); } } } void CloseTC2CycleOrders() { color l_color_0; color l_color_4; int l_cmd_16; bool l_ord_close_20; if (DisplayArrows) { l_color_0 = ForestGreen; l_color_4 = OrangeRed; } else { l_color_0 = CLR_NONE; l_color_4 = CLR_NONE; } int 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); l_cmd_16 = OrderType(); l_ord_close_20 = FALSE; switch (l_cmd_16) { case OP_BUY: if (OrderMagicNumber() == g_magic_740 || OrderMagicNumber() == g_magic_756 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_close_20 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, l_color_0); break; case OP_SELL: if (OrderMagicNumber() == g_magic_744 || OrderMagicNumber() == g_magic_760 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_ord_close_20 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, l_color_4); } if (l_ord_close_20 == 0) { Print("Order ", OrderTicket(), " failed to close. Error:", GetLastError()); Sleep(3000); } } } int ScanAllOrders() { int li_ret_0 = ScanTC1BuyOrders() + ScanTC1SellOrders() + ScanTC2BuyOrders() + ScanTC2SellOrders() + ScanTC1PBuyOrders() + ScanTC1PSellOrders() + ScanTC2PBuyOrders() + ScanTC2PSellOrders(); return (li_ret_0); } int ScanTC1BuyOrders() { int l_ord_total_0 = OrdersTotal(); int l_count_4 = 0; for (int l_pos_8 = 0; l_pos_8 < l_ord_total_0; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_732 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_count_4++; } return (l_count_4); } int ScanTC1PBuyOrders() { int l_ord_total_0 = OrdersTotal(); int l_count_4 = 0; for (int l_pos_8 = 0; l_pos_8 < l_ord_total_0; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_748 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_count_4++; } return (l_count_4); } int ScanTC1SellOrders() { int l_ord_total_0 = OrdersTotal(); int l_count_4 = 0; for (int l_pos_8 = 0; l_pos_8 < l_ord_total_0; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_736 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_count_4++; } return (l_count_4); } int ScanTC1PSellOrders() { int l_ord_total_0 = OrdersTotal(); int l_count_4 = 0; for (int l_pos_8 = 0; l_pos_8 < l_ord_total_0; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_752 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_count_4++; } return (l_count_4); } int ScanTC2BuyOrders() { int l_ord_total_0 = OrdersTotal(); int l_count_4 = 0; for (int l_pos_8 = 0; l_pos_8 < l_ord_total_0; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_740 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_count_4++; } return (l_count_4); } int ScanTC2PBuyOrders() { int l_ord_total_0 = OrdersTotal(); int l_count_4 = 0; for (int l_pos_8 = 0; l_pos_8 < l_ord_total_0; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_756 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_count_4++; } return (l_count_4); } int ScanTC2SellOrders() { int l_ord_total_0 = OrdersTotal(); int l_count_4 = 0; for (int l_pos_8 = 0; l_pos_8 < l_ord_total_0; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_744 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_count_4++; } return (l_count_4); } int ScanTC2PSellOrders() { int l_ord_total_0 = OrdersTotal(); int l_count_4 = 0; for (int l_pos_8 = 0; l_pos_8 < l_ord_total_0; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_744 && OrderSymbol() == Symbol() && OrderComment() == TabID) l_count_4++; } return (l_count_4); } double BuyAutoLotSize(double a_minlot_0, double ad_8) { int li_16 = 0; int l_leverage_20 = 0; double ld_ret_24 = 0; l_leverage_20 = AccountLeverage(); if (g_minlot_636 <= 0.0) g_minlot_636 = MarketInfo(Symbol(), MODE_MINLOT); if (g_lotstep_652 <= 0.0) g_lotstep_652 = MarketInfo(Symbol(), MODE_LOTSTEP); if (g_lotsize_660 <= 0.0) g_lotsize_660 = MarketInfo(Symbol(), MODE_LOTSIZE); if (a_minlot_0 < MarketInfo(Symbol(), MODE_MINLOT)) { Alert("Lot size to open is too small. Set to minimum lot allowable by broker : " + MarketInfo(Symbol(), MODE_MINLOT)); a_minlot_0 = MarketInfo(Symbol(), MODE_MINLOT); } if (g_lotstep_652 == 0.001) li_16 = 3; if (g_lotstep_652 == 0.01) li_16 = 2; if (g_lotstep_652 == 0.1) li_16 = 1; if (UseCapitalManagement) { ld_ret_24 = AccountBalance() * (ad_8 / 100.0) / (g_lotsize_660 / l_leverage_20); ld_ret_24 = NormalizeDouble(MathAbs(ld_ret_24), li_16); } else ld_ret_24 = NormalizeDouble(MathAbs(a_minlot_0), li_16); if (ld_ret_24 < g_minlot_636) ld_ret_24 = g_minlot_636; return (ld_ret_24); } double SellAutoLotSize(double a_minlot_0, double ad_8) { int li_16 = 0; int l_leverage_20 = 0; double ld_ret_24 = 0; l_leverage_20 = AccountLeverage(); if (g_minlot_636 <= 0.0) g_minlot_636 = MarketInfo(Symbol(), MODE_MINLOT); if (g_lotstep_652 <= 0.0) g_lotstep_652 = MarketInfo(Symbol(), MODE_LOTSTEP); if (g_lotsize_660 <= 0.0) g_lotsize_660 = MarketInfo(Symbol(), MODE_LOTSIZE); if (a_minlot_0 < MarketInfo(Symbol(), MODE_MINLOT)) { Alert("Lot size to open is too small. Set to minimum lot allowable by broker : " + MarketInfo(Symbol(), MODE_MINLOT)); a_minlot_0 = MarketInfo(Symbol(), MODE_MINLOT); } if (g_lotstep_652 == 0.001) li_16 = 3; if (g_lotstep_652 == 0.01) li_16 = 2; if (g_lotstep_652 == 0.1) li_16 = 1; if (UseCapitalManagement) { ld_ret_24 = AccountBalance() * (ad_8 / 100.0) / (g_lotsize_660 / l_leverage_20); ld_ret_24 = NormalizeDouble(MathAbs(ld_ret_24), li_16); } else ld_ret_24 = NormalizeDouble(MathAbs(a_minlot_0), li_16); if (ld_ret_24 < g_minlot_636) ld_ret_24 = g_minlot_636; return (ld_ret_24); } int TC1Buy() { int li_4; double ld_8; double l_price_24; double l_price_32; color l_color_48; double l_ima_52; double ld_60; double ld_68; double l_ima_76; double ld_84; double ld_92; int li_100; int li_0 = 0; if (DisplayArrows) l_color_48 = Blue; else l_color_48 = CLR_NONE; Volatility_Screen(l_ima_52, ld_60, ld_68, l_ima_76, ld_84, ld_92); string l_comment_40 = TabID; if (g_maxlot_644 == 0.0) g_maxlot_644 = MarketInfo(Symbol(), MODE_MAXLOT); if (g_lotstep_652 == 0.0) g_lotstep_652 = MarketInfo(Symbol(), MODE_LOTSTEP); if (g_lotstep_652 == 0.001) li_4 = 3; if (g_lotstep_652 == 0.01) li_4 = 2; if (g_lotstep_652 == 0.1) li_4 = 1; double l_ask_16 = GetPrice(1, 0, 0); for (int l_pos_104 = 0; l_pos_104 < OrdersTotal(); l_pos_104++) { OrderSelect(l_pos_104, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_732 && OrderSymbol() == Symbol() && OrderComment() == TabID) li_0++; } if (g_ord_open_price_684 == 0.0) { for (l_pos_104 = 0; l_pos_104 < OrdersTotal(); l_pos_104++) { OrderSelect(l_pos_104, SELECT_BY_POS, MODE_TRADES); g_cmd_716 = OrderType(); if (OrderMagicNumber() == g_magic_732 && OrderSymbol() == Symbol() && OrderComment() == TabID) { g_ord_open_price_684 = OrderOpenPrice(); if (g_cmd_716 == OP_BUY) gi_668 = 1; } } } if (li_0 < 1) { gi_668 = 3; if (FirstTradeCycle == TRUE) gi_668 = 1; } if (li_0 != 0) { li_100 = TC1GridSpacing; for (int li_108 = 1; li_108 <= li_0; li_108++) { if (VolatilityScreen) { if (ld_84 >= ld_60 || ld_92 <= ld_68) li_100 = NormalizeDouble(VolatilityMultiplier * (TC1GridSpacing + MathMax(li_0, 1) * TC1GridIncrement), 0); else li_100 = NormalizeDouble(TC1GridSpacing + MathMax(li_0, 1) * TC1GridIncrement, 0); } else li_100 = NormalizeDouble(TC1GridSpacing + MathMax(li_0, 1) * TC1GridIncrement, 0); } } else li_100 = TC1GridSpacing; RefreshRates(); if (gi_668 == 1) { if (l_ask_16 - g_ord_open_price_684 >= li_100 * gd_536 || li_0 < 1 && ScanAllOrders() <= MaxOrderNumber && MarketInfo(Symbol(), MODE_SPREAD) <= SpreadLimit() && CheckTradingDays() && EntryPeriodFilter()) { l_ask_16 = MarketInfo(Symbol(), MODE_ASK); g_ord_open_price_684 = 0; if (gi_612 == 0) l_price_24 = 0; else l_price_24 = l_ask_16 - MathAbs(gi_612) * gd_536; if (gi_604 == 0) l_price_32 = 0; else l_price_32 = l_ask_16 + MathAbs(gi_604) * gd_536; if (li_0 != 0) { ld_8 = BuyAutoLotSize(TC1BuyLotSize, TC1BuyStakePercent); for (l_pos_104 = 1; l_pos_104 <= li_0; l_pos_104++) { ld_8 = NormalizeDouble(ld_8 * (TC1BuyMultiplier - (li_0 + 1) * AntiProgressionPercent / 100.0), li_4); ld_8 = MathMax(ld_8, MarketInfo(Symbol(), MODE_MINLOT)); } } else ld_8 = BuyAutoLotSize(TC1BuyLotSize, TC1BuyStakePercent); if (ld_8 <= g_maxlot_644) { RefreshRates(); OrderSend(Symbol(), OP_BUY, NormalizeDouble(ld_8, li_4), l_ask_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_732, 0, l_color_48); } else { if (ld_8 > g_maxlot_644) { RefreshRates(); OrderSend(Symbol(), OP_BUY, NormalizeDouble((ld_8 / g_maxlot_644 - MathFloor(ld_8 / g_maxlot_644)) * g_maxlot_644, li_4), l_ask_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_732, 0, l_color_48); for (int l_count_112 = 0; l_count_112 < MathFloor(ld_8 / g_maxlot_644); l_count_112++) { RefreshRates(); OrderSend(Symbol(), OP_BUY, g_maxlot_644, l_ask_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_748, 0, l_color_48); } } } } } return (0); } int TC1Sell() { int li_4; double ld_8; double l_price_24; double l_price_32; color l_color_48; double l_ima_52; double ld_60; double ld_68; double l_ima_76; double ld_84; double ld_92; int li_100; int li_0 = 0; if (DisplayArrows) l_color_48 = Red; else l_color_48 = CLR_NONE; Volatility_Screen(l_ima_52, ld_60, ld_68, l_ima_76, ld_84, ld_92); string l_comment_40 = TabID; if (g_maxlot_644 == 0.0) g_maxlot_644 = MarketInfo(Symbol(), MODE_MAXLOT); if (g_lotstep_652 == 0.0) g_lotstep_652 = MarketInfo(Symbol(), MODE_LOTSTEP); if (g_lotstep_652 == 0.001) li_4 = 3; if (g_lotstep_652 == 0.01) li_4 = 2; if (g_lotstep_652 == 0.1) li_4 = 1; double l_bid_16 = GetPrice(2, 0, 0); for (int l_pos_104 = 0; l_pos_104 < OrdersTotal(); l_pos_104++) { OrderSelect(l_pos_104, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_736 && OrderSymbol() == Symbol() && OrderComment() == TabID) li_0++; } if (g_ord_open_price_692 == 0.0) { for (l_pos_104 = 0; l_pos_104 < OrdersTotal(); l_pos_104++) { OrderSelect(l_pos_104, SELECT_BY_POS, MODE_TRADES); g_cmd_720 = OrderType(); if (OrderMagicNumber() == g_magic_736 && OrderSymbol() == Symbol() && OrderComment() == TabID) { g_ord_open_price_692 = OrderOpenPrice(); if (g_cmd_720 == OP_SELL) gi_672 = 2; } } } if (li_0 < 1) { gi_672 = 3; if (FirstTradeCycle == TRUE) gi_672 = 2; } if (li_0 != 0) { li_100 = TC1GridSpacing; for (int li_108 = 1; li_108 <= li_0; li_108++) { if (VolatilityScreen) { if (ld_84 >= ld_60 || ld_92 <= ld_68) li_100 = NormalizeDouble(VolatilityMultiplier * (TC1GridSpacing + MathMax(li_0, 1) * TC1GridIncrement), 0); else li_100 = NormalizeDouble(TC1GridSpacing + MathMax(li_0, 1) * TC1GridIncrement, 0); } else li_100 = NormalizeDouble(TC1GridSpacing + MathMax(li_0, 1) * TC1GridIncrement, 0); } } else li_100 = TC1GridSpacing; RefreshRates(); if (gi_672 == 2) { if (l_bid_16 - g_ord_open_price_692 >= li_100 * gd_536 || li_0 < 1 && ScanAllOrders() <= MaxOrderNumber && MarketInfo(Symbol(), MODE_SPREAD) <= SpreadLimit() && CheckTradingDays() && EntryPeriodFilter()) { l_bid_16 = MarketInfo(Symbol(), MODE_BID); g_ord_open_price_692 = 0; if (gi_616 == 0) l_price_24 = 0; else l_price_24 = l_bid_16 + MathAbs(gi_616) * gd_536; if (gi_608 == 0) l_price_32 = 0; else l_price_32 = l_bid_16 - MathAbs(gi_608) * gd_536; if (li_0 != 0) { ld_8 = SellAutoLotSize(TC1SellLotSize, TC1SellStakePercent); for (l_pos_104 = 1; l_pos_104 <= li_0; l_pos_104++) { ld_8 = NormalizeDouble(ld_8 * (TC1SellMultiplier - (li_0 + 1) * AntiProgressionPercent / 100.0), li_4); ld_8 = MathMax(ld_8, MarketInfo(Symbol(), MODE_MINLOT)); } } else ld_8 = SellAutoLotSize(TC1SellLotSize, TC1SellStakePercent); if (ld_8 <= g_maxlot_644) { RefreshRates(); OrderSend(Symbol(), OP_SELL, NormalizeDouble(ld_8, li_4), l_bid_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_736, 0, l_color_48); } else { if (ld_8 > g_maxlot_644) { RefreshRates(); OrderSend(Symbol(), OP_SELL, NormalizeDouble((ld_8 / g_maxlot_644 - MathFloor(ld_8 / g_maxlot_644)) * g_maxlot_644, li_4), l_bid_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_736, 0, l_color_48); for (int l_count_112 = 0; l_count_112 < MathFloor(ld_8 / g_maxlot_644); l_count_112++) { RefreshRates(); OrderSend(Symbol(), OP_SELL, g_maxlot_644, l_bid_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_752, 0, l_color_48); } } } } } return (0); } int TC2Buy() { int li_4; double ld_8; double l_price_24; double l_price_32; color l_color_48; double l_ima_52; double ld_60; double ld_68; double l_ima_76; double ld_84; double ld_92; int li_100; int li_0 = 0; if (DisplayArrows) l_color_48 = Black; else l_color_48 = CLR_NONE; Volatility_Screen(l_ima_52, ld_60, ld_68, l_ima_76, ld_84, ld_92); string l_comment_40 = TabID; if (g_maxlot_644 == 0.0) g_maxlot_644 = MarketInfo(Symbol(), MODE_MAXLOT); if (g_lotstep_652 == 0.0) g_lotstep_652 = MarketInfo(Symbol(), MODE_LOTSTEP); if (g_lotstep_652 == 0.001) li_4 = 3; if (g_lotstep_652 == 0.01) li_4 = 2; if (g_lotstep_652 == 0.1) li_4 = 1; double l_ask_16 = GetPrice(1, 0, 0); for (int l_pos_104 = 0; l_pos_104 < OrdersTotal(); l_pos_104++) { OrderSelect(l_pos_104, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_740 && OrderSymbol() == Symbol() && OrderComment() == TabID) li_0++; } if (g_ord_open_price_700 == 0.0) { for (l_pos_104 = 0; l_pos_104 < OrdersTotal(); l_pos_104++) { OrderSelect(l_pos_104, SELECT_BY_POS, MODE_TRADES); g_cmd_724 = OrderType(); if (OrderMagicNumber() == g_magic_740 && OrderSymbol() == Symbol() && OrderComment() == TabID) { g_ord_open_price_700 = OrderOpenPrice(); if (g_cmd_724 == OP_BUY) gi_676 = 1; } } } if (li_0 < 1) { gi_676 = 3; if (SecondTradeCycle == TRUE) gi_676 = 1; } if (li_0 != 0) { li_100 = TC2GridSpacing; for (int li_108 = 1; li_108 <= li_0; li_108++) { if (VolatilityScreen) { if (ld_84 >= ld_60 || ld_92 <= ld_68) li_100 = NormalizeDouble(VolatilityMultiplier * (TC2GridSpacing + MathMax(li_0, 1) * TC2GridIncrement), 0); else li_100 = NormalizeDouble(TC2GridSpacing + MathMax(li_0, 1) * TC2GridIncrement, 0); } else li_100 = NormalizeDouble(TC2GridSpacing + MathMax(li_0, 1) * TC2GridIncrement, 0); } } else li_100 = TC2GridSpacing; RefreshRates(); if (gi_676 == 1) { if (g_ord_open_price_700 - l_ask_16 >= li_100 * gd_536 || li_0 < 1 && ScanAllOrders() <= MaxOrderNumber && MarketInfo(Symbol(), MODE_SPREAD) <= SpreadLimit() && CheckTradingDays() && EntryPeriodFilter()) { l_ask_16 = MarketInfo(Symbol(), MODE_ASK); g_ord_open_price_700 = 0; if (gi_628 == 0) l_price_24 = 0; else l_price_24 = l_ask_16 - MathAbs(gi_628) * gd_536; if (gi_620 == 0) l_price_32 = 0; else l_price_32 = l_ask_16 + MathAbs(gi_620) * gd_536; if (li_0 != 0) { ld_8 = BuyAutoLotSize(TC2BuyLotSize, TC2BuyStakePercent); for (l_pos_104 = 1; l_pos_104 <= li_0; l_pos_104++) { ld_8 = NormalizeDouble(ld_8 * (TC2BuyMultiplier - (li_0 + 1) * AntiProgressionPercent / 100.0), li_4); ld_8 = MathMax(ld_8, MarketInfo(Symbol(), MODE_MINLOT)); } } else ld_8 = BuyAutoLotSize(TC2BuyLotSize, TC2BuyStakePercent); if (ld_8 <= g_maxlot_644) { RefreshRates(); OrderSend(Symbol(), OP_BUY, NormalizeDouble(ld_8, li_4), l_ask_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_740, 0, l_color_48); } else { if (ld_8 > g_maxlot_644) { RefreshRates(); OrderSend(Symbol(), OP_BUY, NormalizeDouble((ld_8 / g_maxlot_644 - MathFloor(ld_8 / g_maxlot_644)) * g_maxlot_644, li_4), l_ask_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_740, 0, l_color_48); for (int l_count_112 = 0; l_count_112 < MathFloor(ld_8 / g_maxlot_644); l_count_112++) { RefreshRates(); OrderSend(Symbol(), OP_BUY, g_maxlot_644, l_ask_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_756, 0, l_color_48); } } } } } return (0); } int TC2Sell() { int li_4; double ld_8; double l_price_24; double l_price_32; color l_color_48; double l_ima_52; double ld_60; double ld_68; double l_ima_76; double ld_84; double ld_92; double ld_100; int li_0 = 0; if (DisplayArrows) l_color_48 = Maroon; else l_color_48 = CLR_NONE; Volatility_Screen(l_ima_52, ld_60, ld_68, l_ima_76, ld_84, ld_92); string l_comment_40 = TabID; if (g_maxlot_644 == 0.0) g_maxlot_644 = MarketInfo(Symbol(), MODE_MAXLOT); if (g_lotstep_652 == 0.0) g_lotstep_652 = MarketInfo(Symbol(), MODE_LOTSTEP); if (g_lotstep_652 == 0.001) li_4 = 3; if (g_lotstep_652 == 0.01) li_4 = 2; if (g_lotstep_652 == 0.1) li_4 = 1; double l_bid_16 = GetPrice(2, 0, 0); for (int l_pos_108 = 0; l_pos_108 < OrdersTotal(); l_pos_108++) { OrderSelect(l_pos_108, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_744 && OrderSymbol() == Symbol() && OrderComment() == TabID) li_0++; } if (g_ord_open_price_708 == 0.0) { for (l_pos_108 = 0; l_pos_108 < OrdersTotal(); l_pos_108++) { OrderSelect(l_pos_108, SELECT_BY_POS, MODE_TRADES); g_cmd_728 = OrderType(); if (OrderMagicNumber() == g_magic_744 && OrderSymbol() == Symbol() && OrderComment() == TabID) { g_ord_open_price_708 = OrderOpenPrice(); if (g_cmd_728 == OP_SELL) gi_680 = 2; } } } if (li_0 < 1) { gi_680 = 3; if (SecondTradeCycle == TRUE) gi_680 = 2; } if (li_0 != 0) { ld_100 = TC2GridSpacing; for (int li_112 = 1; li_112 <= li_0; li_112++) { if (VolatilityScreen) { if (ld_84 >= ld_60 || ld_92 <= ld_68) ld_100 = NormalizeDouble(VolatilityMultiplier * (TC2GridSpacing + MathMax(li_0, 1) * TC2GridIncrement), 0); else ld_100 = NormalizeDouble(TC2GridSpacing + MathMax(li_0, 1) * TC2GridIncrement, 0); } else ld_100 = NormalizeDouble(TC2GridSpacing + MathMax(li_0, 1) * TC2GridIncrement, 0); } } else ld_100 = TC2GridSpacing; RefreshRates(); if (gi_680 == 2) { if (g_ord_open_price_708 - l_bid_16 >= ld_100 * gd_536 || li_0 < 1 && ScanAllOrders() <= MaxOrderNumber && MarketInfo(Symbol(), MODE_SPREAD) <= SpreadLimit() && CheckTradingDays() && EntryPeriodFilter()) { l_bid_16 = MarketInfo(Symbol(), MODE_BID); g_ord_open_price_708 = 0; if (gi_632 == 0) l_price_24 = 0; else l_price_24 = l_bid_16 + MathAbs(gi_632) * gd_536; if (gi_624 == 0) l_price_32 = 0; else l_price_32 = l_bid_16 - MathAbs(gi_624) * gd_536; if (li_0 != 0) { ld_8 = SellAutoLotSize(TC2SellLotSize, TC2SellStakePercent); for (l_pos_108 = 1; l_pos_108 <= li_0; l_pos_108++) { ld_8 = NormalizeDouble(ld_8 * (TC2SellMultiplier - (li_0 + 1) * AntiProgressionPercent / 100.0), li_4); ld_8 = MathMax(ld_8, MarketInfo(Symbol(), MODE_MINLOT)); } } else ld_8 = SellAutoLotSize(TC2SellLotSize, TC2SellStakePercent); if (ld_8 <= g_maxlot_644) { RefreshRates(); OrderSend(Symbol(), OP_SELL, NormalizeDouble(ld_8, li_4), l_bid_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_744, 0, l_color_48); } else { if (ld_8 > g_maxlot_644) { RefreshRates(); OrderSend(Symbol(), OP_SELL, NormalizeDouble((ld_8 / g_maxlot_644 - MathFloor(ld_8 / g_maxlot_644)) * g_maxlot_644, li_4), l_bid_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_744, 0, l_color_48); for (int l_count_116 = 0; l_count_116 < MathFloor(ld_8 / g_maxlot_644); l_count_116++) { RefreshRates(); OrderSend(Symbol(), OP_SELL, g_maxlot_644, l_bid_16, Slippage, l_price_24, l_price_32, l_comment_40, g_magic_760, 0, l_color_48); } } } } } return (0); } int EntryPeriodFilter() { if (EntryPeriodTimeFrame == "m1" || EntryPeriodTimeFrame == "M1") { if (Minute() == 0 || Minute() == 2 || Minute() == 3 || Minute() == 4 || Minute() == 5 || Minute() == 6 || Minute() == 7 || Minute() == 8 || Minute() == 9 || Minute() == 10 || Minute() == 11 || Minute() == 12 || Minute() == 13 || Minute() == 14 || Minute() == 15 || Minute() == 16 || Minute() == 17 || Minute() == 18 || Minute() == 19 || Minute() == 20 || Minute() == 21 || Minute() == 22 || Minute() == 23 || Minute() == 24 || Minute() == 25 || Minute() == 26 || Minute() == 27 || Minute() == 28 || Minute() == 29 || Minute() == 30 || Minute() == 31 || Minute() == 32 || Minute() == 33 || Minute() == 34 || Minute() == 35 || Minute() == 36 || Minute() == 37 || Minute() == 36 || Minute() == 39 || Minute() == 40 || Minute() == 41 || Minute() == 42 || Minute() == 43 || Minute() == 44 || Minute() == 45 || Minute() == 46 || Minute() == 47 || Minute() == 48 || Minute() == 49 || Minute() == 50 || Minute() == 51 || Minute() == 52 || Minute() == 53 || Minute() == 54 || Minute() == 55 || Minute() == 56 || Minute() == 57 || Minute() == 58 || Minute() == 59) return (1); } if (EntryPeriodTimeFrame == "m5" || EntryPeriodTimeFrame == "M5") { if (!(Minute() == 0 || Minute() == 5 || Minute() == 10 || Minute() == 15 || Minute() == 20 || Minute() == 25 || Minute() == 30 || Minute() == 35 || Minute() == 40 || Minute() == 45 || Minute() == 50 || Minute() == 55)) return (0); return (1); } if (EntryPeriodTimeFrame == "m15" || EntryPeriodTimeFrame == "M15") { if (!(Minute() == 0 || Minute() == 15 || Minute() == 30 || Minute() == 45)) return (0); return (1); } if (EntryPeriodTimeFrame == "m30" || EntryPeriodTimeFrame == "M30") { if (!(Minute() == 0 || Minute() == 30)) return (0); return (1); } if (EntryPeriodTimeFrame == "h1" || EntryPeriodTimeFrame == "H1") { if (Minute() != 0) return (0); return (1); } if (EntryPeriodTimeFrame == "h4" || EntryPeriodTimeFrame == "H4") { if (!(Hour() == 0 || Hour() == 4 || Hour() == 8 || Hour() == 12 || Hour() == 16 || Hour() == 20 && Minute() == 0)) return (0); return (1); } if (EntryPeriodTimeFrame == "d1" || EntryPeriodTimeFrame == "D1") { if (!(Hour() == 0 && Minute() == 0)) return (0); return (1); } if (Minute() == 0 || Minute() == 15 || Minute() == 30 || Minute() == 45) return (1); return (0); } int ExitPeriodFilter() { if (ExitPeriodTimeFrame == "m1" || ExitPeriodTimeFrame == "M1") { if (Minute() == 0 || Minute() == 2 || Minute() == 3 || Minute() == 4 || Minute() == 5 || Minute() == 6 || Minute() == 7 || Minute() == 8 || Minute() == 9 || Minute() == 10 || Minute() == 11 || Minute() == 12 || Minute() == 13 || Minute() == 14 || Minute() == 15 || Minute() == 16 || Minute() == 17 || Minute() == 18 || Minute() == 19 || Minute() == 20 || Minute() == 21 || Minute() == 22 || Minute() == 23 || Minute() == 24 || Minute() == 25 || Minute() == 26 || Minute() == 27 || Minute() == 28 || Minute() == 29 || Minute() == 30 || Minute() == 31 || Minute() == 32 || Minute() == 33 || Minute() == 34 || Minute() == 35 || Minute() == 36 || Minute() == 37 || Minute() == 36 || Minute() == 39 || Minute() == 40 || Minute() == 41 || Minute() == 42 || Minute() == 43 || Minute() == 44 || Minute() == 45 || Minute() == 46 || Minute() == 47 || Minute() == 48 || Minute() == 49 || Minute() == 50 || Minute() == 51 || Minute() == 52 || Minute() == 53 || Minute() == 54 || Minute() == 55 || Minute() == 56 || Minute() == 57 || Minute() == 58 || Minute() == 59) return (1); } if (ExitPeriodTimeFrame == "m5" || ExitPeriodTimeFrame == "M5") { if (!(Minute() == 0 || Minute() == 5 || Minute() == 10 || Minute() == 15 || Minute() == 20 || Minute() == 25 || Minute() == 30 || Minute() == 35 || Minute() == 40 || Minute() == 45 || Minute() == 50 || Minute() == 55)) return (0); return (1); } if (ExitPeriodTimeFrame == "m15" || ExitPeriodTimeFrame == "M15") { if (!(Minute() == 0 || Minute() == 15 || Minute() == 30 || Minute() == 45)) return (0); return (1); } if (ExitPeriodTimeFrame == "m30" || ExitPeriodTimeFrame == "M30") { if (!(Minute() == 0 || Minute() == 30)) return (0); return (1); } if (ExitPeriodTimeFrame == "h1" || ExitPeriodTimeFrame == "H1") { if (Minute() != 0) return (0); return (1); } if (ExitPeriodTimeFrame == "h4" || ExitPeriodTimeFrame == "H4") { if (!(Hour() == 0 || Hour() == 4 || Hour() == 8 || Hour() == 12 || Hour() == 16 || Hour() == 20 && Minute() == 0)) return (0); return (1); } if (ExitPeriodTimeFrame == "d1" || ExitPeriodTimeFrame == "D1") { if (!(Hour() == 0 && Minute() == 0)) return (0); return (1); } if (Minute() == 0 || Minute() == 15 || Minute() == 30 || Minute() == 45) return (1); return (0); } int txt2tf(string as_0) { if (as_0 == "m1" || as_0 == "M1") return (1); if (as_0 == "m5" || as_0 == "M5") return (5); if (as_0 == "m15" || as_0 == "M15") return (15); if (as_0 == "m30" || as_0 == "M30") return (30); if (as_0 == "h1" || as_0 == "H1") return (60); if (as_0 == "h4" || as_0 == "H4") return (240); if (as_0 == "d1" || as_0 == "D1") return (1440); if (as_0 == "w1" || as_0 == "W1") return (10080); if (as_0 == "mn" || as_0 == "MN" || as_0 == "mN" || as_0 == "Mn") return (43200); return (0); } double ActivePerformance() { double ld_ret_0; if (ActiveIsolation) { if (ScanLastAccountBalance() == 0.0) ld_ret_0 = NormalizeDouble(100.0 * ((ScanTC1CycleProfit() + ScanTC2CycleProfit()) / (gd_768 + EquityFacility)), 2); else ld_ret_0 = NormalizeDouble(100.0 * ((ScanTC1CycleProfit() + ScanTC2CycleProfit()) / (ScanLastAccountBalance() + EquityFacility)), 2); } else ld_ret_0 = NormalizeDouble(100.0 * ((ScanTC1CycleProfit() + ScanTC2CycleProfit()) / (AccountBalance() + EquityFacility)), 2); return (ld_ret_0); } double MaxAccountBalance() { if (AccountBalance() > gd_776) gd_776 = AccountBalance(); return (gd_776); } double ScanLastAccountBalance() { double ld_ret_4; int l_file_0 = FileOpen("HH" + AccountNumber() + Symbol() + TabID + ".csv", FILE_CSV); if (l_file_0 > 0) { ld_ret_4 = FileReadNumber(l_file_0); FileClose(l_file_0); } return (ld_ret_4); } void ResetAccountBalance() { g_spread_544 = FALSE; gd_548 = 0; gd_556 = 0; gd_564 = 0; gd_776 = AccountBalance(); gd_768 = AccountBalance(); gd_unused_572 = 0; gd_unused_580 = 0; gd_unused_588 = 0; gd_unused_596 = 0; g_file_764 = FileOpen("HH" + Symbol() + AccountNumber() + ".csv", FILE_CSV|FILE_WRITE, ";"); if (g_file_764 > 0) { FileWrite(g_file_764, AccountBalance()); FileClose(g_file_764); } } int ScanOrderOpenTime() { double l_datetime_0; for (int l_pos_8 = 0; l_pos_8 <= OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_732 || OrderMagicNumber() == g_magic_748 || OrderMagicNumber() == g_magic_736 || OrderMagicNumber() == g_magic_752 || OrderMagicNumber() == g_magic_740 || OrderMagicNumber() == g_magic_756 || OrderMagicNumber() == g_magic_744 || OrderMagicNumber() == g_magic_760 && OrderSymbol() == Symbol() && OrderType() == OP_BUY || OrderType() == OP_SELL && OrderComment() == TabID) l_datetime_0 = OrderOpenTime(); } return (l_datetime_0); } void ManualShutDownMail() { SendMail("Hedge Hulk" + " Manual Shut", "Your system has been manually shutdown." + "\n" + "Date: " + Year() + "." + Month() + "." + Day() + "\n" + "Time: " + CurrentTime() + "\n" + "Account Number: " + DoubleToStr(AccountNumber(), 0) + "\n" + "Instrument: " + Symbol()); }