Why does this not work? :( - page 2

 
Matthew Colter:
Dyslexia is a difficult thing to deal with, yes. Your "if" statements look like superheroes, I'll never understand why they wear underpants on the outside. I mean, underpants are supposed to be on the inside to brace your junk right? Also, you've effectively destroyed your clock, so checking that the current time is different from the candle time will always be true. You've also given some of your semicolons downs syndrome, they're way downs away from where they should be
.
I'm not sure why they're dangling there like dingleberries
,
but it makes helping you harder for anyone who might be inclined to do so
.
//€
{
! can only conclude that you're bored And(trolololololololol) + nj // ¿por que?
.
}

Has fun with that more of
;
because








.


And you're welcome.
Goodnight.
void OnInit()
  {
   datetime candletime=0;
   datetime currenttime=0;
   currenttime=Time[0];
   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() + "Sell"));
      }    
      Print(Time[0]);
      Print(TimeCurrent());
      if(pD_line<20 && D_line>20)
      {    
       (SendNotification((string) Period() + Symbol() + "Buy"));
      } 
      Print(Time[0]);
      Print(TimeCurrent());
  }

This is what i've got after using trial and error from compiler errors, still wrong?....I guess I should actually learn to code properly

 
WTM:

This is what i've got after using trial and error from compiler errors, still wrong?....I guess I should actually learn to code properly

Move it back to the OnTick method. You'll get notifications as soon as your conditions are met.

It'll spam you with one notification for every tick until your conditions are not met. That is why there was another check for the time in the original code. You'll have to figure out how you want to rate limit the notifications so that you don't get blocked for spamming. Maybe by using a boolean value to tell when the notification was sent, and then waiting five minutes before switching the boolean back. Put the boolean declaration on the line above OnTick so that the program doesn't wipe out the setting on every tick and so that the code inside of the OnTick can read the value.

I leave calculating time as an exercise for you to Google. Search for "mql once per bar" or even "mql time"
 
Matthew Colter:
Move it back to the OnTick method. You'll get notifications as soon as your conditions are met.

It'll spam you with one notification for every tick until your conditions are not met. That is why there was another check for the time in the original code. You'll have to figure out how you want to rate limit the notifications so that you don't get blocked for spamming. Maybe by using a boolean value to tell when the notification was sent, and then waiting five minutes before switching the boolean back. Put the boolean declaration on the line above OnTick so that the program doesn't wipe out the setting on every tick and so that the code inside of the OnTick can read the value.

I leave calculating time as an exercise for you to Google. Search for "mql once per bar" or even "mql time"
int BarsCount=0;

void OnTick()
{
  if(Bars>BarsCount)
  { 
   datetime candletime=0;
   datetime currenttime=0;
   currenttime=Time[0];
   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() + "Sell"));
      }    
      Print(Time[0]);
      Print(TimeCurrent());
      if(pD_line<20 && D_line>20)
      {    
       (SendNotification((string) Period() + Symbol() + "Buy"));
      } 
      Print(Time[0]);
      Print(TimeCurrent());
   BarsCount=Bars;
  }      
}

This is what I found people said worked, but all were talking about EAs, will this work for mine?

 
WTM:

This is what I found people said worked, but all were talking about EAs, will this work for mine?

Yes, that will make it so that your code is only checking for your notification signals once at the beginning of each bar.

You can get rid of the lines that print times, after you watch your experts tab and see that the times only print at the beginning of each bar now. You can also get rid of the candletime and currenttime variables since they're not being used.

You did it! :D Congratulations! It gets easier and easier with practice. There's a pretty good tutorial series about C# that you could watch to learn some fundamental programming concepts. Almost everything in the series directly applies to the MQL language as well.


https://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners

 
Matthew Colter:
Yes, that will make it so that your code is only checking for your notification signals once at the beginning of each bar.

You can get rid of the lines that print times, after you watch your experts tab and see that the times only print at the beginning of each bar now. You can also get rid of the candletime and currenttime variables since they're not being used.

You did it! :D Congratulations! It gets easier and easier with practice. There's a pretty good tutorial series about C# that you could watch to learn some fundamental programming concepts. Almost everything in the series directly applies to the MQL language as well.


https://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners

Ok, thank you for the help :) I'm still not getting notifications when the parameters hit though. Everything loads up fine in MT4, but something must be wrong still.

I'll definitely watch the series though, thanks for recommendation.

 
WTM:

Ok, thank you for the help :) I'm still not getting notifications when the parameters hit though. Everything loads up fine in MT4, but something must be wrong still.

I'll definitely watch the series though, thanks for recommendation.

Notifications don't work in the backtester. Just add a line to print your notification message right after each call to send a notification. Then watch the journal tab in the tester. There will be a timestamp in the right hand column that tells you what time the notification would have been sent in the past.
 
Matthew Colter:
Notifications don't work in the backtester. Just add a line to print your notification message right after each call to send a notification. Then watch the journal tab in the tester. There will be a timestamp in the right hand column that tells you what time the notification would have been sent in the past.
I have it applied to a real account, and still doesn't work :/
 
WTM:
I have it applied to a real account, and still doesn't work :/
Have you put your MQLID into the settings on this site? Have you enabled notifications in your metatrader settings and in the expert settings?

You could create a new empty script and only have it send you a notification. That way you only test you know how to write that one line of code, and have all of your settings in order.
 
Matthew Colter:
Have you put your MQLID into the settings on this site? Have you enabled notifications in your metatrader settings and in the expert settings?

You could create a new empty script and only have it send you a notification. That way you only test you know how to write that one line of code, and have all of your settings in order.
Yeah, I have everything connected. I was getting notifications earlier, but now it's not working
 
WTM: t now it's not working

Then you broke something and can't see your broken code. There are no mind readers here and our crystal balls are cracked.

Reason: