Can someone help with error codes; expressions not allowed on global scope, function already defined? Thank you for your time.

 

Please look at the attached file for full code.

****

int OnInit()
  {
  return(INIT_SUCCEEDED);
 }
void OnDeinit(const int reason)
  {}
  double TakeProfit,StopLoss,start_price;
  }
int fun_vol()
{
   if(Volume[0]>1)
    return 0;
   else
    return 1;
}


int fun_touch(int stauts)
{
  if(status==1)
  {
  if(StopLoss<Bid&&Bid<TakeProfit)
  return 0;
  else
  return 1;
  }
  else if(Status==-1)
  {
if(StopLoss>Ask&&Ask>TakeProfit)
return 0;
else
return 1; 

else return 10;



if(Bars<=BarsCount) {
return 0;
}
Files:
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Dajuan Lamar Ruff-kelly:

Please look at the attached file for full code.



42       int start(){                Unbalanced parenthesis error is on this line



321     /+------------------------------------------------------------------+                    Unexpected end of program error is on this line

First, add two closing braces "}" to the end of the code; that will alleviate the unbalanced parenthesis and unexpected end of program errors.... and leave you with over 100 other compilation errors to deal with!

My two cents on this code:

1. It's all one function dumped into the start().  Break your code up into logical sections/functions/sub-routines.

2. Instead of massively long if() functions, consider using returns/continues/breaks

e.g.

//Instead of
int start (){

        if (Bars>BarsCount) {
                //lots of code here
                //...
                //..
                // you have to remember that you're inside an if() here
        } // end if()
} //end start()

//try something like
int start (){

        if (Bars<=BarsCount) {
                return 0;
        }
        
        // the rest of your code can go here
        // it's a lot easier to read and debug
} // end start()

3. Lot's has been written already why you shouldn't use Bars to trigger action on new bars.


You've got some work ahead of you to clean up this... good luck.


 
  1. Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.

  2. You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 2016.05.11

 
Dajuan Lamar Ruff-kelly:

Please look at the attached file for full code.

****

Do not double post!

I have deleted your duplicated topic.

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.


 
Keith Watford:

Do not double post!

I have deleted your duplicated topic.

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.


alright, thanks.

 
Scott:

First, add two closing braces "}" to the end of the code; that will alleviate the unbalanced parenthesis and unexpected end of program errors.... and leave you with over 100 other compilation errors to deal with!

My two cents on this code:

1. It's all one function dumped into the start().  Break your code up into logical sections/functions/sub-routines.

2. Instead of massively long if() functions, consider using returns/continues/breaks

e.g.

3. Lot's has been written already why you shouldn't use Bars to trigger action on new bars.


You've got some work ahead of you to clean up this... good luck.


William Roeder:
  1. Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.

  2. You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 2016.05.11

Changes have been made, thank you; however errors are still being displayed. Anyone available to help with next steps.

Files:
 
Dajuan Lamar Ruff-kelly:

Changes have been made, thank you; however errors are still being displayed. Anyone available to help with next steps.

What’s going on with the OnDeinit() function?

 
Scott:

What’s going on with the OnDeinit() function?

you care to elaborate on what you mean specifically?
 
Dajuan Lamar Ruff-kelly:
you care to elaborate on what you mean specifically?

What are the next two lines?  Specifically, the lone closing brace?

 

You seem to struggle with balancing your code blocks { }.

I suggest to take a basic programming course before going on. Start with Java, the syntax is quite similar. There's also a free MQL course at Udemy but I lost the source, look it up yourself.