Problema per uscire da un ciclo

Sezione dedicata a metatrader (ed altre piattaforme) ed al suo linguaggio di programmazione per il trading automatico
Rispondi
texcs
Messaggi: 144
Iscritto il: 29/05/2014, 23:08

Problema per uscire da un ciclo

Messaggio da texcs »

Codice: Seleziona tutto

int MedieCicliche(double intRastvor)
 { 
            // Per convenzione si usa
            // +1 = BUY
            //  0 = Tutto bene, ma non fa niente
            // -1 = SELL

   double  MediaVeloceDayBuffer[],  MediaLentaDayBuffer[],MediaVeloceDefaultBuffer[],MediaLentaDefaultBuffer[], 
           ImaVeloceDefault, ImaLentaDefault, ImaVeloceDay, ImaLentaDay,  
           ImaVelocePrecDay, ImaVelocePrecDefault,ImaLentaPrecDay, ImaLentaPrecDefault;
           
    
            ImaVelocePrecDefault = iMA(NULL,0, MediaVelocePeriod , 0, 0, 0, 1);//fuschia
            ImaLentaPrecDefault = iMA(NULL,0, MediaLentaPeriod , 0, 0, 0, 1);//arancio

            ImaVeloceDefault = iMA(NULL,0, MediaVelocePeriod , 0, 0, 0, 0);//fuschia
            ImaLentaDefault = iMA(NULL,0, MediaLentaPeriod , 0, 1, 0, 0);//arancio
            pipsMAbuy = (int)MathFloor( MathAbs(ImaVeloceDefault-ImaLentaDefault)/(_Point) );
            pipsMAsell = (int)MathFloor( MathAbs(ImaVeloceDefault-ImaLentaDefault)/(_Point) );
            
            if (pipsMAbuy == intRastvor &&ImaVeloceDefault<ImaLentaDefault )//((ImaVelocePrecDefault < ImaLentaDefault) && (ImaVeloceDefault > ImaLentaDefault + intRastvor * Point))
               {
                  buy++; 
                  Comment("Buy " + buy + "\nPips"+ pipsMAbuy+ "\nRastvor" +  Rastvor);
                  return +1; //Long

               }
           
            
              if ((pipsMAsell == intRastvor &&ImaVeloceDefault<ImaLentaDefault ))//((ImaVelocePrecDefault > ImaLentaDefault) && (ImaVeloceDefault < ImaLentaDefault + intRastvor * Point))
                {
                  sell++;
                  Comment("Buy " + buy + "\nPips"+pipsMAsell+ "\nRastvor" +  Rastvor);
                  return -1; //Short
                  
                }
     
       return 0;
  }   
   
Ragazzi allora ho questa funzione che uso così:

Codice: Seleziona tutto


         if (MedieCicliche(Rastvor)==+1)

         {
            if (BuySell !=+1){
              //  Comment("Buy " + buy + pipsMAbuy+ "\nPips"+ "\nRastvor" +  Rastvor);
                AllertoPerIlRialzo();
                BuySell =+1;
               }
                  
         }
        else if(MedieCicliche(Rastvor)==-1)
         {
            if (BuySell !=-1)
            {
            //   Comment("\nSell " +sell+ "\nPips" +  pipsMAsell+ "\nRastvor" +  Rastvor);
            AllertoPerIlRibasso();
            BuySell =-1;
            }
            
       }
ora il mio problema è che  vorrei farmi segnare solo una volta i segnali esempio: segnale buy dopo si attende un segnale sell e viceversa ma non doppio buy  o doppio sell, ho usato la variabile di supporto Buysell ma mi sto incartando!! 
qualche idee in merito?
Avatar utente
carlo10
Messaggi: 4262
Iscritto il: 08/05/2014, 21:17

Re: Problema per uscire da un ciclo

Messaggio da carlo10 »

In passato sfruttavo la tecnica descritta qui: https://metatrader-forex-trading.blogsp ... a.html?m=1
texcs
Messaggi: 144
Iscritto il: 29/05/2014, 23:08

Re: Problema per uscire da un ciclo

Messaggio da texcs »

Grazie, ora volevo un 'altra delucidazione, in questo modo la funzione mi segnala l'incrocio delle medie,
inserendo questa pezzo

Codice: Seleziona tutto

 ((pipsMAsell == intRastvor &..................
per sell

Codice: Seleziona tutto

 ((pipsMAbuy  == intRastvor &.................
per buy
dove "intRastvor" è una variabile esterna vorre farmi dare il segnale qundo la distanza tra una media e l'altra c'è una distanza che vale "intRastvor".
texcs
Messaggi: 144
Iscritto il: 29/05/2014, 23:08

Re: Problema per uscire da un ciclo

Messaggio da texcs »

però cosi com'è non funziona........... avete idee per sistemare
Rispondi

Chi c’è in linea

Visitano il forum: Nessuno e 0 ospiti