Simple EA for Percentage Change
-
Hello,
I am trying to create a simple EA that will trade Percentage change per currency. Coming from an Excel environment, I created more than one block trying to achieve the following simple formula:
If Open>close the Percentage change is (Close - Low) / (High - Low) * 100
If Open< Close the Percentage Change is (Close - High) / (High - Low) * 100The EA will execute if a certain percentage is achieved. The default is set to 90%.
The EA is not taking any traded in backtesting. I am attaching my project and if you could help me with two things:
1- How to input these formulas in the (Formula Block) by typing a simple Code.
2-what am I missing or doing wrong.https://fxdreema.com/shared/lMEVJchhc
Thanks in advance
-
@mohamed80 Hi Mohamed, try changing all your candle ID's to 1, 0 is the current candle so it will only ever have a split second to catch the candle close.
In this link is how to do an if statement, NAME & RESULT are variables, what you have written above can be put into MX code but probably easier to store data, if you wat to do a formula in custom code then like XL you put it in brackets as you did above, E.G (1+9)/8)}.
Hope this helps
-
-
Thank you for your reply.
1-With setting Candle ID to 1, won't the EA be trading based on previous candle data? In this case, if I use Daily for the candle's strength, the EA will only rely on the previous candle. But it is not what I am after.
2-I am trying to understand the second part of the reply but I can not so far. Do you mind showing me an example for how to put in Brackets.
3-I will look more into Modify Variables and storing variables.
-
@mohamed80 AFAIK you will not be able to backtest any EA which is dependent of external files (as per your EXCEL). You need to include those data inside the EA code to backtest it.
-
@mohamed80 This is true and previous candle close = current candle open (unless there is a gap).
VARIABLE 1= (VARIABLE 2/100*23+VARIABLE 3);
You can also add if's like this
if(VARIABLE 1 < VARIABLE 2 ) { VARIABLE 3 = 2.00; }you can add multiple lines into the block, I always put anything that needs calculated first above the rest.
if you put this in custom code then the result will be put into VARIABLE 1, This is for MT4 but I think is the same for MT5, the best you can do is candle open >or< current price as at any point within candle 0 there will be no close. If you start a new project and just put different versions of custom code into variable and place tis into a comment block you will be able to see what your code is doing.
In here link text you will see some examples of code I have used, another tip I will use excel if and = formulas to convert 1 line into multiple, I separate the line into cells and then copy/change it all down until I copy all into the custom code, at this point it will go back into 1 line, probably better ways but I don't know them.
Good luck
-
@mohamed80 If this helps, putting a calculation in a calculation:
WINM= (PROFIT_PER_MIN_LOT*(LOT*100));
-
i would advise against using candle 0 for calculations on this because only the open has been established on 0. On C1, you will have a clearly defined OHLC.