#include extern bool TradeShort = TRUE; extern bool TradeLong = TRUE; extern int OpenOnTick = 0; extern bool UseTMA = FALSE; extern int MAperiod = 240; extern bool UseARSI = TRUE; extern int RSI_period = 15; extern int RSI_bars = 14; extern double ARSI_trigger = 0.007; extern bool UseCCI = FALSE; extern int CCI_Period = 60; extern int CCI_lenght = 60; extern int cci_trigger = 25; extern bool Use_iTrend = FALSE; extern int iTrendPeriod = 60; extern bool ReverseDirection = TRUE; extern bool MoneyMangement = TRUE; extern bool MicroAccount = FALSE; extern double MaximumRisk = 0.5; extern double LotSize = 0.1; extern double LotIncrement = 0.1; extern double Multiplier = 0.0; extern double CounterTrendMultiplier = 0.0; extern int ProfitTarget = 1; extern double ProfitSkew = 1.0; extern int ProfitMode = 1; extern bool ProfitTrailing = TRUE; extern double MaxRetrace = 2.0; extern int ForcedStart = 0; extern double SL = 999.0; extern bool AutoSpacing = TRUE; extern int StDevTF = 15; extern int StDevPer = 14; extern int StDevMode = 0; extern int Spacing = 15; extern int TrendSpacing = 15; extern int CloseDelay = 91; extern bool CeaseTrading = FALSE; extern string PauseTrading = "Pause Trading at Timeinterval"; extern int StartTime = 0; extern int EndTime = 0; extern string QuitTrading = "Quit Trading at Time"; extern int endDayHourMinute = 0; extern bool RightSideLabel = FALSE; extern int SessionTarget = 10000; extern int MaximumBuyOrders = 5; extern int MaximumSellOrders = 200; extern string LossManagement = "What to do if things are going wrong"; extern string Warning = "This feature is in early stage and is not finished!"; extern bool AllowRecovery = FALSE; extern double MaxLossPercent = 320.0; extern bool ExitAllTrades = TRUE; extern bool StopTrading = TRUE; extern bool PlaceRecoveryOrders = TRUE; extern double MaxRecoveryOrders = 0.5; extern double RecoveryTakeProfit = 1100.0; extern double RecoveryStopLoss = 110.0; extern double RecoveryLotMultiplier = 1.0; extern bool RecReverse = FALSE; extern double nanpin = 40.0; extern double honsu = 5.0; double g_price_400 = 0.0; int g_error_408 = 0/* NO_ERROR */; int g_pos_412 = 0; int g_slippage_416 = 0; int g_magic_420 = 0; string g_str_concat_424; double g_close_432 = 0.0; int gi_440 = 0; int gi_444 = 0; double gd_448 = 0.0; bool gi_456 = FALSE; string g_str_concat_460; double gd_468; int gi_476; int gi_unused_480 = 100; bool gi_484 = TRUE; double gd_488 = 10000000.0; double gd_496 = 10000000.0; int init() { if (Symbol() == "AUDCADm" || Symbol() == "AUDCAD") g_magic_420 = 801001; if (Symbol() == "AUDJPYm" || Symbol() == "AUDJPY") g_magic_420 = 801002; if (Symbol() == "AUDNZDm" || Symbol() == "AUDNZD") g_magic_420 = 801003; if (Symbol() == "AUDUSDm" || Symbol() == "AUDUSD") g_magic_420 = 801004; if (Symbol() == "CHFJPYm" || Symbol() == "CHFJPY") g_magic_420 = 801005; if (Symbol() == "EURAUDm" || Symbol() == "EURAUD") g_magic_420 = 801006; if (Symbol() == "EURCADm" || Symbol() == "EURCAD") g_magic_420 = 801007; if (Symbol() == "EURCHFm" || Symbol() == "EURCHF") g_magic_420 = 801008; if (Symbol() == "EURGBPm" || Symbol() == "EURGBP") g_magic_420 = 801009; if (Symbol() == "EURJPYm" || Symbol() == "EURJPY") g_magic_420 = 801010; if (Symbol() == "EURUSDm" || Symbol() == "EURUSD") g_magic_420 = 801011; if (Symbol() == "GBPCHFm" || Symbol() == "GBPCHF") g_magic_420 = 801012; if (Symbol() == "GBPJPYm" || Symbol() == "GBPJPY") g_magic_420 = 801013; if (Symbol() == "GBPUSDm" || Symbol() == "GBPUSD") g_magic_420 = 801014; if (Symbol() == "NZDJPYm" || Symbol() == "NZDJPY") g_magic_420 = 801015; if (Symbol() == "NZDUSDm" || Symbol() == "NZDUSD") g_magic_420 = 801016; if (Symbol() == "USDCHFm" || Symbol() == "USDCHF") g_magic_420 = 801017; if (Symbol() == "USDJPYm" || Symbol() == "USDJPY") g_magic_420 = 801018; if (Symbol() == "USDCADm" || Symbol() == "USDCAD") g_magic_420 = 801019; if (g_magic_420 == 0) g_magic_420 = 801999; gd_468 = AccountBalance(); g_str_concat_424 = StringConcatenate(Symbol(), " ", Period(), " ", "PM", " S_ID: ", TimeLocal()); g_str_concat_460 = StringConcatenate("PipMaker_v10_", Symbol(), "_", Period(), "_M", ".txt"); CalculateLotPrecision(); return (0); } int deinit() { if (ObjectFind("MidPoint") == 0) ObjectDelete("MidPoint"); if (ObjectFind("MarginPercent") == 0) ObjectDelete("MarginPercent"); if (ObjectFind("LowMarginPercent") == 0) ObjectDelete("LowMarginPercent"); Comment(""); return (0); } void CalculateLotPrecision() { double l_lotstep_0 = MarketInfo(Symbol(), MODE_LOTSTEP); l_lotstep_0 = 0.1; if (l_lotstep_0 == 1.0) gi_476 = 0; if (l_lotstep_0 == 0.1) gi_476 = 1; if (l_lotstep_0 == 0.01) gi_476 = 2; if (l_lotstep_0 == 0.001) gi_476 = 3; gi_476 = 1; } double AutoLot() { double ld_0 = NormalizeDouble(AccountBalance() / 1000000.0, gi_476) * MaximumRisk; if (MicroAccount) ld_0 = NormalizeDouble(ld_0 / 1000.0, gi_476); if (ld_0 < 0.1) ld_0 = 0.1; return (0.1); } int RecoveryOrders() { int l_count_0 = 0; for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) { OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_420 * 2 && OrderComment() == "Rec" && OrderSymbol() == Symbol()) l_count_0++; } return (l_count_0); } void PlaceBuyOrder() { double ld_0; double l_lots_8; double l_ord_open_price_24; double l_ord_open_price_16 = 1000; if (MoneyMangement) { LotSize = AutoLot(); if (LotIncrement > 0.0) LotIncrement = LotSize; } g_close_432 = 0; RefreshRates(); for (g_pos_412 = OrdersTotal() - 1; g_pos_412 >= 0; g_pos_412--) { if (OrderSelect(g_pos_412, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420 && OrderType() == OP_BUY) { if (OrderOpenPrice() < l_ord_open_price_16) l_ord_open_price_16 = OrderOpenPrice(); if (OrderOpenPrice() > l_ord_open_price_24) l_ord_open_price_24 = OrderOpenPrice(); ld_0++; } } } ld_0 = 0; if (Ask >= l_ord_open_price_24 + TrendSpacing * Point) { if (Multiplier == 1.0) l_lots_8 = NormalizeDouble(MathPow(2, ld_0) * LotSize, gi_476); else l_lots_8 = NormalizeDouble(LotSize + LotIncrement * ld_0, gi_476); } if (Ask <= l_ord_open_price_16 - Spacing * Point) { if (CounterTrendMultiplier == 1.0) l_lots_8 = NormalizeDouble(MathPow(2, ld_0) * LotSize, gi_476); else l_lots_8 = NormalizeDouble(LotSize + LotIncrement * ld_0, gi_476); } if (ld_0 == 0.0) l_lots_8 = NormalizeDouble(LotSize, gi_476); if (l_lots_8 == 0.0) { if (Multiplier == 1.0) l_lots_8 = NormalizeDouble(LotSize, gi_476); else l_lots_8 = NormalizeDouble(LotSize, gi_476); } if (IsTradeAllowed() == TRUE && ld_0 < MaximumBuyOrders) { if (SL == 0.0) g_price_400 = 0; else g_price_400 = Ask - SL * Point; OrderSend(Symbol(), OP_BUY, l_lots_8, Ask, g_slippage_416, g_price_400, 0, g_str_concat_424, g_magic_420, 16711680); } g_error_408 = GetLastError(); if (g_error_408 != 0/* NO_ERROR */) { Write("Error opening BUY order: " + ErrorDescription(g_error_408) + " (C" + g_error_408 + ") Ask:" + Ask + " Slippage:" + g_slippage_416); return; } g_close_432 = Close[0]; } void PlaceSellOrder() { double ld_0; double l_lots_8; double l_ord_open_price_16; double l_ord_open_price_24 = 1000; if (MoneyMangement) { LotSize = AutoLot(); if (LotIncrement > 0.0) LotIncrement = LotSize; } g_close_432 = 0; RefreshRates(); for (g_pos_412 = OrdersTotal() - 1; g_pos_412 >= 0; g_pos_412--) { if (OrderSelect(g_pos_412, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420 && OrderType() == OP_SELL) { if (OrderOpenPrice() > l_ord_open_price_16) l_ord_open_price_16 = OrderOpenPrice(); if (OrderOpenPrice() < l_ord_open_price_24) l_ord_open_price_24 = OrderOpenPrice(); ld_0++; } } } ld_0 = 0; if (Bid <= l_ord_open_price_24 - TrendSpacing * Point) { if (Multiplier == 1.0) l_lots_8 = NormalizeDouble(MathPow(2, ld_0) * LotSize, gi_476); else l_lots_8 = NormalizeDouble(LotSize + LotIncrement * ld_0, gi_476); } if (Bid >= l_ord_open_price_16 + Spacing * Point) { if (CounterTrendMultiplier == 1.0) l_lots_8 = NormalizeDouble(MathPow(2, ld_0) * LotSize, gi_476); else l_lots_8 = NormalizeDouble(LotSize + LotIncrement * ld_0, gi_476); } if (ld_0 == 0.0) l_lots_8 = NormalizeDouble(LotSize, gi_476); if (l_lots_8 == 0.0) { if (Multiplier == 1.0) l_lots_8 = NormalizeDouble(LotSize, gi_476); else l_lots_8 = NormalizeDouble(LotSize, gi_476); } if (IsTradeAllowed() == TRUE && ld_0 < MaximumSellOrders) { if (SL == 0.0) g_price_400 = 0; else g_price_400 = Bid + SL * Point; OrderSend(Symbol(), OP_SELL, l_lots_8, Bid, g_slippage_416, g_price_400, 0, g_str_concat_424, g_magic_420, 255); } g_error_408 = GetLastError(); if (g_error_408 != 0/* NO_ERROR */) { Write("Error opening SELL order: " + ErrorDescription(g_error_408) + " (D" + g_error_408 + ") Bid:" + Bid + " Slippage:" + g_slippage_416); return; } g_close_432 = Close[0]; } void CloseAllBuyProfit() { bool l_ord_close_8; int li_unused_0 = MarketInfo(Symbol(), MODE_SPREAD); for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) { OrderSelect(l_pos_4, SELECT_BY_POS); l_ord_close_8 = FALSE; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420 && OrderType() == OP_BUY) if (TimeCurrent() - OrderOpenTime() >= CloseDelay) l_ord_close_8 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0, Aqua); } } void CloseAllSellProfit() { bool l_ord_close_8; int li_unused_0 = MarketInfo(Symbol(), MODE_SPREAD); for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) { OrderSelect(l_pos_4, SELECT_BY_POS); l_ord_close_8 = FALSE; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420 && OrderType() == OP_SELL) if (TimeCurrent() - OrderOpenTime() >= CloseDelay) l_ord_close_8 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 0, Lime); } } int start() { double ld_0; int li_24; int li_28; double ld_48; double ld_56; double l_ord_open_price_96; double l_ord_open_price_112; int l_ticket_160; int l_ticket_164; int l_ticket_168; int l_ticket_172; double ld_176; double ld_184; double ld_192; double ld_200; int li_268; double ld_272; double ld_280; double ld_288; double l_lots_296; double ld_304; double ld_312; double l_lots_320; double ld_328; int l_count_336; string l_dbl2str_340; string l_dbl2str_348; string l_dbl2str_356; double l_ord_open_price_64 = 999; double l_ord_open_price_72 = 0.0001; double l_ord_open_price_80 = 999; double l_ord_open_price_88 = 0.0001; double ld_120 = 0; double ld_128 = 0; double ld_136 = 0; double ld_144 = 0; double ld_152 = 0; bool li_208 = FALSE; bool li_212 = FALSE; double l_marginrequired_216 = MarketInfo(Symbol(), MODE_MARGINREQUIRED); double ld_unused_232 = 0; for (g_pos_412 = OrdersTotal() - 1; g_pos_412 >= 0; g_pos_412--) { if (OrderSelect(g_pos_412, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420) { ld_120 = OrderProfit() + OrderSwap() + OrderCommission(); if (OrderType() == OP_BUY) { if (OrderOpenPrice() >= l_ord_open_price_72) { l_ord_open_price_72 = OrderOpenPrice(); l_ticket_160 = OrderTicket(); ld_176 = ld_120; } if (OrderOpenPrice() <= l_ord_open_price_64) { l_ord_open_price_64 = OrderOpenPrice(); l_ticket_164 = OrderTicket(); ld_184 = ld_120; } li_28++; if (li_28 > gi_440) gi_440 = li_28; ld_48 += OrderLots(); ld_128 += ld_120; if (ld_120 > 0.0) ld_144 += ld_120; } if (OrderType() == OP_SELL) { if (OrderOpenPrice() <= l_ord_open_price_80) { l_ord_open_price_80 = OrderOpenPrice(); l_ticket_172 = OrderTicket(); ld_200 = ld_120; } if (OrderOpenPrice() >= l_ord_open_price_88) { l_ord_open_price_88 = OrderOpenPrice(); l_ticket_168 = OrderTicket(); ld_192 = ld_120; } li_24++; if (li_24 > gi_444) gi_444 = li_24; ld_56 += OrderLots(); ld_136 += ld_120; if (ld_120 > 0.0) ld_152 += ld_120; } } } } if (l_ord_open_price_72 >= l_ord_open_price_88) l_ord_open_price_96 = l_ord_open_price_72; else l_ord_open_price_96 = l_ord_open_price_88; if (l_ord_open_price_64 <= l_ord_open_price_80) l_ord_open_price_112 = l_ord_open_price_64; else l_ord_open_price_112 = l_ord_open_price_80; double l_price_104 = (l_ord_open_price_96 + l_ord_open_price_112) / 2.0; RefreshRates(); if (MoneyMangement) ProfitTarget = 100.0 * AutoLot() * ProfitSkew; double ld_240 = ld_128 + ld_136; double ld_248 = li_28 + li_24; if (ld_240 > gd_448) gd_448 = ld_240; if (ld_248 == 0.0 || ld_240 <= 0.0) gd_448 = 0; if (ProfitTrailing) { ProfitMode = FALSE; if (ld_240 >= ProfitTarget && ld_240 <= gd_448 - gd_448 * MaxRetrace / 100.0) ExitAllTrades(Lime, "Max profit reached"); } if (ProfitMode == 1 || ProfitMode == 2 && ld_128 + ld_136 >= ProfitTarget) { for (g_pos_412 = OrdersTotal() - 1; g_pos_412 >= 0; g_pos_412--) { if (OrderSelect(g_pos_412, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), g_slippage_416, Red); g_error_408 = GetLastError(); if (g_error_408 != 0/* NO_ERROR */) Write("Error closing order " + OrderTicket() + ": " + ErrorDescription(g_error_408) + " (F" + g_error_408 + ") Lots:" + OrderLots() + " Ask:" + MarketInfo(OrderSymbol(), MODE_ASK)); } } } if (ProfitMode == 1 || ProfitMode == 3) { if (ld_128 >= ProfitTarget) CloseAllBuyProfit(); if (ld_136 >= ProfitTarget) CloseAllSellProfit(); } int li_256 = Direction(); if (ReverseDirection) li_256 = -li_256; bool li_260 = FALSE; bool li_264 = FALSE; if (AllowRecovery) { if (iMA(Symbol(), PERIOD_M5, 10, 0, MODE_SMA, PRICE_CLOSE, 0) < iMA(Symbol(), PERIOD_M5, 10, 1, MODE_SMA, PRICE_CLOSE, 1)) li_268 = -1; if (iMA(Symbol(), PERIOD_M5, 10, 0, MODE_SMA, PRICE_OPEN, 0) > iMA(Symbol(), PERIOD_M5, 10, 1, MODE_SMA, PRICE_OPEN, 1)) li_268 = 1; if (RecReverse) li_268 = -li_268; ld_272 = AccountBalance() / 10.0 * MaxLossPercent; Print(ld_272); if (ld_136 <= -ld_272) { li_264 = TRUE; li_260 = FALSE; if (ExitAllTrades) ExitAllTrades(Aqua, "Sell profit going under max allowed loss"); if (PlaceRecoveryOrders && RecoveryOrders() < MaxRecoveryOrders) { ld_280 = ld_136 - ProfitTarget; ld_288 = (-ld_280) / RecoveryTakeProfit; l_lots_296 = ld_288 / 10.0 * RecoveryLotMultiplier; if (l_lots_296 < 0.5) { if (li_268 == 1) OrderSend(Symbol(), OP_BUY, l_lots_296, Ask, g_slippage_416, Ask - RecoveryStopLoss * Point, Ask + RecoveryTakeProfit * Point, "Rec", g_magic_420 * 2, 0, Blue); if (li_268 == -1) OrderSend(Symbol(), OP_SELL, l_lots_296, Bid, g_slippage_416, Bid + RecoveryStopLoss * Point, Bid - RecoveryTakeProfit * Point, "Rec", g_magic_420 * 2, 0, Red); if (StopTrading) CeaseTrading = TRUE; } } } if (ld_128 <= -ld_272) { li_260 = TRUE; li_264 = FALSE; if (ExitAllTrades) ExitAllTrades(Aqua, "Buy profit going under max allowed loss"); if (PlaceRecoveryOrders && RecoveryOrders() < MaxRecoveryOrders) { ld_304 = ld_128 - ProfitTarget; ld_312 = (-ld_304) / RecoveryTakeProfit; l_lots_320 = ld_312 / 10.0 * RecoveryLotMultiplier; if (l_lots_296 < 0.5) { if (li_268 == -1) OrderSend(Symbol(), OP_SELL, l_lots_320, Bid, g_slippage_416, Bid + RecoveryStopLoss * Point, Bid - RecoveryTakeProfit * Point, "Rec", g_magic_420 * 2, 0, Red); if (li_268 == 1) OrderSend(Symbol(), OP_BUY, l_lots_320, Ask, g_slippage_416, Ask - RecoveryStopLoss * Point, Ask + RecoveryTakeProfit * Point, "Rec", g_magic_420 * 2, 0, Blue); if (StopTrading) CeaseTrading = TRUE; } } } } if (ForcedStart > 0 && li_28 + li_24 == 0) if (ForcedStart == 1 && li_256 == -1 || ForcedStart == 2 && li_256 == 1) gi_484 = FALSE; if (AutoSpacing == TRUE) { ld_328 = iStdDev(Symbol(), StDevTF, StDevPer, 0, StDevMode, PRICE_OPEN, 0) / Point; Spacing = ld_328; if (TrendSpacing != 1000) TrendSpacing = ld_328; else TrendSpacing = 1000; } if (gi_484) { l_count_336 = 0; for (g_pos_412 = OrdersTotal() - 1; g_pos_412 >= 0; g_pos_412--) { if (OrderSelect(g_pos_412, SELECT_BY_POS, MODE_TRADES)) if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420) l_count_336++; } if (l_count_336 == 0) { if (l_ord_open_price_72 > 0.0 && l_ord_open_price_64 < 1000.0) { if (Ask <= l_ord_open_price_64 - Spacing * Point || Ask >= l_ord_open_price_72 + TrendSpacing * Point) { li_212 = TRUE; if (OpenOnTick == 1 && g_close_432 > 0.0 && Close[0] < g_close_432) li_212 = TRUE; } if (li_256 != 1) li_212 = FALSE; if (CeaseTrading && li_28 == 0) li_212 = FALSE; if (li_260) li_212 = FALSE; if (PauseAtTime(StartTime, EndTime, 1) != 1) li_212 = FALSE; if (li_212 && TradeLong == TRUE) PlaceBuyOrder(); } if (l_ord_open_price_88 > 0.0 && l_ord_open_price_80 < 1000.0) { if (Bid >= l_ord_open_price_88 + Spacing * Point || Bid <= l_ord_open_price_80 - TrendSpacing * Point) { li_208 = TRUE; if (OpenOnTick == 1 && g_close_432 > 0.0 && Close[0] > g_close_432) li_208 = TRUE; } if (li_256 != -1) li_208 = FALSE; if (CeaseTrading && li_24 == 0) li_208 = FALSE; if (li_264) li_208 = FALSE; if (PauseAtTime(StartTime, EndTime, -1) != -1) li_208 = FALSE; if (li_208 && TradeShort == TRUE) PlaceSellOrder(); } } else { if (l_ord_open_price_72 > 0.0 && l_ord_open_price_64 < 1000.0 && ld_128 / (l_count_336 * 2 - 1) <= (-nanpin) && honsu > l_count_336) { if (Ask <= l_ord_open_price_64 - Spacing * Point || Ask >= l_ord_open_price_72 + TrendSpacing * Point) { li_212 = TRUE; if (OpenOnTick == 1 && g_close_432 > 0.0 && Close[0] < g_close_432) li_212 = TRUE; } if (li_256 != 1) li_212 = FALSE; if (CeaseTrading && li_28 == 0) li_212 = FALSE; if (li_260) li_212 = FALSE; if (PauseAtTime(StartTime, EndTime, 1) != 1) li_212 = FALSE; if (li_212 && TradeLong == TRUE) PlaceBuyOrder(); } if (l_ord_open_price_88 > 0.0 && l_ord_open_price_80 < 1000.0 && ld_136 / (l_count_336 * 2 - 1) <= (-nanpin) && honsu > l_count_336) { if (Bid >= l_ord_open_price_88 + Spacing * Point || Bid <= l_ord_open_price_80 - TrendSpacing * Point) { li_208 = TRUE; if (OpenOnTick == 1 && g_close_432 > 0.0 && Close[0] > g_close_432) li_208 = TRUE; } if (li_256 != -1) li_208 = FALSE; if (CeaseTrading && li_24 == 0) li_208 = FALSE; if (li_264) li_208 = FALSE; if (PauseAtTime(StartTime, EndTime, -1) != -1) li_208 = FALSE; if (li_208 && TradeShort == TRUE) PlaceSellOrder(); } } } if (AccountMargin() != 0.0) ld_0 = MathRound(100.0 * (AccountEquity() / AccountMargin())); if (gd_488 > ld_0) gd_488 = ld_0; if (AccountEquity() < gd_496) gd_496 = AccountEquity(); string ls_224 = " PipMakerV19-1" + "\n" + " ProfitTarget " + DoubleToStr(ProfitTarget, 2) + "\n" + " MaxProfit " + DoubleToStr(gd_448, 2) + "\n" + " Floating PL " + DoubleToStr(ld_240, 2) + "\n" + " Buys " + li_28 + " Highest: " + gi_440 + "\n" + " BuyLots " + DoubleToStr(ld_48, 2) + "\n" + " BuyProfit " + DoubleToStr(ld_128, 2) + "\n" + " Highest Buy " + DoubleToStr(l_ord_open_price_72, Digits) + " #" + DoubleToStr(l_ticket_160, 0) + " Profit: " + DoubleToStr(ld_176, 2) + "\n" + " Highest Sell " + DoubleToStr(l_ord_open_price_88, Digits) + " #" + DoubleToStr(l_ticket_168, 0) + " Profit: " + DoubleToStr(ld_192, 2) + "\n" + "\n" + " Sells " + li_24 + " Highest: " + gi_444 + "\n" + " SellLots " + DoubleToStr(ld_56, 2) + "\n" + " SellProfit " + DoubleToStr(ld_136, 2) + "\n" + " Lowest Buy " + DoubleToStr(l_ord_open_price_64, Digits) + " #" + DoubleToStr(l_ticket_164, 0) + " Profit: " + DoubleToStr(ld_184, 2) + "\n" + " Lowest Sell " + DoubleToStr(l_ord_open_price_80, Digits) + " #" + DoubleToStr(l_ticket_172, 0) + " Profit: " + DoubleToStr(ld_200, 2) + "\n" + "\n" + " Spacing " + Spacing + "\n" + " Trend Spacing " + TrendSpacing + "\n" + "\n" + " Balance " + DoubleToStr(AccountBalance(), 2) + "\n" + " Equity " + DoubleToStr(AccountEquity(), 2) + " Lowest: " + DoubleToStr(gd_496, 2) + "\n" + "\n" + " Margin " + DoubleToStr(AccountMargin(), 2) + "\n" + " MarginPercent " + DoubleToStr(ld_0, 2) + "\n" + " LowMarginPercent " + DoubleToStr(gd_488, 2) + "\n" + " Current Time is " + TimeToStr(TimeCurrent(), TIME_SECONDS); Comment(ls_224); if (RightSideLabel) { l_dbl2str_340 = DoubleToStr(ld_0, 0); l_dbl2str_348 = DoubleToStr(gd_488, 0); l_dbl2str_356 = DoubleToStr(AccountBalance(), 0); ObjectDelete("MarginPercent"); if (ObjectFind("MarginPercent") != 0) { ObjectCreate("MarginPercent", OBJ_TEXT, 0, Time[0], Close[0]); ObjectSetText("MarginPercent", l_dbl2str_340 + "% " + l_dbl2str_348 + "% $" + l_dbl2str_356, 10, "Arial Black", DodgerBlue); } else ObjectMove("MarginPercent", 0, Time[0], Close[0]); } if (ObjectFind("MidPoint") != 0) { ObjectCreate("MidPoint", OBJ_HLINE, 0, Time[0], l_price_104); ObjectSet("MidPoint", OBJPROP_COLOR, Gold); ObjectSet("MidPoint", OBJPROP_WIDTH, 2); } else ObjectMove("MidPoint", 0, Time[0], l_price_104); getSessionTarget(); QuitAtTime(endDayHourMinute); return (0); } void Write(string as_0) { int l_file_8; if (gi_456) { l_file_8 = FileOpen(g_str_concat_460, FILE_CSV|FILE_WRITE|FILE_READ, "/t"); if (l_file_8 < 1) Print("Error opening audit file: Code ", GetLastError()); else { if (!FileSeek(l_file_8, 0, SEEK_END)) Print("Error seeking end of audit file: Code ", GetLastError()); else { if (FileWrite(l_file_8, TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS) + " " + as_0) < 1) Print("Error writing to audit file: Code ", GetLastError()); else FileClose(l_file_8); } } } } int Direction() { int li_ret_0; if ((UseTMA && TMADecision() == 1) || !UseTMA && (UseCCI && CCIDecision() == 1) || !UseCCI && (UseARSI && ARSIDecision() == 1) || !UseARSI && (Use_iTrend && iTrendDecision() == 1) || !Use_iTrend) li_ret_0 = 1; if ((UseTMA && TMADecision() == -1) || !UseTMA && (UseCCI && CCIDecision() == -1) || !UseCCI && (UseARSI && ARSIDecision() == -1) || !UseARSI && (Use_iTrend && iTrendDecision() == -1) || !Use_iTrend) li_ret_0 = -1; if ((TMADecision() == 0 && CCIDecision() == 0 && iTrendDecision() == 0 && ARSIDecision() == 0) || (!UseTMA && !UseCCI && !Use_iTrend && !UseARSI)) li_ret_0 = 0; return (li_ret_0); } int TMADecision() { int li_ret_0; double l_ima_4; double l_ima_12; double l_ima_20; double l_ima_28; double l_ima_36; double l_ima_44; if (UseTMA == TRUE) { l_ima_4 = iMA(NULL, MAperiod, 3, 0, MODE_LWMA, PRICE_CLOSE, 0); l_ima_12 = iMA(NULL, MAperiod, 3, 0, MODE_LWMA, PRICE_CLOSE, 1); l_ima_20 = iMA(NULL, MAperiod, 20, 0, MODE_LWMA, PRICE_CLOSE, 0); l_ima_28 = iMA(NULL, MAperiod, 20, 0, MODE_LWMA, PRICE_CLOSE, 1); l_ima_36 = iMA(NULL, MAperiod, 50, 0, MODE_LWMA, PRICE_CLOSE, 0); l_ima_44 = iMA(NULL, MAperiod, 50, 0, MODE_LWMA, PRICE_CLOSE, 1); if (l_ima_36 < l_ima_44 && l_ima_20 < l_ima_28 && l_ima_4 < l_ima_12 && l_ima_4 < l_ima_20) li_ret_0 = -1; if (l_ima_36 > l_ima_44 && l_ima_20 > l_ima_28 && l_ima_4 > l_ima_12 && l_ima_4 > l_ima_20) li_ret_0 = 1; } else li_ret_0 = 0; return (li_ret_0); } int CCIDecision() { int li_ret_0; double l_icci_4; if (UseCCI == TRUE) { l_icci_4 = 0; l_icci_4 = iCCI(NULL, CCI_Period, CCI_lenght, PRICE_TYPICAL, 0); if (l_icci_4 < -cci_trigger) li_ret_0 = -1; if (l_icci_4 > cci_trigger) li_ret_0 = 1; } else li_ret_0 = 0; return (li_ret_0); } int ARSIDecision() { int li_ret_0; double ld_4; double ld_12; if (UseARSI == TRUE) { ld_4 = 10.0 * iCustom(NULL, RSI_period, "Adaptive RSI", RSI_bars, 0, 0); ld_12 = 10.0 * iCustom(NULL, RSI_period, "Adaptive RSI", RSI_bars, 0, 1); if (ld_4 > ld_12 && ld_4 - ld_12 > ARSI_trigger) li_ret_0 = 1; if (ld_4 < ld_12 && ld_12 - ld_4 > ARSI_trigger) li_ret_0 = -1; } else li_ret_0 = 0; return (li_ret_0); } int iTrendDecision() { int li_ret_0; double l_icustom_4; double l_icustom_12; double l_icustom_20; double l_icustom_28; double l_icustom_36; double l_icustom_44; double l_icustom_52; double l_icustom_60; if (Use_iTrend == TRUE) { l_icustom_4 = iCustom(NULL, iTrendPeriod, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 0, 0); l_icustom_12 = iCustom(NULL, iTrendPeriod, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 1, 0); l_icustom_20 = iCustom(NULL, iTrendPeriod, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 0, 0); l_icustom_28 = iCustom(NULL, iTrendPeriod, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 0, 1); l_icustom_36 = iCustom(NULL, iTrendPeriod, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 0, 0); l_icustom_44 = iCustom(NULL, iTrendPeriod, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 1, 0); l_icustom_52 = iCustom(NULL, iTrendPeriod, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 0, 0); l_icustom_60 = iCustom(NULL, iTrendPeriod, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 0, 1); if (l_icustom_4 > l_icustom_12 && l_icustom_20 > l_icustom_28) li_ret_0 = 1; if (l_icustom_36 < l_icustom_44 && l_icustom_52 < l_icustom_60) li_ret_0 = -1; } else li_ret_0 = 0; return (li_ret_0); } void QuitAtTime(int ai_0) { int li_4 = 10000 * TimeDay(TimeCurrent()) + 100 * TimeHour(TimeCurrent()) + TimeMinute(TimeCurrent()); if (li_4 >= ai_0 && ai_0 != 0) { CeaseTrading = TRUE; ExitAllTrades(Gold, "Stopped Trading because endtime reached!"); } } int PauseAtTime(int ai_0, int ai_4, int ai_8) { int li_ret_12; int li_16; if (ai_0 != 0 && ai_4 != 0) { li_16 = 10000 * TimeDay(TimeCurrent()) + 100 * TimeHour(TimeCurrent()) + TimeMinute(TimeCurrent()); if (li_16 >= ai_0 && li_16 <= ai_4) li_ret_12 = 0; else { if (ai_8 == 1) li_ret_12 = 1; if (ai_8 == -1) li_ret_12 = -1; } } else { if (ai_8 == 1) li_ret_12 = 1; if (ai_8 == -1) li_ret_12 = -1; } return (li_ret_12); } double SessionProfit() { double ld_0; double ld_8; for (int l_pos_24 = OrdersHistoryTotal() - 1; l_pos_24 >= 0; l_pos_24--) { OrderSelect(l_pos_24, SELECT_BY_POS, MODE_HISTORY); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420) if (OrderComment() == g_str_concat_424) ld_0 += OrderProfit(); } for (int l_pos_28 = OrdersTotal() - 1; l_pos_28 >= 0; l_pos_28--) { OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420) if (OrderComment() == g_str_concat_424) ld_8 += OrderProfit(); } double ld_ret_16 = ld_0 + ld_8; return (ld_ret_16); } void getSessionTarget() { if (SessionTarget > 0) { if (SessionProfit() >= SessionTarget) { CeaseTrading = TRUE; ExitAllTrades(Aqua, "Session Target Achieved. YUHUUI!"); } } } void ExitAllTrades(color a_color_0, string as_4) { int l_ord_close_12; for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) { OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_420) { l_ord_close_12 = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), g_slippage_416, a_color_0); if (l_ord_close_12 == 1) Print("Closed all positions because ", as_4); } } }