根据历史盈利情况,计算当前应该下的手数,使用马丁方法,一般适用于策略非常稳定的ea,偶尔亏损,可使用该手数计算方法。
double 净值恢复算法()
{
double HisProfit;
int pcs;
double MinHisProfit;
int MinHisProfitPOS;
double MaxHisProfit;
int MaxHisProfitPOS;
double 更远处最高盈利;
int 更高点;
double Heild_48 = 1;
if (martin > 0.0 && Siegd_148 > 0.0)
{
HisProfit = 0;
pcs = 0;
MinHisProfit = 0;
MinHisProfitPOS = 0;
MaxHisProfit = 0;
MaxHisProfitPOS = 0;
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
pcs++;
HisProfit += OrderProfit()+OrderSwap()+OrderCommission();
if (HisProfit > MaxHisProfit)
{
MaxHisProfit = HisProfit;
MaxHisProfitPOS = pcs;
}
if (HisProfit < MinHisProfit)
{
MinHisProfit = HisProfit;
MinHisProfitPOS = pcs;
}
if (pcs >= MaxBTBars) break;
}
}
}
if (MaxHisProfitPOS <= MinHisProfitPOS) Heild_48 = MathPow(martin, MinHisProfitPOS);
else //净值越来越低
{
HisProfit = MaxHisProfit;
pcs = MaxHisProfitPOS;
更远处最高盈利 = MaxHisProfit;
更高点 = MaxHisProfitPOS;
for (i = OrdersHistoryTotal() - MaxHisProfitPOS - 1; i >= 0; i--) //扫描更远处
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
if (pcs >= MaxBTBars) break;
pcs++;
HisProfit += OrderProfit()+OrderSwap()+OrderCommission();
if (HisProfit < 更远处最高盈利)
{
更远处最高盈利 = HisProfit;
更高点 = pcs;
}
}
}
}
if (更高点 == MaxHisProfitPOS || 更远处最高盈利 == MaxHisProfit) Heild_48 = MathPow(martin, MinHisProfitPOS);
else
{
if (MathAbs(MinHisProfit - MaxHisProfit) / MathAbs(更远处最高盈利 - MaxHisProfit) >= (净值回撤幅度 + 100.0) / 100.0)
Heild_48 = MathPow(martin, MinHisProfitPOS);
else Heild_48 = MathPow(martin, 更高点);
}
}
}
double 最后手数 = MathMax(minlot, MathMin(maxlot, MathCeil(MathMin(Siegd_156, Heild_48 * Siegd_148) / 100.0 * AccountFreeMargin() / lotstep / (Siegi_448 / 100)) * lotstep));
for (; 最后手数 >= 2.0 * minlot && 1.05 * (最后手数 * margin) >= AccountFreeMargin(); 最后手数 -= minlot)
{}
return (最后手数);
}
发表评论