'{' - function definition unexpected

 

Hello all, 

A beginners mistake I'm sure, but haven't been able to find a solution on here that's worked.


void OnTick();

double K_line=iStochastic(NULL,0,20,3,5,2,0,MODE_MAIN,1);

double D_line=iStochastic(NULL,0,20,3,5,2,0,MODE_SIGNAL,1);

double pK_line=iStochastic(NULL,0,20,3,5,2,0,MODE_MAIN,2);

double pD_line=iStochastic(NULL,0,20,3,5,2,0,MODE_MAIN,2);

{

if(pD_line > 80 && D_line < 80)

   SendNotification((string)Period()+Symbol()+"80 Cross, Sell");   

if(pD_line < 20 && D_line > 20)

   SendNotification((string)Period()+Symbol()+"20 Cross, Buy");


I get the error message for '{' and can't get rid of it. It says this is the only error. 

Thanks in advance. 

 
This code will (try to) send notifications on every tick. You should somehow define a single notification per bar or per cross.
 

Change where your opening brace begins.

void OnTick()
{
        double K_line=iStochastic(NULL,0,20,3,5,2,0,MODE_MAIN,1);
        double D_line=iStochastic(NULL,0,20,3,5,2,0,MODE_SIGNAL,1);
        double pK_line=iStochastic(NULL,0,20,3,5,2,0,MODE_MAIN,2);
        double pD_line=iStochastic(NULL,0,20,3,5,2,0,MODE_MAIN,2);

Also, please use code formatting when posting code in this forum.

 
kypa:
This code will (try to) send notifications on every tick. You should somehow define a single notification per bar or per cross.
As in every tick after one of the conditions is met? 
Surely not as a notification is only sent if the previous candles meet the conditions? 
Or will it send a notification for every tick in the first period after a trigger?
 
Anthony Garot:

Change where your opening brace begins.

Also, please use code formatting when posting code in this forum.

Thanks, that worked :) Now I just get a warning saying 'no indicator window property is defined, indicator_chart_window is applied'. What should I do for this? 
Should it be an EA instead? As I don't want it to actually draw anything?
 
  1. WTM: As in every tick after one of the conditions is met?

    Yes. You are looking at a signal. Either check once per bar or act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum

  2. WTM: no indicator window property is defined, indicator_chart_window is applied'. What should I do for this?
    Add the property.
              Program Properties (#property) - Preprocessor - Language Basics - MQL4 Reference


Program Properties (#property) - Preprocessor - Language Basics - MQL4 Reference
Program Properties (#property) - Preprocessor - Language Basics - MQL4 Reference
  • docs.mql4.com
Every MQL4-program allows to specify additional specific parameters named #property that help client terminal in proper servicing for programs without the necessity to launch them explicitly. This concerns external settings of indicators, first of all. Properties described in included files are completely ignored. Properties must be specified...
Reason: