I'm new to this EA thing...

 
 I am trying to write an EA but I have a problem. 
I want it to look at stochastic on multiple timeframes. 
So I wrote my "if" statement with two iStochastic sentences with 4h and daily chart selected. And with && between the two, but when I backtest I look at the Stochastic and it will buy before its under 20! 

if((iStochastic(NULL,PERIOD_H4,5,3,3,MODE_SMA,1,MODE_MAIN,0)<20)&&(iStochastic(NULL,PERIOD_D1,5,3,3,MODE_SMA,1,MODE_MAIN,0)<20)) 

Help!
 
fly2hi:
 I am trying to write an EA but I have a problem. 
I want it to look at stochastic on multiple timeframes. 
So I wrote my "if" statement with two iStochastic sentences with 4h and daily chart selected. And with && between the two, but when I backtest I look at the Stochastic and it will buy before its under 20! 

if((iStochastic(NULL,PERIOD_H4,5,3,3,MODE_SMA,1,MODE_MAIN,0)<20)&&(iStochastic(NULL,PERIOD_D1,5,3,3,MODE_SMA,1,MODE_MAIN,0)<20)) 

Help!
The "if" statement is right. But don't forget that you watch (both on H4 and D1) the current bar and the current bar isn't finished (The Stochastics are changed until the current bar is finished).
 
Petr Nosek:
The "if" statement is right. But don't forget that you watch (both on H4 and D1) the current bar and the current bar isn't finished (The Stochastics are changed until the current bar is finished).
But why would it place a trade before the two criteria are met?
 
fly2hi:
But why would it place a trade before the two criteria are met?

the if statement isn't right .

iStochastic : The function returns the handle of the Stochastic Oscillator indicator and not the value.

You need to use copyBuffer to get the values.

 
Bilal Said:

the if statement isn't right .

iStochastic : The function returns the handle of the Stochastic Oscillator indicator and not the value.

You need to use copyBuffer to get the values.

This of course applies to MQL5, but not to MQL4. But I did not expect it that this is a part of the MQL5 code.
 
fly2hi:
But why would it place a trade before the two criteria are met?
I don't see your code even I don't know if it is MQL5 or MQL4. Assuming it is MQL4 then it could happen. During lifetime of the current bar the Stochastic could fall bellow 20 and then go back above 20. At the moment when the Stochastic was below 20 the criteria were met but if you watch the chart backwards you don't see it. 
 
fly2hi:

So I changed my code a little bit to see if I could get around doing stuff I don't already know. And now I'm also getting the errors Unbalanced Parenthesis, and Unexpected End of Program... And I've tried adding a close parenthesis in multiple places but cant find where to place it. (I have an extra "{" right before "Get Handles") Any Help would be Great! Thanks

I've seen your code and now I'm sure you need help because you are really confused. You tried to mix MQL4 and MQL5. It will never work. I suppose you want to edit an old code that someone else created. You should go back to the original code and persuade someone to edit the code by your rules.
 
Petr Nosek:
I've seen your code and now I'm sure you need help because you are really confused. You tried to mix MQL4 and MQL5. It will never work. I suppose you want to edit an old code that someone else created. You should go back to the original code and persuade someone to edit the code by your rules.
Hahaha ok thanks I'll do that XD thank you guys for the help XD
Reason: