SOLO CANDELA / BAR - Come catalogare o segregare la candela? - PER FAVORE CORREGGIMI! - pagina 4

 

Ho la sensazione che perdiamo un po' di controllo sul codice....

        if ( SignalBULL62Executed) CheckForClose_BULL6();       // I don't know it is the right place to close

No, questo non è sicuramente il posto giusto.

   int    result;
   if(Bid==Close[1]+3*Point)  
     {
      result=OrderSend(Symbol(),OP_BUY,0.61,Ask,0,Close[1]-25*Point,0,"",MAGICMA2,0,Red);
      return;
     }
   if (result == -1)
      {
      int e = GetLastError();
      Print(e);
      }   
  } 

Questa "gestione degli errori" non migliora nulla. Controlla di nuovo.

bool Fun_New_Bar()                              // bool             

   {                                
   static datetime New_Time=0;      
   New_Bar=false;                   
   if(New_Time!=Time[0])           
      {
      New_Time=Time[0];                
      New_Bar=true;                    
      }
   }

Questo non è stato creato per divertimento! Dovrebbe essere usato per resettare le bandiere eseguite su una nuova barra.

if(Bid==Close[1]+3*Point)  

Cosa abbiamo imparato sul confronto dei doppi e se questo ha senso qui?

 

Così hai deciso di cancellare il tuo post a cui mi riferisco... Ben fatto, questo è molto utile!

 

Scusate ma ieri c'è stato un problema con internet (mql4.com non funziona più). Stavo cercando di correggere qualcosa e ... crollare

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#define MAGICMA1  2000        // blue starategy
#define MAGICMA2  2001        // red strategy

//+------------------------------------------------------------------+
//| Check NEW BAR                                |
//+------------------------------------------------------------------+
bool New_Bar = false;

bool Fun_New_Bar()                              // bool             

   {                                
   static datetime New_Time=0;      
   New_Bar=false;                   
   if(New_Time!=Time[0])           
      {
      New_Time=Time[0];                
      New_Bar=true;                    
      }
   }

//+------------------------------------------------------------------+
//| Calculate open positions    HOW MEANY OF THIS is open   |
//+------------------------------------------------------------------+

//--- FOR BLUE---------------------------------------------------------
int OpenOrders_BULL4(string symbol)
  {
   int buys=0;

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; 
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA1)    // magic ma 1 ( is ==)
        {
         if(OrderType()==OP_BUY) buys++;
        }
     }
   return(buys);
  }
  
//--- FOR RED--------------------------------------------------------------
int OpenOrders_BULL6(string symbol)
  {
   int buys=0;

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; 
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA2)    // magic ma 2 ( is ==)
        {
         if(OrderType()==OP_BUY) buys++;
        }
     }
   return(buys);
  }



//+------------------------------------------------------------------+
//| Condition candle                                                 |
//+------------------------------------------------------------------+
bool BULL4()
   {
   if(Close[1]-Open[1]>=4*Point && Close[1]-Open[1]<=5*Point)
   return(true);
   } 

bool BULL6()
   {
   if(Close[1]-Open[1]>=6*Point && Close[1]-Open[1]<=7*Point)
   return(true);
   }
      
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
//--------------------------- blue bull4 magicma1 
void OpenBULL41()
  {
   int    result;
   if(Bid==Close[1]+3*Point)  
     {
      result=OrderSend(Symbol(),OP_BUY,0.41,Ask,0,Close[1]-25*Point,0,"",MAGICMA1,0,Blue);
      return(true);
     }
    if (result == -1)
      {
      int e = GetLastError();
      Print(e);
      }      
  }
  
void OpenBULL42()
  {
   int    result;
   
   for(int i=1;i<=OrdersTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; 
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA1)    // magic ma 1 ( is ==)
        {
         if(Ask>OrderOpenPrice()+2*Point)  
            {
             result=OrderSend(Symbol(),OP_BUY,0.42,Ask,0,Close[1]-25*Point,0,"",MAGICMA1,0,Blue);
             return;
            }
          if (result == -1)
             {
             int e = GetLastError();
             Print(e);
             }    
        }
     }
  }  
//--------------------------- red bull6 magicma2 
void OpenBULL61()
  {
   int    result;
   if(Bid==Close[1]+3*Point)  
     {
      result=OrderSend(Symbol(),OP_BUY,0.61,Ask,0,Close[1]-25*Point,0,"",MAGICMA2,0,Red);
      return;
     }
   if (result == -1)
      {
      int e = GetLastError();
      Print(e);
      }   
  }
  
void OpenBULL62()
  {
   int    result;
   if(Ask>OrderOpenPrice()+2*Point)  
     {
      result=OrderSend(Symbol(),OP_BUY,0.62,Ask,0,Close[1]-25*Point,0,"",MAGICMA2,0,Red);
      return;
     }
    if (result == -1)
      {
      int e = GetLastError();
      Print(e);
      }     
  }

void OpenBULL63()
  {
   int    result;
   if(Ask>OrderOpenPrice()+2*Point)  
     {
      result=OrderSend(Symbol(),OP_BUY,0.63,Ask,0,Close[1]-25*Point,0,"",MAGICMA2,0,Red);
      return;
     }
    if (result == -1)
      {
      int e = GetLastError();
      Print(e);
      }    
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+

void CheckForClose_BULL4()
{

   if(OrderOpenPrice()+4*Point< Ask)
   for (int i = OrdersTotal()-1; i >= 0;i--)          // add: -1
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol() == Symbol()&& OrderMagicNumber()==MAGICMA1) 
      {
         bool ticket = true;
         if (OrderType() == OP_BUY) ticket = OrderClose(OrderTicket(),OrderLots(),Bid,1,Blue);

      }
   }
} 

void CheckForClose_BULL6()
{

   if(OrderOpenPrice()+8*Point< Ask)
   for (int i = OrdersTotal()-1; i >= 0;i--)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol() == Symbol()&& OrderMagicNumber()==MAGICMA2) 
      {
         bool ticket = true;
         if (OrderType() == OP_BUY) ticket = OrderClose(OrderTicket(),OrderLots(),Bid,1,Red);

      }
   }
}  
  
//+------------------------------------------------------------------+
//| flag                               |
//+------------------------------------------------------------------+ 
Fun_New_Bar();
if (New_Bar==false);
bool SignalBULL41Executed=false;
bool SignalBULL42Executed=false;
bool SignalBULL61Executed=false;
bool SignalBULL62Executed=false;
bool SignalBULL63Executed=false;

if(Fun_New_Bar())
{
   SignalBULL41Executed=true;
   return(SignalBULL41Executed);
}


  
  
//+------------------------------------------------------------------+
//| Start function                                 |
//+------------------------------------------------------------------+
void start()
  {
// ----------------bull4
if(BULL4())             
  if(!SignalBULL41Executed && OpenOrders_BULL4(Symbol())==0)
  {
    OpenBULL41();//do open buy position
    SignalBULL41Executed=true;
    if ( SignalBULL41Executed) CheckForClose_BULL4();       // I don't know it is the right place to close
  }
  
  
  if(!SignalBULL42Executed && OpenOrders_BULL4(Symbol())==1)
  {
    OpenBULL42();//do open buy position
    SignalBULL42Executed=true;
        if ( SignalBULL42Executed) CheckForClose_BULL4();       // I don't know it is the right place to close
  }
  
// ----------------bull6  
if(BULL6())             
  if(!SignalBULL61Executed && OpenOrders_BULL6(Symbol())==0)
  {
    OpenBULL61();//do open buy position
    SignalBULL61Executed=true;
        if ( SignalBULL61Executed) CheckForClose_BULL6();       // I don't know it is the right place to close
  }
  
  
  if(!SignalBULL62Executed && OpenOrders_BULL6(Symbol())==1)
  {
    OpenBULL62();//do open buy position
    SignalBULL62Executed=true;
        if ( SignalBULL62Executed) CheckForClose_BULL6();       // I don't know it is the right place to close
  }
  
  
  if(!SignalBULL63Executed && OpenOrders_BULL6(Symbol())==2)
  {
    OpenBULL63();//do open buy position
    SignalBULL42Executed=true;
        if ( SignalBULL62Executed) CheckForClose_BULL6();       // I don't know it is the right place to close
  }   

  }
//+------------------------------------------------------------------+
 

Non è facile aiutarvi. Perché non provi a implementare solo una strategia per ora, ma con unafunzione corretta, Open(), Close(), Count(), NewBar(), Signal().

Il blocco sottostante è al di fuori della funzione di avvio. Non sono sicuro che questo sia voluto.

Fun_New_Bar();
if (New_Bar==false);               // <-- ???
bool SignalBULL41Executed=false;   // <-- This could be correct, but I am not sure you know why and
bool SignalBULL42Executed=false;   //     its not more an accident that you initalize it here.
bool SignalBULL61Executed=false;
bool SignalBULL62Executed=false;
bool SignalBULL63Executed=false;

if(Fun_New_Bar())                  // <-- Your Fun_New_Bar() function doesn't return anything,
{                                  //     you set the global New_Bar variable with the function. 
   SignalBULL41Executed=true;      // <-- You should set it to false on a new bar.    
   return(SignalBULL41Executed);   // <-- ???
}
 

Penso lo stesso di te, piccoli passi. Prendiamo solo un'opzione BULL4
A volte sembra Ea al mio su codebase

https://www.mql5.com/en/code/9156 - interessante

Capisco questi (ma non sento), è una bandiera ecapisco il suo scopo

Cosa ne pensi di piccoli passi?

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#define MAGICMA1  2000        // blue starategy


//+------------------------------------------------------------------+
//| Check NEW BAR                                |
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Calculate open positions    HOW MEANY OF THIS is open   |
//+------------------------------------------------------------------+

int OpenOrders_BULL4(string symbol)
  {
   int buys=0;

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; 
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA1)   
        {
         if(OrderType()==OP_BUY) buys++;
        }
     }
   return(buys);
  }
  
//+------------------------------------------------------------------+
//| Condition candle                                                 |
//+------------------------------------------------------------------+
bool BULL4()
   {
   if(Close[1]-Open[1]>=4*Point && Close[1]-Open[1]<=5*Point)
      {
         return(true);
      } 
   else
      {
         return(false);
      } 
   }
//+------------------------------------------------------------------+
//| Condition send buy                                                 |
//+------------------------------------------------------------------+
 
bool BULL4send()
   {
   if( Bid==Close[1]+3*Point)
      {
         return(true);
      } 
    else
      {
        return(false);
      }
   }
 
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+

