-
Why did you post your MT4 question in the
Root /
MT5 General section
instead of the
MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. if(pD_line>80 && D_line<80) if(currenttime!=candletime) SendNotification((string)Period()+Symbol()+"80 Cross, Sell"); candletime=Time[0];
The assignment is not part of any if statement. It always executes. Which means the next if fails. Add proper braces.datetime candletime=0; datetime currenttime=Time[0]; : if(currenttime!=candletime)
Since candletime isn't static, the first if always succeeds.SendNotification((string)Period()+Symbol()+"80 Cross, Sell");
Check your return codes for errors, report them and you would know why. Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.
-
Why did you post your MT4 question in the
Root /
MT5 General section
instead of the
MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - The assignment is not part of any if statement. It always executes. Which means the next if fails. Add proper braces.
- Since candletime isn't static, the first if always succeeds.
-
Check your return codes for errors, report them
and you would know why.
Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.
I don't get any error messages now, but I still don't get notifications.
I do still get the indicator window property warning though.
I don't get any error messages now, but I still don't get notifications.
I do still get the indicator window property warning though.
- Asked and answered. Fix your broken code.
- It has OnTick not OnCalculate. Therefor it is an EA not an indicator. Fix your broken code.
- Asked and answered. Fix your broken code.
- It has OnTick not OnCalculate. Therefor it is an EA not an indicator. Fix your broken code.
;) I think the poster is confused about how braces work and would like you to decorate the code. The snippet provided looks very web scripty... I mean the missing semicolon! I will try suggesting something without the context of knowing what the intended functionality of the code is... like... maybe...
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) { if(currenttime!=candletime) { SendNotification((string)Period()+Symbol()+"80 Cross, Sell"); if(pD_line<20 && D_line>20) { if(currenttime!=candletime) SendNotification((string)Period()+Symbol()+"20 Cross, Buy"); } candletime=Time[0]; } }
Maybe this helps? It needs full volume though, braces don't make sense without full volume.
Barring that, maybe the terminal is low on compiler fluid?
- Asked and answered. Fix your broken code.
- It has OnTick not OnCalculate. Therefor it is an EA not an indicator. Fix your broken code.
;) I think the poster is confused about how braces work and would like you to decorate the code. The snippet provided looks very web scripty... I mean the missing semicolon! I will try suggesting something without the context of knowing what the intended functionality of the code is... like... maybe...
Maybe this helps? It needs full volume though, braces don't make sense without full volume.
Barring that, maybe the terminal is low on compiler fluid?
I think that's helped - but then again I thought it was fixed before too :(
I just want it to send me a notification whenever the D line crosses from below 20, and from above 80.
I think that's helped - but then again I thought it was fixed before too :(
I just want it to send me a notification whenever the D line crosses from below 20, and from above 80.
Then my solution will not work. Take your original code and add braces around all of the lines you want executed for each of your "if" statements. Without braces the "if" statements only affect the next line. That is why your original code keeps setting the "candle time" and "current time" to the same value, both places where you are setting the candle time get executed every time your method runs. I think you might have been attempting to only change the candle time after a notification was sent.
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) if(currenttime!=candletime) (SendNotification((string) Period() + Symbol() + "Sell")) ;} { if(pD_line<20 && D_line>20) if(currenttime!=candletime) (SendNotification((string) Period() + Symbol() + "Buy")) ;} }
This code sends me notifications, but too late. It's sending them a bar too late. I want it to look back 2 closed bars only, with the 0th look-back bar being the current open bar. Also, the buy signals aren't working, just sell signals. Seems like something is blocking it? Maybe bracket problem again?
This code sends me notifications, but too late. It's sending them a bar too late. I want it to look back 2 closed bars only, with the 0th look-back bar being the current open bar. Also, the buy signals aren't working, just sell signals. Seems like something is blocking it? Maybe bracket problem again?
if(true) { Alert("aha!"); Alert("ooh, two statements in one block!"); } Print(Time[0]); Print(TimeCurrent()); ExpertRemove();The mobile version of this site doesn't offer any formatting buttons, so the example isn't going to turn pink.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm new to coding, and not sure why this doesn't work. Need it so send me push notifications when conditions hit.