At the buttom of this post is a script for lotsize-calculation based on free margin. I would very much like to combine it with the attached ParabolicSAR-EA.
Anyone can do that?
It would be a GREAT help.
void BuyOrderRiskFixed2()
{
double profit = 0;
datetime lastCloseTime = 0;
int cnt = OrdersHistoryTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && lastCloseTime < OrderCloseTime())
{
lastCloseTime = OrderCloseTime();
profit = OrderProfit();
}
}
if (profit > 0)
{
CurrentBuyRisk4 = CurrentBuyRisk4 * RiskBuyMpOnProfit4 + RiskBuyChOnProfit4;
if (RiskResetOnProfit4)
CurrentBuyRisk4 = RiskPercent;
}
elseif (profit < 0)
{
CurrentBuyRisk4 = CurrentBuyRisk4 * RiskBuyMpOnLoss4 + RiskBuyChOnLoss4;
if (RiskResetOnLoss4) CurrentBuyRisk4 = RiskPercent;
}
if (CurrentBuyRisk4 > MaxBuyRisk4)
{
CurrentBuyRisk4 = MaxBuyRisk4;
}
double lotsize = MarketInfo(Symbol(),MODE_LOTSIZE) / 1;
double pipsize = 100 * 10;
double maxlots = AccountEquity() / 100 * CurrentBuyRisk4 / lotsize * pipsize;
if (StopLoss == 0) Print("OrderSend() error - stoploss can not be zero");
double lots = maxlots / StopLoss * 10;
// calculate lot size based on current riskdouble lotvalue = 0.001;
double minilot = MarketInfo(Symbol(), MODE_MINLOT);
int powerscount = 0;
while (minilot < 1)
{
minilot = minilot * MathPow(10, powerscount);
powerscount++;
}
lotvalue = NormalizeDouble(lots, powerscount - 1);
if (lotvalue < MarketInfo(Symbol(), MODE_MINLOT)) // make sure lot is not smaller than allowed value
{
lotvalue = MarketInfo(Symbol(), MODE_MINLOT);
}
if (lotvalue > MarketInfo(Symbol(), MODE_MAXLOT)) // make sure lot is not greater than allowed value
{
lotvalue = MarketInfo(Symbol(), MODE_MAXLOT);
}
double SL = Ask - StopLoss*PipValue*Point;
if (StopLoss == 0) SL = 0;
double TP = Ask + TakeProfit*PipValue*Point;
if (TakeProfit == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_BUY, lotvalue, Ask, Slippage, 0, 0, ExpertName, MagicNumber, 0, Blue);
else
ticket = OrderSend(Symbol(), OP_BUY, lotvalue, Ask, Slippage, SL, TP, ExpertName, MagicNumber, 0, Blue);
if (ticket > -1)
{
if (true)
{
OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
fj4klkd8: I would very much like to combine it with the attached ParabolicSAR-EA.
Since there are no slaves here, there are only two choices: learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello
At the buttom of this post is a script for lotsize-calculation based on free margin. I would very much like to combine it with the attached ParabolicSAR-EA.
Anyone can do that?
It would be a GREAT help.
}