Skip to content

Commit 21ecbb3

Browse files
author
EarnForex
authored
1.13
1. Fixed a bug that prevented the timer's time type from saving and loading correctly. 2. Fixed a potential array out range error that could arise in some situations. 3. Fixed a potential division by zero error that could arise in some very rare circumstances.
1 parent 82624e1 commit 21ecbb3

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

MQL4/Experts/Account Protector/Account Protector.mq4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//+------------------------------------------------------------------+
66
#property copyright "EarnForex.com"
77
#property link "https://www.earnforex.com/metatrader-expert-advisors/Account-Protector/"
8-
#property version "1.121"
9-
string Version = "1.121";
8+
#property version "1.13"
9+
string Version = "1.13";
1010
#property strict
1111

1212
#property description "Protects account balance by applying given actions when set conditions trigger."

MQL4/Experts/Account Protector/Account Protector.mqh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,7 +3330,7 @@ bool CAccountProtector::SaveSettingsOnDisk()
33303330
FileWrite(fh, sets.Timer);
33313331
FileWrite(fh, "TimeLeft");
33323332
FileWrite(fh, sets.TimeLeft);
3333-
FileWrite(fh, "TimeType");
3333+
FileWrite(fh, "intTimeType");
33343334
FileWrite(fh, IntegerToString(sets.intTimeType));
33353335
FileWrite(fh, "dtTimerLastTriggerTime");
33363336
FileWrite(fh, IntegerToString(sets.dtTimerLastTriggerTime));
@@ -5097,7 +5097,7 @@ void CAccountProtector::Logging_Current_Settings()
50975097
// Condition-side values are calculated with P/L filter on. Action-side position array is set up without P/L filtering.
50985098
void CAccountProtector::Logging_Condition_Is_Met()
50995099
{
5100-
int i, market = 0, pending = 0;
5100+
int i, market = 0, pending = 0, market_pl = 0;
51015101
double floating_profit = 0;
51025102
ClosedVolume = 0;
51035103
TotalVolume = 0;
@@ -5124,10 +5124,11 @@ void CAccountProtector::Logging_Condition_Is_Met()
51245124
floating_profit += order_floating_profit;
51255125
market++;
51265126
}
5127-
ArrayResize(PositionsByProfit, market, 100); // Reserve extra physical memory to increase the resizing speed.
5128-
if ((CloseFirst != ENUM_CLOSE_TRADES_MOST_DISTANT_FIRST) && (CloseFirst != ENUM_CLOSE_TRADES_NEAREST_FIRST)) PositionsByProfit[market - 1][0] = order_floating_profit; // Normal profit.
5129-
else PositionsByProfit[market - 1][0] = MathAbs(OrderOpenPrice() - OrderClosePrice()) / SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT);
5130-
PositionsByProfit[market - 1][1] = OrderTicket();
5127+
market_pl++;
5128+
ArrayResize(PositionsByProfit, market_pl, 100); // Reserve extra physical memory to increase the resizing speed.
5129+
if ((CloseFirst != ENUM_CLOSE_TRADES_MOST_DISTANT_FIRST) && (CloseFirst != ENUM_CLOSE_TRADES_NEAREST_FIRST)) PositionsByProfit[market_pl - 1][0] = order_floating_profit; // Normal profit.
5130+
else if (SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT) != 0) PositionsByProfit[market_pl - 1][0] = MathAbs(OrderOpenPrice() - OrderClosePrice()) / SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT);
5131+
PositionsByProfit[market_pl - 1][1] = OrderTicket();
51315132
TotalVolume += OrderLots(); // Used to close trades, so no need to filter by P/L.
51325133
}
51335134
else if ((OrderType() == OP_BUYSTOP) || (OrderType() == OP_SELLSTOP) || (OrderType() == OP_BUYLIMIT) || (OrderType() == OP_SELLLIMIT)) pending++;

MQL5/Experts/Account Protector/Account Protector.mq5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//+------------------------------------------------------------------+
66
#property copyright "EarnForex.com"
77
#property link "https://www.earnforex.com/metatrader-expert-advisors/Account-Protector/"
8-
#property version "1.121"
9-
string Version = "1.121";
8+
#property version "1.13"
9+
string Version = "1.13";
1010
#property strict
1111

1212
#property description "Protects account balance by applying given actions when set conditions trigger."

MQL5/Experts/Account Protector/Account Protector.mqh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,7 +3442,7 @@ bool CAccountProtector::SaveSettingsOnDisk()
34423442
FileWrite(fh, sets.Timer);
34433443
FileWrite(fh, "TimeLeft");
34443444
FileWrite(fh, sets.TimeLeft);
3445-
FileWrite(fh, "TimeType");
3445+
FileWrite(fh, "intTimeType");
34463446
FileWrite(fh, IntegerToString(sets.intTimeType));
34473447
FileWrite(fh, "dtTimerLastTriggerTime");
34483448
FileWrite(fh, IntegerToString(sets.dtTimerLastTriggerTime));
@@ -5272,7 +5272,7 @@ void CAccountProtector::Logging_Current_Settings()
52725272
// Logs pre-condition values into the .log file and record positions into array.
52735273
void CAccountProtector::Logging_Condition_Is_Met()
52745274
{
5275-
int i, market = 0, pending = 0;
5275+
int i, market = 0, pending = 0, market_pl = 0;
52765276
double floating_profit = 0;
52775277
ulong ticket;
52785278
ClosedVolume = 0;
@@ -5314,10 +5314,11 @@ void CAccountProtector::Logging_Condition_Is_Met()
53145314
floating_profit += position_floating_profit;
53155315
market++;
53165316
}
5317-
ArrayResize(PositionsByProfit, market, 100); // Reserve extra physical memory to increase the resizing speed.
5318-
if ((CloseFirst != ENUM_CLOSE_TRADES_MOST_DISTANT_FIRST) && (CloseFirst != ENUM_CLOSE_TRADES_NEAREST_FIRST)) PositionsByProfit[market - 1][0] = position_floating_profit; // Normal profit.
5319-
else if (SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_POINT) != 0) PositionsByProfit[market - 1][0] = MathAbs(PositionGetDouble(POSITION_PRICE_OPEN) - PositionGetDouble(POSITION_PRICE_CURRENT)) / SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_POINT);
5320-
PositionsByProfit[market - 1][1] = (double)ticket;
5317+
market_pl++;
5318+
ArrayResize(PositionsByProfit, market_pl, 100); // Reserve extra physical memory to increase the resizing speed.
5319+
if ((CloseFirst != ENUM_CLOSE_TRADES_MOST_DISTANT_FIRST) && (CloseFirst != ENUM_CLOSE_TRADES_NEAREST_FIRST)) PositionsByProfit[market_pl - 1][0] = position_floating_profit; // Normal profit.
5320+
else if (SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_POINT) != 0) PositionsByProfit[market_pl - 1][0] = MathAbs(PositionGetDouble(POSITION_PRICE_OPEN) - PositionGetDouble(POSITION_PRICE_CURRENT)) / SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_POINT);
5321+
PositionsByProfit[market_pl - 1][1] = (double)ticket;
53215322
TotalVolume += PositionGetDouble(POSITION_VOLUME); // Used to close trades, so no need to filter by P/L.
53225323
}
53235324
break; // Order already processed - no point to process this order with other magic numbers.

0 commit comments

Comments
 (0)