Hi all,
Appreciate any help here. I am new to MQL4 and have only been trying this for a week.
I have written a bunch of functions, which I then call, in the start function.
My problem seems to be the order in which things happen or possibly I need a loop, or maybe just the brackets are in the wrong place, but I have tried lots of variations to no avail. Here is a snippet of the code as it stands. (as i say I have tried lots of variations to this already). Basically the Barcheck vaiable seems to then conflict with the next statement.
Barcheck is a function that checks whether price is between a range. If it is in that range then it is true. I then want to take a trade the moment price is greater than that range. The problem seems to be though that as soon as price is greater than the range which is what I need for an entry ( ie if (buyprice > NormalizeDouble(EL,Digits)) - where EL is the EntryLine/top of range) it resets the BarCheck to false, and therefore my criteria is invalid.
I am sure this is just something simple - it always seems to be the case, but I can't figure it out
thanks
Simon
<CODE DELETED>
Please read some other posts before posting . . .
Please edit your post . . . please use the SRC button to post code: How to use the SRC button.
Hi all,
Appreciate any help here. I am new to MQL4 and have only been trying this for a week.
I have written a bunch of functions, which I then call, in the start function.
My problem seems to be the order in which things happen or possibly I need a loop, or maybe just the brackets are in the wrong place, but I have tried lots of variations to no avail. Here is a snippet of the code as it stands. (as i say I have tried lots of variations to this already). Basically the Barcheck vaiable seems to then conflict with the next statement.
Barcheck is a function that checks whether price is between a range. If it is in that range then it is true. I then want to take a trade the moment price is greater than that range. The problem seems to be though that as soon as price is greater than the range which is what I need for an entry ( ie if (buyprice > NormalizeDouble(EL,Digits)) - where EL is the EntryLine/top of range) it resets the BarCheck to false, and therefore my criteria is invalid.
It might be a good idea to show the code for the BarCheck() function.
Sorry - have now posted the code in readable format in my first post.
I have been looking at other breakout type strategies but not found anything that has given me a clue yet.
Sorry - have now posted the code in readable format in my first post.
I have been looking at other breakout type strategies but not found anything that has given me a clue yet.
You need to be careful comparing double values . . . read this thread: Can price != price ?
thanks - yes I had come across that thread and thought that might also be an issue, so I tried to use the formula that WHR suggests - just not sure I am using it correctly, though now at least the EA is taking more trades. I need to step through the error log (which I will do tomorrow as getting late here) to see if that is the root cause of the problem.
Is my interpretation of the formula correct?
if (buyprice >= NormalizeDouble(EL,Digits) //becomes if ((buyprice - EL > Point/2)==0) and if (sellprice <= NormalizeDouble(EL,Digits)) //becomes if((EL - sellprice > Point/2==0)
Is my interpretation of the formula correct?
Don't use the == 0,
EL - sellprice > Point/2
results in a true or false value . . .
Don't use the == 0,
results in a true or false value . . .
ok sure that makes sense, thanks.
So now my price comparison is cleaned up, I still have the issue where as soon as price is greater than the EntryLine, which is the 2nd criteria, it sets the first criteria (Barcheck = true) back to false and therefore not a valid trade criteria.
so what I think I need is something that says whilst Barcheck = 1, and as soon as price is greater then take the trade.
have tried several iterations of while loop now but can't seem to get it to work. Or is it something to do with the way I do the BarCheck in the first place? Would I better off having this as a while loop?
any ideas?
ok sure that makes sense, thanks.
So now my price comparison is cleaned up, I still have the issue where as soon as price is greater than the EntryLine, which is the 2nd criteria, it sets the first criteria (Barcheck = true) back to false and therefore not a valid trade criteria.
so what I think I need is something that says whilst Barcheck = 1, and as soon as price is greater then take the trade.
have tried several iterations of while loop now but can't seem to get it to work. Or is it something to do with the way I do the BarCheck in the first place? Would I better off having this as a while loop?
any ideas?
Looking at your code above, BarCheck() is not dependant on EL so its value does not determine if BarCheck() returns true or false, Print() the variables in the BarCheck() function so you can understand why it is returning false.
Correct there is no dependancy on EL for the BarCheck - I am not expecting there to be. (My thinking was that I could have the entry criteria in a separate function.)
The function Barcheck just makes sure that price has hit the correct zone.
If price has hit this zone, thus validating the criteria (Barcheck = true), then as soon as price is less than the EL (if a buy), or greater than (if sell) I want to place a trade. (The EL happens to be either the top or bottom of the zone).
But the moment price moves out of the zone Barcheck becomes false again, and therefore that part of the criteria is not met.
So what I really need is two criteria to be met.
1. Trade hits the zone - (currently my Barcheck)
2. Trade then is greater than or less then the EL
How can I make these things happen simultaneously? I was thinking some kind of loop maybe? Just not sure how to construct it so it works. (I am guessing here, there could be better ways to do this)
How can I make these things happen simultaneously? I was thinking some kind of loop maybe? Just not sure how to construct it so it works. (I am guessing here, there could be better ways to do this)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
Appreciate any help here. I am new to MQL4 and have only been trying this for a week.
I have written a bunch of functions, which I then call, in the start function.
My problem seems to be the order in which things happen or possibly I need a loop, or maybe just the brackets are in the wrong place, but I have tried lots of variations to no avail. Here is a snippet of the code as it stands. (as i say I have tried lots of variations to this already). Basically the Barcheck vaiable seems to then conflict with the next statement.
Barcheck is a function that checks whether price is between a range. If it is in that range then it is true. I then want to take a trade the moment price is greater than that range. The problem seems to be though that as soon as price is greater than the range which is what I need for an entry ( ie if (buyprice > NormalizeDouble(EL,Digits)) - where EL is the EntryLine/top of range) it resets the BarCheck to false, and therefore my criteria is invalid.
I have added some debugging print statements at the bottom. You can see that the first two lines show Barcheck is true. I then need price to be greater than the EL at 1.02796, but as soon as it is in the third line it resets the Barcheck to false.
I am sure this is just something simple - it always seems to be the case, but I can't figure it out
thanks
Simon