bool OpenBULL41()
  {
      int    result;

      result=OrderSend(Symbol(),OP_BUY,0.41,Ask,0,Close[1]-25*Point,0,"",MAGICMA1,0,Blue);
      if(result>0)
           {
            if(OrderSelect(result,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
      else
         {
            Print("Error opening BUY order : ",GetLastError()); 
            return(false);
         }
      return(true);       
   }
   
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+

  
//+------------------------------------------------------------------+
//| Start function                                 |
//+------------------------------------------------------------------+
void start()
  {
// ----------------bull4
   if(BULL4() && BULL4send() && OpenOrders_BULL4(Symbol())==0)             

     {
       OpenBULL41();//do open buy position
     }
  }
//+------------------------------------------------------------------+
 

Sì, piccoli passi, quindi gli errori sono gestibili...
Vuoi evidenziare qualcosa di specifico dal codice EA?

Non lo vedrò più - non ti aiuterò più se ignori ulteriormente i passi di correzione che io - o qualcun altro - ti ha consigliato di fare:

if( Bid==Close[1]+3*Point)

Lo slittamento è 0? Probabilmente otterrai un errore, ma la gestione degli errori fissata lo prenderà :-)

result=OrderSend(Symbol(),OP_BUY,0.41,Ask,0,Close[1]-25*Point,0,"",MAGICMA1,0,Blue);

Questo non è sbagliato, ma non è l'ideale e nel peggiore dei casi non fa quello che volete all'interno del ciclo. Meglio, non iniziare nemmeno a usare i loop da 0 a OrdersTotal. Leggete questo: Loop e chiusura o cancellazione di ordini

for(int i=0;i<OrdersTotal();i++)

Qual è lo spread del tuo broker e quante cifre hai per il simbolo che vuoi negoziare? Non sono sicuro che tu usi Point correttamente (Leggi la prima pagina del tuo thread).

 
kronin:

Sì, piccoli passi, quindi gli errori sono gestibili...
Vuoi evidenziare qualcosa di specifico dal codebase EA?

Penso di no, niente da illuminare, ho capito quello che ho scritto.

Non lo vedrò più - non ti aiuterò più se ignori ulteriormente i passi di correzione che io - o qualcun altro - ti ha consigliato di fare:

Sì. So cosa fare NormalizeDouble, cosa che ho capito (se ho: euro/usd = 1.2390022129.....09.... E abbiamo bisogno di: 1,29893 fine! non infinito) ma non posso scrivere questi, potrebbero essere questi?

if ( NormalizeDouble ( abc(),0 ) )

bool abc()

{

bool z,y,z;

x=Bid;

y=Chiusura[1]

z=x-y+3*Punto

return(z);

}

o ?

If ( NormalizeDouble ((Close[1]-Bid) +3*point),0 ) ;

Lo slippage è 0? Probabilmente otterrete un errore, ma la gestione fissa degli errori lo prenderà :-)

Posso avere +1 senza problemi result=OrderSend(Symbol(),OP_BUY,0.41,Ask, 1 ,Close[1]-25*Point,0,"",MAGICMA1,0,Blue);

errore gestirà, bene, vediamo cosa sarà dopo

Questo non è sbagliato, ma non è l'ideale e nel peggiore dei casi non fa quello che vuoi all'interno del ciclo. Meglio, non iniziare nemmeno a usare i loop da 0 a OrdersTotal. Leggete questo: Cicli e chiusura o cancellazione di ordini

OTTIMO ARTICOLO! Dovrei leggerlo all'inizio :)

Qual è lo spread del tuo broker e quante cifre hai per il simbolo che vuoi negoziare? Non sono sicuro che tu usi il punto correttamente (Leggi la prima pagina del tuo thread).

Ho Admiral Market Bid=1,29000 Ask = 1,29001. Questi è un problema che so,,, ma non ho risoluzione in questo momento non ho trovato il buon esempio.

Sto scrivendo il codice...

 
Wodzuuu:

Sì. So cosa fa NormalizeDouble, penso di aver capito (se ho: euro/usd = 1.2390022129.....09.... E abbiamo bisogno di: 1,29893 fine! non infinito) ma non posso scrivere questi, potrebbero essere questi?


if (NormalizeDouble( abc(),0 ) )

bool abc()

{


Non puoi NormalizeDouble() un bool, l'indizio è nel nome della funzione e anche nella documentazione.

doppioNormalizeDouble(valoredoppio,cifreint)

 
RaptorUK:

Non puoi NormalizeDouble() un bool, l'indizio è nel nome della funzione e anche nella documentazione.

È un peccato che non possiamo normalizzare il vero per essere molto vero :-(

Wodzuuu:
Sì. So cosa fa NormalizeDouble, cosa che capisco ( se ho: euro/usd = 1.2390022129.....09.... E abbiamo bisogno di: 1,29893 fine! non infinito) ma non posso scrivere questi, potrebbero essere questi?

No, non devi normalizzare Bid o Close[1]. Quello che volevo dire è che non dovresti semplicemente confrontarli per l'uguaglianza.

Immaginate:
Chiusura[1] = 1,31933
Nuova_barra
Tick1, Offerta = 1.31935
Tick2, Offerta = 1.31934
Tick3, Offerta = 1.31937
Tick4, Offerta = 1.31937
Tick5, Offerta = 1.31942


Il tuo codice cerca un Tick dove Bid è 1.31936

if( Bid==Close[1]+3*Point)

Perderai il tuo segnale. Questo non accadrebbe, se usi > .

Wodzuuu:
Posso avere +1 senza problemi result=OrderSend(Symbol(),OP_BUY,0.41,Ask, 1 ,Close[1]-25*Point,0,"",MAGICMA1,0,Blue);

Questo non migliora di molto la situazione. Tutto il tuo calcolo in punti dovrebbe essere Pips dalla mia comprensione. Tuttavia, non ho esperienza con i broker ECN, quindi potrebbe funzionare.

Wodzuuu:

Questo non è sbagliato, ma non è l'ideale e in un caso peggiore non fa quello che vuoi all'interno del ciclo. Meglio, non iniziare nemmeno a usare i loop da 0 a OrdersTotal. Leggete questo: Loop e chiusura o cancellazione di ordini

ARTICOLO MOLTO BUONO! Dovrei leggere questi all'inizio :)

Concordo e ci sono molti articoli molto buoni più, scritti dallo stesso autore. Anche il libro non è un brutto posto per iniziare.

Wodzuuu:

Ho Admiral Market Bid=1,29000 Ask = 1,29001. Questi è un problema che so,,, ma non ho risoluzione in questo momento non ho trovato il buon esempio.

Sul sito del vostro broker è indicato che per EURUSD lo spread minimo è 0,1. Lo spread medio è 0,5. <-- Questo è inteso in pip! Quindi 0,1 è 1 punto. 0,5 è 5 punti.
Quindi, nel tuo caso, un Pip è 10*Punto. Lo spread confonderà tutti i tuoi mini calcoli dove aggiungi solo 3 punti ad un prezzo.
Cerca "adjust for 5 digit broker" e dovresti trovare molti esempi.

 

CIAO :)

Se questo codice era cattivoperché stavo passando dei segnali, è migliorato.Ho pensato che il problema è interamente in un posto diverso, non nel segno di uguaglianza '=='......... il '>=' è un'idea migliore naturalmente

if( Bid==Close[1]+3*Point)
if( Bid>=Close[1]+MyPips*3)

Domanda 1. Devo usare MyPips in candela, in queste funzioni? bool BULL4()

Problema DIGIT.

Ho trovato questi

https://www.mql5.com/en/forum/140097 da WHRoeder

https://www.mql5.com/en/forum/123736 da WHRoeder

Cos'è Digit? in https://docs.mql4.com/predefined/variables/digits e https://docs.mql4.com/convert/doubletostr

Poiché tu sei l' esperto avrei dovuto dire qualcosa, potrebbe essere importante.
Ora uso lapiattaforma MT4 e vedo 4 cifre dopo il punto decimale (Bid-Ask= 0.0001 usualy). Al momento abbiamo programmatoin MQL4 lasciare che sia.
In MT5, vedo5 cifre dopo il punto decimale. c'èdifferenza tra MQL4 eMQL5. Al momento questo spreco non haimportanza per me. Importanteper il nostro EA ha funzionato bene.
non voglio in questo momento a parlare di esso (a meno che non sia necessario)

E ho scritto il programma per me è buono :) e tu?

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#define MAGICMA1  2000        // blue starategy

//+------------------------------------------------------------------+
//| Check NEW BAR                                |
//+------------------------------------------------------------------+

// nothing yet, one moment

//+------------------------------------------------------------------+
//| These are adjusted for 5/4 digit brokers                           |
//+------------------------------------------------------------------+

double  MyPips;        // slippage and others

int init()
  {
    if (Digits == 5)    // Adjust for five (5) 
    {                
         MyPips=Point*10; 
    } 
    else                // Adjust for four (4, and ..)
    {
         MyPips=Point*1;  
    }
  }
 
//+------------------------------------------------------------------+
//| Calculate open positions    HOW MEANY OF THIS is open   |
//+------------------------------------------------------------------+

int OpenOrders_BULL4(string symbol)
  {
   int buys=0;

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; 
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA1)   
        {
         if(OrderType()==OP_BUY) buys++;
        }
     }
   return(buys);
  }
  
//+------------------------------------------------------------------+
//| Condition candle                                                 |
//+------------------------------------------------------------------+
bool BULL4()
   {
   if(Close[1]-Open[1]>=4*Point && Close[1]-Open[1]<=5*Point)
      {
         return(true);
      } 
   else
      {
         return(false);
      } 
   }

//+------------------------------------------------------------------+
//| Condition send buy                                                 |
//+------------------------------------------------------------------+
 
bool BULL4send()
   {
   if( Bid>=Close[1]+MyPips*3)
      {
         return(true);
      } 
    else
      {
        return(false);
      }
   }
 
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+

bool OpenBULL41()
  {
      int    result;

      result=OrderSend(Symbol(),OP_BUY,0.41,Ask,MyPips,Close[1]-25*MyPips,0,"",MAGICMA1,0,Blue);
      if(result>0)
           {
            if(OrderSelect(result,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
      else
         {
            Print("Error opening BUY order : ",GetLastError()); 
            return(false);
         }
      return(true);       
   }
   
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+

bool CheckForCloseBULL4()
{
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
      if( ! OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ) continue;
         if( OrderMagicNumber() == MAGICMA1 && OrderSymbol() == Symbol()  && OrderType() == OP_BUY )
            if(OrderOpenPrice()+8*MyPips < Ask) return(true);
            
   else return(false);
}

//+------------------------------------------------------------------+
//|  close                               |
//+------------------------------------------------------------------+

void CloseBULL4()
{
   int i;   
   for(i=OrdersTotal()-1;i>=0;i--)
      {
      if( ! OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ) continue;  
   
      if( OrderMagicNumber() == MAGICMA1 && OrderSymbol() == Symbol()  && OrderType() == OP_BUY )  
   
         if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), MyPips*1,Black ) )               
            Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() );  
      } 
}

//+------------------------------------------------------------------+
//| Start function                                 |
//+------------------------------------------------------------------+
void start()
  {
// ----------------bull4
   if(BULL4() && BULL4send() && OpenOrders_BULL4(Symbol())==0)             

     {
       OpenBULL41();//do open buy position
     }
     
   if(CheckForCloseBULL4()==true && OpenOrders_BULL4(Symbol())==1) CloseBULL4();   
  }
//+------------------------------------------------------------------+
Motivazione: