Cleaning Code

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
58
Mike.T 2016.01.10 03:39 #
 
Mike.T:

That's exactly  my point GoS...... but thanx....

Unfortunately.... U don't have a clue as to what I'm talking about...

But I appreciate your input....

Thanx 

  

That is my frustration...
avatar
58
Mike.T 2016.01.10 03:56 #
 
Mike.T:
That is my frustration...

That's exactly my issue....

 

avatar
Moderator
3416
GumRai 2016.01.10 04:35 #
 
//+------------------------------------------------------------------+//+------------------------------------------+
//| BAR Number LONG Function                 |
//+------------------------------------------+
int Bar_Number_Long(int BarShiftLong)
{
datetime BarTimeLong;
int      lastTicketLong = -1; // None open.
datetime lastTimeLong = 0;
    
   for(int i=OrdersTotal()-1; i>=0; i--)
   {
   
   if (OrderSelect(i, SELECT_BY_POS)==true
       && OrderType() ==  OP_BUY
       && OrderSymbol() == Symbol()
       && OrderMagicNumber() == MagicNumberLong
       && OrderOpenTime() > lastTimeLong) 
   {
            lastTimeLong = OrderOpenTime();
         
   
   if(OrderSelect(i, SELECT_BY_POS)==true
      &&  OrderType()         ==  OP_BUY
      &&  OrderOpenTime()     >=  lastTimeLong
      &&  OrderTicket()       >   lastTicketLong
      && OrderMagicNumber() == MagicNumberLong
      &&  OrderSymbol() == Symbol())
      {
      BarTimeLong=OrderOpenTime();   
      BarShiftLong = iBarShift(NULL, 0, BarTimeLong);
      }
   }
}
return(BarShiftLong);
}

Change the variable name in your function to one that has not been used elsewhere, then you will not get the warning

 

 

 

avatar
58
Mike.T 2016.01.11 00:38 #
 
GumRai:

Change the variable name in your function to one that has not been used elsewhere, then you will not get the warning

 

 

 

Thanx GumRai.... but it's unique to this function.... so I'm not 100% sure how that helps.... If I don't declare the variable in the global context then I get an Error.... Maybe I should just forget about it.... It works.... soooo....let sleeping dogs lie.... it's just frustrating...
avatar
58
Mike.T 2016.01.11 00:41 #
 

....I'd like to work this out.... but thanx anyway
avatar
Moderator
3416
GumRai 2016.01.11 06:57 #
 
GumRai:

Change the variable name in your function to one that has not been used elsewhere, then you will not get the warning

Mike.T:
Thanx GumRai.... but it's unique to this function.... so I'm not 100% sure how that helps.... If I don't declare the variable in the global context then I get an Error.... Maybe I should just forget about it.... It works.... soooo....let sleeping dogs lie.... it's just frustrating...

It cannot be unique to the function or you would not get the warning.

We don't know how the function is called, but if it is something like this

int BarNumberLong; //Declared Globally
BarNumberLong=Bar_Number_Long(BarNumberLong); //In main code

 Then you will get the warning because the variable is NOT unique to the function

In a case such as this, there is no need to have a parameter in your function and just

//BarNumberLong=Bar_Number_Long(BarNumberLong); //In main code
Bar_Number_Long();

 as the global variable will be given a new value in the function if necessary

//+------------------------------------------+
//| BAR Number LONG Function                 |
//+------------------------------------------+
void Bar_Number_Long()
{
datetime BarTimeLong;
int      lastTicketLong = -1; // None open.
datetime lastTimeLong = 0;
    
   for(int i=OrdersTotal()-1; i>=0; i--)
   {
   
   if (OrderSelect(i, SELECT_BY_POS)==true
       && OrderType() ==  OP_BUY
       && OrderSymbol() == Symbol()
       && OrderMagicNumber() == MagicNumberLong
       && OrderOpenTime() > lastTimeLong) 
   {
            lastTimeLong = OrderOpenTime();
         
   
   if(OrderSelect(i, SELECT_BY_POS)==true
      &&  OrderType()         ==  OP_BUY
      &&  OrderOpenTime()     >=  lastTimeLong
      &&  OrderTicket()       >   lastTicketLong
      && OrderMagicNumber() == MagicNumberLong
      &&  OrderSymbol() == Symbol())
      {
      BarTimeLong=OrderOpenTime();   
      BarNumberLong = iBarShift(NULL, 0, BarTimeLong); //Global variable is re-valued here, if necessary
      }
   }
}
return;
}

 

 .

 

 

avatar
58
Mike.T 2016.01.15 20:25 #
 
GumRai:

It cannot be unique to the function or you would not get the warning.

We don't know how the function is called, but if it is something like this

 Then you will get the warning because the variable is NOT unique to the function

In a case such as this, there is no need to have a parameter in your function and just

 as the global variable will be given a new value in the function if necessary

 

 .

 

 

Thanx GumRai

I'm still getting Error messages when I try that route.... but I now understand why I am getting the Warning messages... I'll do some research on the Error messages that I am getting and will try to sort this out...

Thanks for pointing me in the right direction...

 Cheers 

Back to topics list   | 1 2  

To add comments, please log in or register