why not create line my code ?

 

Hi  i have a and expert in ontick it call 2  function


void OnTick()
 {

      CALC_DATA();
      DrawLine4SnipeAll();

}

void DrawLine4SnipeAll()
{
 //Print("object_line4SniepAll: ", object_line4SniepAll);
     // Creazione della linea se non esiste
    if (g_dominance == "BUY")
    {
    
       if (ObjectFind(0, object_line4SniepAll) < 0)
       {
           ObjectCreate(0, object_line4SniepAll, OBJ_HLINE, 0, 0, g_mediumPrice4BkLineALL);
           ObjectSetInteger(0, object_line4SniepAll, OBJPROP_WIDTH, 0, line_width);
           ObjectSetInteger(0, object_line4SniepAll, OBJPROP_STYLE, 0, line_style);
           ObjectSetInteger(0, object_line4SniepAll, OBJPROP_SELECTABLE, false);
           //ObjectSetInteger(0, object_line4SniepAll, OBJPROP_HIDDEN, true);
           ObjectSetInteger(0, object_line4SniepAll, OBJPROP_COLOR, clrGreen);     
       }
       else
       {
           ObjectMove(0, object_line4SniepAll, 0, 0, g_mediumPrice4BkLineALL);
       }
    }
    else if (g_dominance == "SELL")
     {
    
         if (ObjectFind(0, object_line4SniepAll) < 0)
          {
              // Print("Break-even price: SELL", g_mediumPrice4BkLineALL);
              ObjectCreate(0, object_line4SniepAll, OBJ_HLINE, 0, 0, g_mediumPrice4BkLineALL);
              bool created = ObjectCreate(0, object_line4SniepAll, OBJ_HLINE, 0, 0, g_mediumPrice4BkLineALL);
if (!created)
{
    int err = GetLastError();
    Print("⚠️ Errore nella creazione della linea: ", err);
}
else
{
    Print("✅ Linea creata correttamente a prezzo: ", g_mediumPrice4BkLineALL);
}
              ObjectSetInteger(0, object_line4SniepAll, OBJPROP_WIDTH, 0, line_width);
              ObjectSetInteger(0, object_line4SniepAll, OBJPROP_STYLE, 0, line_style);
              ObjectSetInteger(0, object_line4SniepAll, OBJPROP_SELECTABLE, false);
              ObjectSetInteger(0, object_line4SniepAll, OBJPROP_HIDDEN, true);
              ObjectSetInteger(0, object_line4SniepAll, OBJPROP_COLOR, clrRed);    
          }
          else
          {
              ObjectMove(0, object_line4SniepAll, 0, 0, g_mediumPrice4BkLineALL);
          }
     }
}

bool CALC_DATA()
{
    int totalBuy = 0;       // Contatore per le posizioni BUY
    int totalSell = 0;      // Contatore per le posizioni SELL
    double totalBuyVolume = 0.0;  // Volume totale delle posizioni BUY
    double totalSellVolume = 0.0; // Volume totale delle posizioni SELL
    double weightedBuyPrice = 0.0; // Prezzo medio ponderato delle posizioni BUY
    double weightedSellPrice = 0.0; // Prezzo medio ponderato delle posizioni SELL
    double totalCommission = 0.0; // Commissioni totali
    double totalSwap = 0.0; // Swap totale

    // Numero totale di posizioni aperte
    int totalPositions = PositionsTotal();

    for (int i = 0; i < totalPositions; i++)
    {
        // Ottieni il ticket della posizione corrente
        ulong ticket = PositionGetTicket(i);

        // Seleziona la posizione tramite il ticket
        if (PositionSelectByTicket(ticket))
        {
            // Verifica se il Magic Number corrisponde
            if (PositionGetInteger(POSITION_MAGIC) == MagikNumb)
            {
                // Ottieni il tipo di posizione (BUY o SELL)
                ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);

                // Ottieni il volume della posizione
                double volume = PositionGetDouble(POSITION_VOLUME);

                // Ottieni il prezzo di apertura della posizione
                double openPrice = PositionGetDouble(POSITION_PRICE_OPEN);

                // Ottieni le commissioni e lo swap della posizione
                double commission = PositionGetDouble(POSITION_COMMISSION);
                double swap = PositionGetDouble(POSITION_SWAP);

                // Aggiorna i totali di commissioni e swap
                totalCommission += commission;
                totalSwap += swap;

                // Calcola il prezzo medio ponderato in base al tipo di posizione
                if (type == POSITION_TYPE_BUY)
                {
                    totalBuy++;
                    totalBuyVolume += volume;
                    weightedBuyPrice += openPrice * volume; // Somma ponderata dei prezzi BUY
                }
                else if (type == POSITION_TYPE_SELL)
                {
                    totalSell++;
                    totalSellVolume += volume;
                    weightedSellPrice += openPrice * volume; // Somma ponderata dei prezzi SELL
                }
            }
        }
    }

    // Calcola il prezzo medio ponderato per BUY e SELL
    double averageBuyPrice = (totalBuyVolume > 0) ? weightedBuyPrice / totalBuyVolume : 0.0;
    double averageSellPrice = (totalSellVolume > 0) ? weightedSellPrice / totalSellVolume : 0.0;

    // Calcola la dominance

   
    if (totalBuyVolume > totalSellVolume)
    {
        g_dominance = "BUY";
        g_mediumPrice4BkLineALL = averageBuyPrice + (totalCommission + totalSwap) / totalBuyVolume; // Break-even per BUY
    }
    else if (totalSellVolume > totalBuyVolume)
    {
        g_dominance = "SELL";
        g_mediumPrice4BkLineALL = averageSellPrice - (totalCommission + totalSwap) / totalSellVolume; // Break-even per SELL
    }
    
      // Numero di decimali del simbolo corrente
    int digits = (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS);

    // Normalizza il prezzo Break-even
    g_mediumPrice4BkLineALL = NormalizeDouble(g_mediumPrice4BkLineALL, digits);
    
    
/*
    // Stampa i risultati
    Print("Posizioni BUY con Magic Number ", MagikNumb, ": ", totalBuy);
    Print("Posizioni SELL con Magic Number ", MagikNumb, ": ", totalSell);
    Print("Volume totale BUY: ", totalBuyVolume);
    Print("Volume totale SELL: ", totalSellVolume);
    Print("Prezzo medio BUY: ", averageBuyPrice);
    Print("Prezzo medio SELL: ", averageSellPrice);
    Print("Commissioni totali: ", totalCommission);
    Print("Swap totale: ", totalSwap);
    Print("Dominance effettiva: ", g_dominance);
    Print("Break-even price: ", g_mediumPrice4BkLineALL);
*/
    return true; // Restituisce true per indicare che la funzione è stata eseguita correttamente
}

but  not  draw  the line   i look the priice  return perfect till in function andsintax is right i suppose  anyone can suggest somthing ?

 
it looks like chatgpt generated code. AI makes error and AI can fix that too if you explain the error in logical terms. Your code is also not compilable.
 
Rajesh Kumar Nait #:
it looks like chatgpt generated code. AI makes error and AI can fix that too if you explain the error in logical terms. Your code is also not compilable.

the problem is here 

object_line4SniepAll
 i fix it  thanks so much for rply