[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 396

 
Sorry, I can't compile a simple-simple line.
double price=(Ask+Bid)/2;
Before I put it in, it compiled to 0. Now...
 
Dimka-novitsek:
Sorry, I can't compile a simple-simple line, it compiled to 0 before I put it in, now it compiles to
.

♪ put it in start ♪
 
Thank you!
 

I can't get the cycle right, on every tick a couple of orders are opened, it should be like this. When a tick comes, variable X is declared inside the loop, accordingly taking value 0.

Then X=number of orders is calculated within the loop, and if X=0 or 1, then they open.

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

You have declared a variable but not zeroed it. Therefore, with every tick it will only grow !!!!!!

That's not the right way to do it.

double price=(Ask+Bid)/2;
 
Thank you!!! I'll reset it now. But all the same, something is wrong, maybe the first loop for some reason does not work and X always remains 0. I cannot even find this out for sure, because Alert ("X",X) does not log anything, only orders with zeros are logged.
 
VOLDEMAR:

You have declared a variable but not zeroed it. Therefore, with every tick it will only grow !!!!!!

That's not right.


You are mistaken here. With every tick this variable is declared anew, hence it equals 0.

It takes it out of hand

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:

This is where you are wrong. With every tick this variable is declared anew, so it equals 0.

Yes, if you set it as x=0, it is zeroed if you just set it as x:, it is not zeroed, it is incremented.

 
VOLDEMAR:

Yes, if you set it as x=0, it will go to zero if you just set it as x:, it won't go to zero, it will go up.



Where in the annals did you read that?
Reason: