Problems with My EA. Repea

 
Problems with My EA.

I have problems with a complex function of my EA. Every day, pending orders are renewed, however some of them are repeated at the same price level.

There is an indicator and I use the price of that indicator as an entry reference.

1- I would like if it were possible to compare the entry price of the indicator with order 1, of the next day's order, so that duplicates do not occur

or else...
2- Build a counter for each individual order to distinguish position status based on ctrader class.
 0 when renewing appointments next day || when the profit gain of the order is reached || or when own and delete them

 1 for when the pending order is executed but not completed


Repeated pending orders at the same price level after the next day

using an indicator with double variables and predefined buffers

appointments are renewed the next day or at predefined times


Void Ontick()
{
       
           
      Print("Atualizando");
      
      CopyBuffer(handlevaria, 0, 0, 5, S3S);
      CopyBuffer(handlevaria, 1, 0, 5, S2S);
      CopyBuffer(handlevaria, 2, 0, 5, S1S);
      CopyBuffer(handlevaria, 3, 0, 5, fec);
      CopyBuffer(handlevaria, 4, 0, 5, S1I);
      CopyBuffer(handlevaria, 5, 0, 5, S2I);
      CopyBuffer(handlevaria, 6, 0, 5, S3I);
      
      
      Print(S3S[0]);
      Print(S2S[0]);
      Print(S1S[0]);
      Print(fec[0]);
      Print(S1I[0]);
      Print(S2I[0]);
      Print(S3I[0]);
      
     
      
      Print("");
      
      }
      
      //Vendas contra a tendencia no 1° indicador
    //  (Caso04());
      m_trade.SellLimit(0.01, S3S[0], _Symbol, 0, (S3S[0]*0.995), ORDER_TIME_GTC, 0, "");
      //(Caso03());
      m_trade.SellLimit(0.01, S2S[0], _Symbol, 0, (S2S[0]*0.995), ORDER_TIME_GTC, 0, "");
   //   (Caso02());
      m_trade.SellLimit(0.01, S1S[0], _Symbol, 0, (S1S[0]*0.995), ORDER_TIME_GTC, 0, "");
   //   (Caso01());
      m_trade.SellLimit(0.01, fec[0], _Symbol, 0, (fec[0]*0.995), ORDER_TIME_GTC, 0, "");    
       
      //Vendas a favor da tendencia no 1° indicador     
      m_trade.SellStop(0.01, fec[0], _Symbol, 0, (fec[0]*0.995), ORDER_TIME_GTC, 0, "");
    //  (Caso01());
      m_trade.SellStop(0.01, S1I[0], _Symbol, 0, (S1I[0]*0.995), ORDER_TIME_GTC, 0, "");
   //   (Caso02());
      m_trade.SellStop(0.01, S2I[0], _Symbol, 0, (S2I[0]*0.995), ORDER_TIME_GTC, 0, "");
    //   (Caso03());
      m_trade.SellStop(0.02, S3I[0], _Symbol, 0, (S3I[0]*0.995), ORDER_TIME_GTC, 0, "");
     //  (Caso04());
    //  
      
      
     }    


 

Please don't create topics randomly in any section. It has been moved to the section: Expert Advisors and Automated Trading

Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

 
Fernando Carreiro #:

Please don't create topics randomly in any section. It has been moved to the section: Expert Advisors and Automated Trading

Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Hover your mouse over your post and select "edit" ... 


well, I didn't know, thanks for the information
 

I am tryng this but not work... help please


enum OrderType
{   
    BUY,
    SELL,
    BUY_STOP,
    BUY_LIMIT,
    SELL_STOP,
    STOP_LIMIT,
};


Void Ontick()

      {
      
           
      Print("Atualizando");
      
      CopyBuffer(handlevaria, 0, 0, 5, S3S);
      CopyBuffer(handlevaria, 1, 0, 5, S2S);
      CopyBuffer(handlevaria, 2, 0, 5, S1S);
      CopyBuffer(handlevaria, 3, 0, 5, fec);
      CopyBuffer(handlevaria, 4, 0, 5, S1I);
      CopyBuffer(handlevaria, 5, 0, 5, S2I);
      CopyBuffer(handlevaria, 6, 0, 5, S3I);
      
      
      
      Print(S3S[0]);
      Print(S2S[0]);
      Print(S1S[0]);
      Print(fec[0]);
      Print(S1I[0]);
      Print(S2I[0]);
      Print(S3I[0]);
      
     
      
      Print("");
      
      }
      

// Verifica se já existe uma ordem no mesmo nível de preço
int totalOrders = OrdersTotal();
for (int i = 0; i < totalOrders; i++)
{
    // Obtém o ticket e o preço de abertura de cada ordem
    ulong ticket = OrderGetTicket(i);
    double openPrice = OrderGetDouble(ORDER_PRICE_OPEN);
    
    // Obtém o tipo da ordem
    int orderType = (int)OrderGetInteger(ORDER_TYPE);
    
    // Verifica se o preço de abertura e o tipo de ordem são iguais
    if ((openPrice == S3S[0] || openPrice == S2S[0] || openPrice == S1S[0] || openPrice == fec[0] || openPrice == S1I[0] || openPrice == S2I[0] || openPrice == S3I[0] ||
         ) &&         orderType == ORDER_TYPE)
    {
        // Já existe uma ordem no mesmo nível de preço com o mesmo tipo
        // Faça alguma ação aqui, como exibir uma mensagem de erro ou ignorar a criação da ordem
        m_trade.OrderDelete(ticket);
        Print("ordem deletada",ticket);
        return;
    }
}







or


Void Ontick()

 {    
     // Verifica se já existe uma ordem no mesmo nível de preço
    int totalOrders = OrdersTotal();
    for (int i = 0; i < totalOrders; i++)
    {
        // Obtém o ticket e o preço de abertura de cada ordem
        ulong ticket = OrderGetTicket(i);
        double openPrice = OrderGetDouble(ORDER_PRICE_OPEN);
        
        
        //double PositionPrice= POSITION_PRICE_OPEN

       
        //OrderSelect(ticket);
     if(ORDER_TYPE_BUY_STOP)
     
     // if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==InpMagic) 

        // Compara o preço de abertura da ordem com o preço desejado para a nova ordem
         if (openPrice == S3S[0] || openPrice == S2S[0] || openPrice == S1S[0] || openPrice == fec[0] || openPrice == S1I[0] || openPrice == S2I[0] || openPrice == S3I[0])
            {
                m_trade.OrderDelete(ticket);
                
                Print("ordem deletada",ticket);
                return;
            }
         
            
     if(ORDER_TYPE_BUY_LIMIT)
    
   
     //if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==InpMagic)
        // Compara o preço de abertura da ordem com o preço desejado para a nova ordem
         if (openPrice == S3S[0] || openPrice == S2S[0] || openPrice == S1S[0] || openPrice == fec[0] || openPrice == S1I[0] || openPrice == S2I[0] || openPrice == S3I[0])
            {
                m_trade.OrderDelete(ticket);
                Print("ordem deletada",ticket);
                return;
           
     if(ORDER_TYPE_SELL_LIMIT)
    
     
     //if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==InpMagic)
        // Compara o preço de abertura da ordem com o preço desejado para a nova ordem
         if (openPrice == S3S[0] || openPrice == S2S[0] || openPrice == S1S[0] || openPrice == fec[0] || openPrice == S1I[0] || openPrice == S2I[0] || openPrice == S3I[0])
            {
                m_trade.OrderDelete(ticket);
                Print("ordem deletada",ticket);
                return;
            }
         
     if(ORDER_TYPE_SELL_STOP)
   
     //if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==InpMagic)
         

        // Compara o preço de abertura da ordem com o preço desejado para a nova ordem
         if (openPrice == S3S[0] || openPrice == S2S[0] || openPrice == S1S[0] || openPrice == fec[0] || openPrice == S1I[0] || openPrice == S2I[0] || openPrice == S3I[0])
            {
                m_trade.OrderDelete(ticket);
                Print("ordem deletada",ticket);
                return;
            }
        
     if((ORDER_TYPE_BUY) || (POSITION_TYPE_BUY))
      //if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==InpMagic)

        // Compara o preço de abertura da ordem com o preço desejado para a nova ordem
         if (openPrice == S3S[0] || openPrice == S2S[0] || openPrice == S1S[0] || openPrice == fec[0] || openPrice == S1I[0] || openPrice == S2I[0] || openPrice == S3I[0])
            {
                m_trade.OrderDelete(ticket);
                Print("ordem deletada",ticket);
                return;
            }
        
     if((ORDER_TYPE_SELL)|| (POSITION_TYPE_SELL))
     //if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==InpMagic)

        // Compara o preço de abertura da ordem com o preço desejado para a nova ordem
         if (openPrice == S3S[0] || openPrice == S2S[0] || openPrice == S1S[0] || openPrice == fec[0] || openPrice == S1I[0] || openPrice == S2I[0] || openPrice == S3I[0])
            {
                m_trade.OrderDelete(ticket);
                Print("ordem deletada",ticket);
                return;
            }