Skip to content

Commit

Permalink
m07 candidate.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkirs committed Aug 22, 2016
1 parent d77b77f commit 3b43ad8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Milky way EA v3.24.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#property version "3.24"
//#property strict

string ExpertName = "Milky way EA v3.24 m06"; // modification 6
string ExpertName = "Milky way EA v3.24 m07cand"; // modification 7 Candidate

extern string Settings01 = "====Настройки входа====";
extern int BBPeriod = 20; // Период Bollinger Bands
Expand Down Expand Up @@ -610,9 +610,10 @@ void CloseOrd()
}
}

//+--------------------------------------------------------------------------------------------+
//| Расчет максимального риска в процентах для ВСЕХ позиций на счете, имеющих уровень StopLoss |
//+--------------------------------------------------------------------------------------------+
//+---------------------------------------------------------------------------------------------------------+
//| Расчет максимального риска в процентах для ВСЕХ уже открытых позиций на счете, имеющих уровень StopLoss +
//| Отложенные ордера не учитываются +
//+---------------------------------------------------------------------------------------------------------+
bool AllRisk()
{
double currRiskInPercent = 0;
Expand All @@ -621,16 +622,23 @@ bool AllRisk()
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderStopLoss() == 0) continue;

double currSymbolPoint = MarketInfo(OrderSymbol(), MODE_POINT);
if (currSymbolPoint == 0)
{
EAComment("Error getting `Point` value for symbol " + OrderSymbol() + " in AllRisk() calculation | Skipping MaxRisk check");
return(true);
}

double distanceInPoints = 0;
if (OrderType() == OP_SELL && OrderOpenPrice() < OrderStopLoss())
{
distanceInPoints = (OrderStopLoss() - OrderOpenPrice()) / Point;
distanceInPoints = (OrderStopLoss() - OrderOpenPrice()) / currSymbolPoint;
currRiskInPercent = currRiskInPercent + (distanceInPoints * OrderLots() / AccountBalance()) * 100;
}
if (OrderType() == OP_BUY && OrderOpenPrice() > OrderStopLoss())
{
distanceInPoints = (OrderOpenPrice() - OrderStopLoss()) / Point;
distanceInPoints = (OrderOpenPrice() - OrderStopLoss()) / currSymbolPoint;
currRiskInPercent = currRiskInPercent + (distanceInPoints * OrderLots() / AccountBalance()) * 100;
}
}
Expand Down

0 comments on commit 3b43ad8

Please sign in to comment.