单个订单实现自动追踪止损容易,但是成交价格低的订单止盈平仓后,高位订单因未平而最终导致整体亏损,如果能将多订单平均成本如同个别订单样,实现自动追踪那感觉就好很多了。如果设置整体盈利目标到后全部平,也简单,不过感觉这个数值等于算命那样全靠碰,不科学,主观臆断成分太重,同时差一点点到不了,又得坐免费甚至高昂过山车。止损止盈交给市场客观决定,应该才是硬道理,你觉得呢,我的大神!以我的资质难完成,所以走过路过的大神还请出手相助为盼!当然我的表述可能有点啰嗦不明确,好在作为大神,您都懂我的意思的。
你可以在自由職業者發布委託 做一個計算平均持倉價後的移動止盈止損
或是在腳本裡面找一下 有免費的計算平均價跟單獨的移動止盈腳本可以用
double averageCost = 0.0; // 平均成本
double stopLossDistance = 100.0; // 止损距离(以点为单位)
int OnInit()
{
double totalCost = 0.0;
int totalLots = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderType() == OP_BUY)
{
totalCost += OrderOpenPrice() * OrderLots();
totalLots += OrderLots();
}
}
}
if (totalLots > 0)
{
averageCost = totalCost / totalLots;
}
return INIT_SUCCEEDED;
}
void OnTick()
{
double totalCost = 0.0;
int totalLots = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderType() == OP_BUY)
{
totalCost += OrderOpenPrice() * OrderLots();
totalLots += OrderLots();
}
}
}
if (totalLots > 0)
{
averageCost = totalCost / totalLots;
}
double stopLossPrice = averageCost - stopLossDistance * Point;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderType() == OP_BUY)
{
if (OrderStopLoss() != stopLossPrice)
{
OrderModify(OrderTicket(), OrderOpenPrice(), stopLossPrice, OrderTakeProfit(), 0, CLR_NONE);
}
}
}
}
}
//这样堪称完美标准答案,谢谢大神出手!