Help wanted, please!
-
Hi FxDreema,
I created a new EA designed to close all my open trades once a preset pip level is reached. What I want to do is manually opening several trades at differents charts simultaneously. Then my EA will be operating from a different chart and adding/substracting pips from my previous closed trades as well as my current open ones. In essence, what I want is harvesting a specific pips' target per day (25, 35, 50, etc.). This target is included as a constant manually.
I tried this: https://fxdreema.com/shared/lv4vkjdob
But it doesn't work. Every time I put it on a chart, pips are counted before ANY trade is open!!
I simply can't see why it's not working. Could you please help me?Thank you very much on advance.
-
@isp00rt Hi
FIRST of all, you say you want to Close all trades, after you accumulated a certain amount of Pips from all open trades. Right?IF SO, your condition to close trades, is something TOTALLY DIFFERENT from what you say you want. Your condition to close is a MA Cross!?
Also, you NULL the variables at the MA cross as well, which could happen at any time, when you don't want that.
I don't think you need to null the variables, cause if there are non open trades, MQL should calculate that your variable for Open Pips is 0.
Your condition to Close should probably be something like: CurrentTotalOpenPips >= MyTargetPips
SECOND, you have 2 loops + 2 modify blocks that are identical. I would delete one of loops (to simplify & make the EA faster), and add the 2 formula blocks last in the one loop.
I don't understand all your variables that aren't defined, but the formula you use could also be wrong.
I believe if you start correcting the above first, you should be much closer to the solution you want, or even solve it totally I guess. You need to start there anyway I believe. Let's know how you progress.
Have Fun!

-
@fxfun said in Help wanted, please!:
@isp00rt Hi
FIRST of all, you say you want to Close all trades, after you accumulated a certain amount of Pips from all open trades. Right?Yes, that's exactly what I want.
IF SO, your condition to close trades, is something TOTALLY DIFFERENT from what you say you want. Your condition to close is a MA Cross!?
No. My condition to close is having at least as many pips as I specified as a target. That includes all previous closed trades that were a loss.
Also, you NULL the variables at the MA cross as well, which could happen at any time, when you don't want that.
No, no. There's no MA anywhere. This EA will be operating on a chart and I will manually operate other charts. It will control all my open and closed trades so that the final amount of pips accumulated is at least the one I specified as a target.
I don't think you need to null the variables, cause if there are non open trades, MQL should calculate that your variable for Open Pips is 0.
Interesting. I didn't consider that.
Your condition to Close should probably be something like: CurrentTotalOpenPips >= MyTargetPips
That would count all my current open trades, but I need another variable to count my closed ones (wins and loses).
SECOND, you have 2 loops + 2 modify blocks that are identical. I would delete one of loops (to simplify & make the EA faster), and add the 2 formula blocks last in the one loop.
You're right. My fault! Good idea.

I don't understand all your variables that aren't defined, but the formula you use could also be wrong.
I need 4 variables. ProfitOpen counts the total amount of pips from current open trades. ProfitClose does the same for all my closed trades. ProfitAll is the sum of both previous ones (this one must be at least as big as the target). ProfitTemp is the way to update ProfitOpen and ProfitClose.
I believe if you start correcting the above first, you should be much closer to the solution you want, or even solve it totally I guess. You need to start there anyway I believe. Let's know how you progress.
Have Fun!

Thank you very much for your help. I did your suggested correction, but it still doesn't work.
https://fxdreema.com/shared/hAA1LhAmcMaybe my problem is with variables. I assume that ProfitClose will just sum up all closed trades but I'm not sure how to do that. How can a variable distinguish when a trade is open or closed? Maybe this is why it is failing. What do you think?
-
Hi again,
I redesigned the whole EA and I think I got closer to my goal. You can find it here:
https://fxdreema.com/shared/KCY4ZHjgd. I erased one variable (ProfitTemp) and I now work with just 3 of them and 1 single constant.Now my problem is that variables ProfitOpen (the sum of pips of all open trades) and ProfitClose (same for all closed trades) show exactly the same number no matter what. Additionally, open orders are not detected at all. Apparently the EA is not detecting anu order at all, open or close.
Could you please give me some help?
-
For each trade blocks are working as "loop" for trade conditions which you specified ...
.... maybe this can working, I have not tested it ...
https://fxdreema.com/shared/YSMm3lMKd
.... I added here one condition for situation, when sum of closed trades reached Targed, and when you open new trade, it will be immediately closed because profit sum of all opened trades (with small profit) + history profit still be higher as targed .... so after "close all" is EA terminated ... and you need "check" or something manually, if profit of history trades pass your next trades opening, and you can specify unix timestamp value (it is time in seconds from year 1970 to now), you can use this converter to get right timestamp from specific date:
http://www.onlineconversion.com/unix_time.htm
... ... of course you can somehow automate it all with more condition blocks and another logic/variables/conversions, but that is for loooonger testing and failing and testing and ...
-
Hi Miro1360,
Thank you very much for your suggestion, but it doesn't work. No pips are counted (open or close). Are you sure that "loop" option is correct here? As FxFun said, you put it exactly the same on both open/closed "For each trade" blocks and I'm not sure this is how it should work :(.
Any other suggestion?
-
you know what I dont like? when I investigate time to help somebody, when I am 99% sure that I am doing it right :D, somebody tell me it is not working - and than I test it because I trust somebody that somewhere is mistake because he proved it .... and after my test I see, that it is working
... (I added simple buttons to test it in tester) ... and it is working exactly as I expected and described it in first post .... pips are counting, I just must proved myself ...






yes here with profitOpen:

-
is your MagicNumber set to 0? because 0 is for manually opened trades .. or both EA must have the same magic number if you open trades with one EA and want close it with another EA ...
-
Hi Miro 1360,
Please accept my apoligizes if my words sounded rude. My intention was NOT to underappreciate your time and effort to solve my problem. On the contrary, I have to admit that I am impressed by your knowledge of FxDreema. Once again, let me express my gratitude for your help.
However, I'm afraid there must be something different between your MT4 platform and mine. Could you please confirm you are testing this?: https://fxdreema.com/shared/YSMm3lMKd
I try it at my MT4 platform and this is what I get:

As you can see, the EA is correctly running and three orders are currently open (all of them manually), and yes, the Magic Number is 0. Nonetheless, no pips are counted. All three variables are showing the same 0 result. Maybe I am doing something wrong, but honestly I don't know what :(.
-
if magic is 0, it must normally working ... when it is not, try different broker or new installation of metatrader (or installation of newest version) ...

here is buttons version (the same, only added buttons) https://fxdreema.com/shared/SBxzCtIpb -
try https://fxdreema.com/shared/qncZoz4Kb
set money target ext parameter, close single or multiple trades if target money reached -
@miro1360 said in Help wanted, please!:
if magic is 0, it must normally working ... when it is not, try different broker or new installation of metatrader (or installation of newest version) ...

here is buttons version (the same, only added buttons) https://fxdreema.com/shared/SBxzCtIpbOk. I found the problem. Your code works fine if I set the "Close Time (UNIX)" value at 0.0. Otherwise it doesn't count pips. Probably I'm not inserting the time variable correctly. What values should be understood by the EA?
Thank you in advance.
-
@cucushanji82 said in Help wanted, please!:
try https://fxdreema.com/shared/qncZoz4Kb
set money target ext parameter, close single or multiple trades if target money reachedInteresting, but I need to specify my target as pips, not as profit. I don't see that option elegible at your "Bucket" block. Do you know how could I substitute it, please?
Thank you in advance.
@cucushanji82 said in Help wanted, please!:
try https://fxdreema.com/shared/qncZoz4Kb
set money target ext parameter, close single or multiple trades if target money reached -
Hi again miro1360,
I finally decided to remove the time variable from the EA. I tried it and it works perfectly!

Thank you very much for your help. This forum and people like you are simply priceless. -
interesting problem with that 0.0 ... my metatrader give it automatically as 0.0 ... as input type it can be int instead of double (as I gave) but it should converts automatically ... but good that you have what you want

-
Hi again miro1360,
I found an unexpected problem. Today I began to use your code and my other EAs in other charts and I'm afraid it's not calculating all variables correctly. Let me show you what's happening. Open trades are counted correctly (in pips):

But I don't know why closed trades are all counted as a positive result, including the negative ones:

This means that ProfitAll variable is also wrong. As you can see at the image, ProfitAll counts correctly ProfitOpen and ProfitClose. The problem is that ProfitClose considers all closed trades as positive, no matter they aren't.
I didn't test your code for a long time so far, this is why I didn't see this, sorry :(.
-
what can be wrong ... because for me it is working for sure, I tested it also in demo (not only in tester) ... are you sure that your blocks are in right order, or have you not forget for something?

-
Once again, accept my apologizes. I know what's the problem now. The MT4 platform MUST NOT have any closed trade BEFORE running the EA. If ALL trades of the day are opened AFTER the EA is running, everything works fine. For some reason the EA does not understand negative closed trades existing before it is running. Now I'm changing my MT4 settings so that only the trades closed today are shown at the display so that they will be immediately erased tomorrow.
What could I possibly forget for the EA not to count them correctly?
-
look on my trades when they were closed and than look when I posted my post
.. you can see, that EA recognize trades which were opened before EA was running
.... be sure, that Magic ID of previous closed trades is right ... -
I will test it more carefully and will be back here if any other problem is found. Thank you very much.
