谁帮我修改下代码,谢谢!

 
double averageBuyPrice = 0.0; // 多单均价
double averageSellPrice = 0.0; // 空单均价
int longLineHandle;  // 多单均价线句柄
int shortLineHandle; // 空单均价线句柄
double totalBuyLots = 0.0;
double totalBuyProfit = 0.0;
double totalBuyCommission = 0.0;
double totalBuySwap = 0.0;
double totalNetProfitBuy = 0.0;
double totalSellLots = 0.0;
double totalSellProfit = 0.0;
double totalSellCommission = 0.0;
double totalSellSwap = 0.0;
double totalNetProfitSell = 0.0;
double totalBuyAmount = 0.0;
double totalBuyCost = 0.0;
double totalSellAmount = 0.0;
double totalSellCost = 0.0;
double totalNetProfit = 0.0; // 总净盈亏

void OnTick()
{   
    UpdateAveragesAndLabel();
      CalculateTotalNetProfit();
    ShowPositionInfo();
    
}
void CreateLinesAndLabel()
{
    longLineHandle = ObjectCreate(0, "LongLine", OBJ_HLINE, 0, 0, 0);
    ObjectSetInteger(0, "LongLine", OBJPROP_COLOR, clrBlue);
    ObjectSetInteger(0, "LongLine", OBJPROP_WIDTH, 2);
    ObjectSetInteger(0, "LongLine", OBJPROP_SELECTABLE, 0);  // 设置为不可选中
    ObjectSetDouble(0, "LongLine", OBJPROP_PRICE1, averageBuyPrice);
    shortLineHandle = ObjectCreate(0, "ShortLine", OBJ_HLINE, 0, 0, 0);
    ObjectSetInteger(0, "ShortLine", OBJPROP_COLOR, clrRed);
    ObjectSetInteger(0, "ShortLine", OBJPROP_WIDTH, 2);
    ObjectSetInteger(0, "ShortLine", OBJPROP_SELECTABLE, 0);  // 设置为不可选中
    ObjectSetDouble(0, "ShortLine", OBJPROP_PRICE1, averageSellPrice);

}
void UpdateAveragesAndLabel()
{
    totalBuyLots = 0.0;
    totalBuyProfit = 0.0;
    totalBuyCommission = 0.0;
    totalBuySwap = 0.0;
    totalNetProfitBuy = 0.0;
    
    averageBuyPrice = 0.0; // Reset average buy price
    totalSellLots = 0.0;
    totalSellProfit = 0.0;
    totalSellCommission = 0.0;
    totalSellSwap = 0.0;
    totalNetProfitSell = 0.0;

    averageSellPrice = 0.0; // Reset average sell price
    totalBuyAmount = 0.0;
    totalBuyCost = 0.0;
    totalSellAmount = 0.0;
    totalSellCost = 0.0;

    for (int i = 0; i < OrdersHistoryTotal(); i++)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == _Symbol)
        {
            double orderProfit = OrderProfit();
            double orderCommission = OrderCommission();
            double orderSwap = OrderSwap();
            double netProfit = orderProfit + orderCommission + orderSwap;

            if (OrderType() == OP_BUY)
            {
                totalBuyLots += OrderLots();
                totalBuyProfit += orderProfit;
                totalBuyCommission += orderCommission;
                totalBuySwap += orderSwap;
                totalNetProfitBuy += netProfit;
                
                totalBuyAmount += OrderLots();
                totalBuyCost += OrderLots() * OrderOpenPrice();
            }
            else if (OrderType() == OP_SELL)
            {
                totalSellLots += OrderLots();
                totalSellProfit += orderProfit;
                totalSellCommission += orderCommission;
                totalSellSwap += orderSwap;
                totalNetProfitSell += netProfit;
                
                totalSellAmount += OrderLots();
                totalSellCost += OrderLots() * OrderOpenPrice();
            }
        }
    }

    // Calculate average buy price
    averageBuyPrice = (totalBuyAmount > 0) ? totalBuyCost / totalBuyAmount : 0.0;

    // Calculate average sell price
    averageSellPrice = (totalSellAmount > 0) ? totalSellCost / totalSellAmount : 0.0;

    // Update chart objects
    ObjectSetDouble(0, "LongLine", OBJPROP_PRICE1, averageBuyPrice);
    ObjectSetDouble(0, "ShortLine", OBJPROP_PRICE1, averageSellPrice);
}
int OnInit()
{
    ObjectCreate(0, "PositionInfo_Long", OBJ_LABEL, 0, 0, 0);
    ObjectSetInteger(0, "PositionInfo_Long", OBJPROP_XDISTANCE, 10);
    ObjectSetInteger(0, "PositionInfo_Long", OBJPROP_YDISTANCE, 30);
    ObjectCreate(0, "PositionInfo_Short", OBJ_LABEL, 0, 0, 0);
    ObjectSetInteger(0, "PositionInfo_Short", OBJPROP_XDISTANCE, 10);
    ObjectSetInteger(0, "PositionInfo_Short", OBJPROP_YDISTANCE, 60);    
    ObjectCreate(0, "PositionInfo_Net", OBJ_LABEL, 0, 0, 0);
    ObjectSetInteger(0, "PositionInfo_Net", OBJPROP_XDISTANCE, 10);
    ObjectSetInteger(0, "PositionInfo_Net", OBJPROP_YDISTANCE, 90);
    CreateLinesAndLabel();
    return (INIT_SUCCEEDED);
}

void ShowPositionInfo()
{
    string textBuy = StringFormat("多单手数: %.2f, 盈亏金额: %.2f, 均价: %.2f", totalBuyAmount, totalNetProfitBuy, averageBuyPrice);
    ObjectSetText("PositionInfo_Long", textBuy, 10, "Arial", Blue);
    string textSell = StringFormat("空单手数: %.2f, 盈亏金额: %.2f, 均价: %.2f", totalSellAmount, totalNetProfitSell, averageSellPrice);
    ObjectSetText("PositionInfo_Short", textSell, 10, "Arial", Blue);
    double netLots = totalBuyAmount - totalSellAmount;
    string netLotsText = (netLots > 0) ? "多" : (netLots < 0) ? "空" : "平";
    string textNetInfo = StringFormat("净手数: %s, %.2f,净盈亏: %.2f", netLotsText, MathAbs(netLots), totalNetProfit);
    ObjectSetText("PositionInfo_Net", textNetInfo, 15, "Arial", Blue);        
}
void CalculateTotalNetProfit()
{
    totalNetProfit = totalNetProfitBuy + totalNetProfitSell;
    double netLots = totalBuyAmount - totalSellAmount;
}

哪位大佬帮我修改下这个,实现多空持仓信息跟随均价线移动,现在是显示在左上角。

附加的文件:
 
Frist001:

哪位大佬帮我修改下这个,实现多空持仓信息跟随均价线移动,现在是显示在左上角。

Print()把函數或變數打印出來自己找原因,編程就只是不定期的三個步驟。

1.了解程式語言經常會用到的語法,舉例if...else,for,函數,變數,參數。

2.了解程式語言的內建函數功能。

3.遇到困難時,但編譯又沒有錯時,將函數返回結果給打印出來。

上面三個步驟不一定要按照順序,照自己的節奏調整就好。

編程就只是這樣而已,但很多人都會忘記第三個步驟的重要性,自己找答案會比求神問佛還要有效率。

而且下次遇到類似的問題時,也才知道要如何找到答案。

發現老是幫人修改代碼,對方下次還是不曉得如何排除問題,給魚到不如教人釣魚。