Tell EA to stop trading for that Day if a Profit or Loss in Pips is reached?
13 replies
birdy70
9 years ago #112314
Hello Mark,
In wich strategy block I could type the rule in, when I wanted to stop trading for that day, if the daily profit or loss is reached +/- 100 Pips for example?
Thanks for your feedback,
Birdy70
Mark Fric
9 years ago #125178
Hello,
EA Wizard doesn’t have function that returns PL for a current day, but you can add it.
1. Open {EA Wizard}/code/CustomFunctions.mq4 and add the following code there:
Mark
StrategyQuant architect
birdy70
9 years ago #125205
Hello Mark,
where I have to type this code in? If I open on my PC the folder C:StrategyQuant/SQEAWizard/Code, I find a file called CustomFunctions.mql4. If I open that file, the Editor of MT4 opens with the window CustomFunctions. When I copy your code in that window, I get 6 error messages after compiling this code!
Please help me.
Birdy70
Mark Fric
9 years ago #125244
Hello,
you have to copy this function to this file, but don’t compile it, it is not a complete EA.
The contents of this file is appended to every EA generated by EA Wizard, so it is a place where we can put custom functions.
So just open EA Wizard, load your strategy, add the custom function there and export to EA. Then it should be compiled without problems.
Mark
StrategyQuant architect
birdy70
9 years ago #126130
Hello Marc,
I am sorry, but I do not understand! In my EAW Folder I find the File CustomFunctions.mql4. I could open this file with MT4 Editor (in MT4) and could paste your Trading Conditions you told me at first. If I open my EAW Strategy details, I could see in the Dialog Box under “Functions” the File “Custom Function”! But how to type your Trading Rule in this Window.
Maybe you could tell me step by step, how I could use this Rule in EAW or tell me another Trading Rule, that tells the EA “stop Trading for that Day, after a profit or Loss of 100 Pips or 100 Euro is reached”!
This would be very great.
Under the Button “Strategy Options” I see some Rules like:
Sum of closed P/L (Magic Number / Orders Count)
TotalProfits
Total Losses
Closed P/L in Pips (Magic Number and trades ago)
Closed P/L in money (Magic Number and trades ago)
Is it not possible, to create with these Options a Rule like:
IF
Sum of closed BUY/SELL Orders is > 100 Pips or 100 Euro (for example)
Then
Stop Trading for that Day
Thanks for your help! I hope it is possible, to create a Trading Rule like this.
Best Regards
Birdy70
Mark Fric
9 years ago #126137
Hello,
when you copied this function to CustomFunctions.mq4 file it will be attached to every new EA, so you can use it in your conditions.
How to do it – normally open your strategy in EA Wizard. Click to add new trading rule, then go to Functions -> Custom Function and in the Function field write: sqGetPLInPipsToday()
Add < 100 comparison and click OK to close the dialog.
That’s all, now save this strategy as an EA and it should work.
Mark
StrategyQuant architect
jastejp
9 years ago #129459
Hello Marc,
I just recently bought EA Wizard after I had compared it with other EA builders, and I am very pleased with it as includes so many pre-built functions to use – I think this sets it apart from your competitors, so please keep up the good work.
Unfortunately, I cannot get the sqGetPLInPipsToday() custom function here to work having spent all day on it. The problem is that trading still continues after I have reached my daily profit target and I don’t know why after I have followed your instructions very carefully. If you look at the attached chart you can clearly see the first trade hits the daily target of 20 pips, but the EA still continues to trade for that day. Could you kindly take a look at the attached files to determine the problem please.
Thanks a lot.
Regards,
Jamie
Mark Fric
8 years ago #129552
ok, I found the problem, there was a mistake in my function, below is the correct one.
Mark
StrategyQuant architect
jastejp
8 years ago #129560
Hi Mark,
Thanks very much.
I will try the new code and I’ll let you know the results. I hope some back testing will show over trading is the problem and the script will fix this.
Jamie
jastejp
8 years ago #129888
Hi Mark,
Sorry for the delay in getting back here.
It is working and doing exactly what I want. Good job!
May I suggest you put useful code like this and others in a forum sticky thread, so they can be easily found.
Thank you,
Jamie
ryanbrignac9764
8 years ago #130754
I have tried your string above and did just as you explained but it keeps trading after number of pips reached. What am i doing wrong with this simple ea creation?
ryanbrignac9764
8 years ago #130768
Guys,
I have literally worked through the night as you can see by my few time posts and just cannot get this.. Can someone please just explain in detail to me what i am doing wrong.
All i am looking for is a simple strategy to learn from. Say go long when EMA 10> EMA 20 AND SHORT WHEN EMA10 < EMA 20.. All i want to do is stop profit at $10 and start the next trading day.. I am exhausted from working through the night and would appreciate if this can get done asap..
boraucak
8 years ago #135674
hello,
first of all, thank you for all this great support on EA Wizard,
this function is great and I desperately needed it.
But a small correction is needed for this code.
tomas262
8 years ago #135684
Yes, that is correct. That one OrderOpenPrice() needs to be replaced by OrderClosePrice()
Viewing 13 replies - 1 through 13 (of 13 total)