Cleaning Code

 

Hi Guys

I've finally finished my EA/Bot but (even though I have been anal about keeping it clean) I'm wondering if anyone can point me in the right  direction as to how I can clean the code. ie. get rid of variables that are not used etc.

It's just over 8000 lines so I would hate to go over it line by line...and it works perfectly (16% this first week of Jan).... but I feel that I need to clean it up...

 OR 

Should I just let sleeping dogs lie.... 

I'd be interested in any comments on this....

 

For me it would be horrible, if my code isn't clean. i have a big set of rules for organisation, style and typing. I need all these rules to easily understand my written code weeks or months later. And this is necessary because my EA is only 88 lines, but my funcLibs are also about 8000 lines.

 

You write, your EA works fine, so I'm not sure if you should clean it up.

But if you would do any further work on it some times ago, you should clean it up. 

 
Mike.T:

Hi Guys

I've finally finished my EA/Bot but (even though I have been anal about keeping it clean) I'm wondering if anyone can point me in the right  direction as to how I can clean the code. ie. get rid of variables that are not used etc.

It's just over 8000 lines so I would hate to go over it line by line...and it works perfectly (16% this first week of Jan).... but I feel that I need to clean it up...

 OR 

Should I just let sleeping dogs lie.... 

I'd be interested in any comments on this....

Sorry... variables are easy... I just delete them and see if I get error messages....

 I'm just wondering if there are any other things you guru's do when you are finished with your code to optimize it...? 

 
GoS:

For me it would be horrible, if my code isn't clean. i have a big set of rules for organisation, style and typing. I need all these rules to easily understand my written code weeks or months later. And this is necessary because my EA is only 88 lines, but my funcLibs are also about 8000 lines.

 

You write, your EA works fine, so I'm not sure if you should clean it up.

But if you would do any further work on it some times ago, you should clean it up. 

Thanx Gos.... 

Ja... I don't think I'm going to mess with the code.... I'll sort out the variables and put up with the odd function that is not being used.... the rest is pretty clean

I'd be interested in your rules though... I kinda immersed myself with this and did not start off with a set of rules... I'm sure there is loads of this info on the internet... so... I guess I should look into it further...

 Anyways... thanx for your comments 

 
The best in my opinion would be to re-write the whole code.
 
gooly:
The best in my opinion would be to re-write the whole code.
Hehehehhh... everyone's a comedian these days....
 
Mike.T:
Hehehehhh... everyone's a comedian these days....

So I take it that's a NO Gooly.... We need to plan and follow coding rules.... No quick fixes....

Ok... Roger that.... I was just checking....

Thanx    and thanx for the laugh.... I'm still cracking up...

Cheers 

 

Maybe I should put it this way....

Out of all my code....I have 23 warnings.... 

Most of those warnings are from declaring a variable within a Function....and then declaring the same variable at the beginning of my code... which I have to do otherwise I get an error for NOT declaring that variable... The variable in question (in this eg) is "int BarNumberLong"

 

//+------------------------------------------+
//| BAR Number LONG Function                 |
//+------------------------------------------+
int Bar_Number_Long(int BarNumberLong)
{
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);
      }
   }
}
return(BarNumberLong);
}

 I then also declare the variable globally.... because I HAVE TOO, otherwise I get an error for NOT declaring it (as mentioned above)

 When I do that (I have no option but to declare it otherwise I get an Error) ... I get  this:

 

 declaration of 'BarNumberLong" hides global declaration at line 195    Rhythm_V8.3.mq4 2905    25


Phew.... I guess it's not a train smash but I am trying to get my code to show no errors and no warnings... 

...and for the life of me I have not been able to find a solution online... 

Can anyone point me in the right direction here.... without getting me to re-write ALL the code...

I'd appreciate some help...

 

Thanx 


 

gooly's suggestion is not as funny as you think.

After more than two years of development, the status of my ea is version 3; means: at the moment, i rewrite it for the second time.

And i don't do that for fun. MQL is growing, my knowledge is growing, the ea does some crazy behaviour or simply i want to add some failsave to my ea and so on...

Sometimes it is necessary to restruct all that code to get a better view.

 

Can anyone point me in the right direction here.... without getting me to re-write ALL the code...

I'd appreciate some help...

If you declare a variable at global scope, you must NOT put it as parameter for any function.

If BarNumberLong is global, than it is accessable inside the function-scope.

 
GoS:

If you declare a variable at global scope, you must NOT put it as parameter for any function.

If BarNumberLong is global, than it is accessable inside the function-scope.

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 

Reason: