[Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate oltre. Non potrei andare da nessuna parte senza di te - 2. - pagina 396

 
Mi dispiace, non riesco a compilare una linea semplice-semplice.
double price=(Ask+Bid)/2;
Prima che lo mettessi, ha compilato a 0. Ora...
 
Dimka-novitsek:
Scusa, non riesco a compilare una linea semplice-semplice, compilava a 0 prima che la mettessi, ora compila a
.

# Mettilo all'inizio #
 
Grazie!
 

Non riesco ad ottenere il ciclo giusto, ad ogni tick vengono aperti un paio di ordini, dovrebbe essere così. Quando arriva un tick, la variabile X viene dichiarata all'interno del ciclo, assumendo rispettivamente il valore 0.

Poi X=numero di ordini viene calcolato all'interno del ciclo, e se X=0 o 1, allora si aprono.

//+------------------------------------------------------------------+
//|                                                         блин.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern double stoploss=0; extern double takeprofit=20;extern int otstup=20; extern datetime expiration=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int tiket,tikett;double volume=0.1;int i=0,R1=0,R2=0,A=1 ;
int start()
  { int X; double price=(Ask+Bid)/2;      
//----
       for(int Uy=OrdersTotal();Uy==0;Uy--){Alert ("OrdersTotal()",OrdersTotal());//тут считаем кол-во уже открытых ордеров.
OrderSelect( Uy,SELECT_BY_POS );Alert ("Uy",Uy);if(OrderSymbol()==Symbol()&&OrderMagicNumber( )==1000||OrderMagicNumber( )==2000 &&OrderSymbol()==Symbol())
{X ++;}  Alert ("X",X);}
//----
if (X<2){
   tiket= OrderSend( Symbol(), OP_BUYSTOP,  volume*A, price +otstup*Point, Point* 3, R1, price+takeprofit*Point+otstup*Point, "OP_BUYSTOP", 1000,  expiration, Red); 
   Alert ("OP_BUYSTOP", GetLastError( )); 
   tikett= OrderSend( Symbol(), OP_SELLSTOP,  volume*A, price -otstup*Point, Point* 3,R2, price-takeprofit*Point-otstup*Point, "OP_SELLSTOP" , 2000,  expiration,C'0,128,255' );
    Alert ("OP_SELLSTOP", GetLastError( )); 
    }       
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
//+------------------------------------------------------------------+
//|                                                         блин.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern double stoploss=0; extern double takeprofit=20;extern int otstup=20; extern datetime expiration=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int tiket,tikett;double volume=0.1;int i=0,R1=0,R2=0,A=1 ;
int start()
  { int X=0; double price=(Ask+Bid)/2;      
//----
       for(int Uy=OrdersTotal();Uy==0;Uy--){Alert ("OrdersTotal()",OrdersTotal());
OrderSelect( Uy,SELECT_BY_POS );Alert ("Uy",Uy);if(OrderSymbol()==Symbol()&&OrderMagicNumber( )==1000||OrderMagicNumber( )==2000 &&OrderSymbol()==Symbol())
{X ++;}  Alert ("X",X);}
//----
if (X<2){
   tiket= OrderSend( Symbol(), OP_BUYSTOP,  volume*A, price +otstup*Point, Point* 3, R1, price+takeprofit*Point+otstup*Point, "OP_BUYSTOP", 1000,  expiration, Red); 
   Alert ("OP_BUYSTOP", GetLastError( )); 
   tikett= OrderSend( Symbol(), OP_SELLSTOP,  volume*A, price -otstup*Point, Point* 3,R2, price-takeprofit*Point-otstup*Point, "OP_SELLSTOP" , 2000,  expiration,C'0,128,255' );
    Alert ("OP_SELLSTOP", GetLastError( )); 
    }       
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

Avete dichiarato una variabile ma non l'avete azzerata. Pertanto, con ogni spunta non potrà che crescere !!!!!!

Non è la cosa giusta da fare.

double price=(Ask+Bid)/2;
 
Grazie!!! Ora lo resetto. Ma c'è comunque qualcosa che non va, forse il primo ciclo per qualche motivo non funziona e X rimane sempre 0. Non posso nemmeno scoprirlo con certezza, perché Alert ("X",X) non mette niente nel log, mette solo ordini con zeri.
 
VOLDEMAR:

Avete dichiarato una variabile ma non l'avete azzerata. Pertanto, con ogni spunta non potrà che crescere !!!!!!

Non è giusto.


Qui vi sbagliate. Ad ogni tick questa variabile viene dichiarata di nuovo, quindi è uguale a 0.

Lo toglie dall'equazione.

int start()
  { int X; double price=(Ask+Bid)/2;      
//----
       for(int Uy=OrdersTotal();Uy==0;Uy--){Alert ("OrdersTotal()",OrdersTotal());
OrderSelect( Uy,SELECT_BY_POS );Alert ("Uy",Uy);if(OrderSymbol()==Symbol()&&(OrderMagicNumber( )==1000||OrderMagicNumber( )==2000 )&&OrderSymbol()==Symbol())
{X ++;}  Alert ("X",X);}
//----
if (X<2){
   tiket= OrderSend( Symbol(), OP_BUYSTOP,  volume*A, price +otstup*Point, 3, R1, price+takeprofit*Point+otstup*Point, "OP_BUYSTOP", 1000,  expiration, Red); 
   Alert ("OP_BUYSTOP", GetLastError( )); 
   RefreshRates();
   tikett= OrderSend( Symbol(), OP_SELLSTOP,  volume*A, price -otstup*Point,  3,R2, price-takeprofit*Point-otstup*Point, "OP_SELLSTOP" , 2000,  expiration,C'0,128,255' );
    Alert ("OP_SELLSTOP", GetLastError( )); 
    }       
   
//----
   return(0);
  }
 
Roger:

È qui che vi sbagliate. Ad ogni tick questa variabile viene dichiarata di nuovo, quindi è uguale a 0.

Sì, se lo impostate come x=0, è azzerato, se lo impostate solo come x:, non è azzerato, è incrementato.

 
VOLDEMAR:

Sì, se lo impostate come x=0, andrà a zero, se lo impostate come x:, non andrà a zero, andrà su.



Dove l'hai letto negli annali?
Motivazione: