Buy a EUR pair when Conditions are met from three Pairs
-
Hello,
I have a very simple EA to build on later.
The EA will buy EURUSD if the price of each pair (EURUSD, EURGBP, EURJPY) is above SMA 5.
I created this for MT5 https://fxdreema.com/shared/ggHkL4Fjb but is not working in backtesting.
I just created a condition for each symbol to be above its SMA 5.
Can someone comment on what is missing?
Thanks
-
@mohamed80 As is your conditions are never true because for example GBPUSD C1 MA will never be above GBPUSD C1 MA because it is always the same, instead of pass you need a no position block, this prevents more than 1 trade being placed. in these links you will see the two options to achieve what yo desire, 1 is to check if current price is above MA, 2 is to check candle has closed (or another position) above MA.
Haven't tested but either of these should work.
-
How silly of me! It might have been after spending so many hours on numerous projects.
Thank you for correcting me.
-
@mohamed80 No problem, I quite often find if I spend too long, any problems are found easily after a sleep
-
I created this EA that would trade on one EUR pair based on the overall bullish score of EUR.
The calculation is simple. For each pair: (current - Low) / (High - Low) *100. Then averaging all values and assigning a threshold.I am not sure what is wrong with the structure I made as it is not executing any trades in backtesting.
https://fxdreema.com/shared/dqieJ3eYd
Thanks,
-
@mohamed80 Hi Mohamed, I will gladly go over this and see what I can, first though the symbols are correct in being strings but, to me there was no string in the constant? is this how it is for you? Also put variables/constants in a comment block then you can see if correct result is within, allows for easier fault finding.
-
@jstap said in Buy a EUR pair when Conditions are met from three Pairs:
@mohamed80 Hi Mohamed, I will gladly go over this and see what I can, first though the symbols are correct in being strings but, to me there was no string in the constant? is this how it is for you? Also put variables/constants in a comment block then you can see if correct result is within, allows for easier fault finding.
I used the parameter (Candle Total Size in Pips) to give me the same value as (High - Low).


-
@mohamed80 That's ok but the currency constants need to have something like EURUSD, otherwise the calculation for each formula cant happen, it uses the string to find the candle for the specific market. If you change this depending on what you are doing, put an example it so when I look I can reference why it's not working.
-
I wanted to input the pairs myself in the EA when applying it on a chart or for backtesting.
However, I now have inserted the symbols inside the blocks and removed all strings so there is no referencing for symbols.
Still, it is not working.
When you have some time, please check the formulas for the first two blocks (pairs) and that will suffice for the overall logic.
Thanks
-
@mohamed80 Ok I will have a look.
-

Your suggestion to use the comments helped a lot to track down what is wrong.
First, the Total Size of the Candle in Pips was causing a problem. So I substituted it with raw calculation (High - Low).
And a second block for (Current - Low). Lastly, a third block for the calculation (Current - Low) / (High - Low) * 100.I can now continue with the project. I wish if I knew how to write simple Arthimetic formulas in the Coding Block. I would use much fewer Blocks.
BTW: How to round numbers in the Comments? and Also to get rid of the last number next to the readings?
-
In case I want the EA to check the Pair so I can inverse it. For example, I want to inverse AUDUSD to read as USDAUD.
Is there a block to check the (string constant) and reverse the value? I mean to be done automatically.
Thanks -
I am thinking that to be more practical I need to customize an indicator for my currency strength formula. I will hire a coder.
Should I ask the coder to output buffers in numbers or in color or both? What buffers are easier for FX Dreema to pick?
-
@mohamed80 Sorry I haven't been able to check, my mt5 has been busy optimising, FX uses numbers, the colours just help you know which buffer to choose, you can have them all black, works fine but difficult to remember which number to use when you have lots.
-
@mohamed80 I can help you with most of this, I am not a coder and what I know is self learnt. In here you will see a few examples of what you can do, anything your not sure about just ask, a simple formula would be variable1=(132+(45-5/2)); link text
I will also say that I try not to use too many formula blocks, previously I have found unexpected results, results that are corrected by using custom code, I still use formula blocks just not as many as I used to.
-
and dont forget that most blocks can be adjusted at the bottom of each after you expand the adjustment section. Formulas can be entered right into that block.
-
Thanks for your help
So lets say I want this simple formula: (Close (0) - Low(0) )/(High (0) - Low (0)) and assign it to a variable and a specific pair.
I will type seven of them for example.
Where do you think I should start from for such basic formulas? I mean to learn how to use the minimum needed.I am more of an Excel user and never coded anything in MQL4.
-
each candle parameter that you want would need to be made into a variable, then use that named variable in place just like that formula.
side note, you can't refer to C0, high, low, and close because they have not been defined. Only C0 open is defined logically. Only on C1 do you have a OHLC.
You can use high and low cross, but i typically use Ask or Bid of market properties if I need immediate entries
-
@mohamed80 Tipsy is correct there is a candle 0 close but it happens at the same time as the new candle opens, in code you can specify C0 close (I am unsure how to do it) but it potentially moves until the candle closes, using C1 for everything, and then C0 open for C1 close is the best way. In this link you can see how I would achieve this link text
-
Iam calculating strength over a group of pairs by averaging the strength of seven pairs per currency and then conditioning based on a threshold.
EX: if EUR > 80 percent and USD < 20 percent then Buy EURUSD.