[¡Archivo!] Cualquier pregunta de novato, para no saturar el foro. Profesionales, no lo dejéis pasar. No podría ir a ningún sitio sin ti - 2. - página 396

 
Lo siento, no puedo compilar una línea simple-simple.
double price=(Ask+Bid)/2;
Antes de ponerlo, se compilaba a 0. Ahora...
 
Dimka-novitsek:
Lo siento, no puedo compilar una línea simple-simple, compilaba a 0 antes de ponerla, ahora compila a
.

*Ponlo en marcha*
 
Gracias.
 

No consigo que el ciclo sea correcto, en cada tick se abren un par de órdenes, debería ser así. Cuando llega un tick, la variable X se declara dentro del bucle, tomando respectivamente el valor 0.

Entonces se calcula X=número de pedidos dentro del bucle, y si X=0 o 1, entonces se abren.

//+------------------------------------------------------------------+
//|                                                         блин.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);
  }
//+------------------------------------------------------------------+
 

Has declarado una variable pero no la has puesto a cero. ¡¡¡¡¡¡Por lo tanto, con cada garrapata sólo crecerá !!!!!!

Esa no es la forma correcta de hacerlo.

double price=(Ask+Bid)/2;
 
¡¡¡Gracias!!! Lo reiniciaré ahora. Pero de todas formas, algo falla, quizás el primer bucle por alguna razón no funciona y X siempre se queda en 0. Ni siquiera puedo averiguarlo con seguridad, porque Alert ("X",X) no registra nada, sólo se registran las órdenes con ceros.
 
VOLDEMAR:

Has declarado una variable pero no la has puesto a cero. ¡¡¡¡¡¡Por lo tanto, con cada garrapata sólo crecerá !!!!!!

Eso no es correcto.


Aquí se equivoca. Con cada tic esta variable se declara de nuevo, por lo que es igual a 0.

Es sacarlo de la ecuación.

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:

Aquí es donde te equivocas. Con cada tic esta variable se declara de nuevo, por lo que es igual a 0.

Sí, si lo pones como x=0, se pone a cero si sólo lo pones como x:, no se pone a cero, se incrementa.

 
VOLDEMAR:

Sí, si lo pones como x=0, irá a cero si sólo lo pones como x:, no irá a cero, subirá.



¿En qué lugar de los anales has leído eso?
Razón de la queja: