Topic: Stop trading if daily profit target reached?


I'm new here, and I'm playing around and trading like mad for one week, since I discovered this awesome piece of software! Thanks, Mr. Popov.

Now to my question: Is it possible to construct a logic condition, in such a way that it closes all positions, and doesn't start trading until the next day, whenever a user defined equity profit-percentage over the daily starting balance has been reached?

I'll try to express it in "pseudo" code:


UserDefinedProfitPercent = 2 // Default value, can be changed by user

StartBalance = Balance at the beginning of the day (or when launching strategy)
CloseAllPositions = FALSE
NoTradeTillTomorrow = FALSE

//Check profit so far

IF equity > StartBalance + (StartBalance/100*UserDefinedProfitPercent)

       CloseAllPositions = TRUE
       NoTradeTillTomorrow = TRUE


In other words: I want to make, say, 2% a day, and exit the market if I made it (beware of greed). Otherwise, the trading would continue, but refreshing the StartBalance at the beginning of every new day. This is important, because if you have lost some, you have to lower your expectations.

Thank you.

Re: Stop trading if daily profit target reached?

I am trying to add a "Close_on_Profit_Percent" option to the FST Expert, so the user can define the percentage of profit at which he wants to stop trading.

The idea is, that once the equity is reached, the expert closes all trades, and stops running, or deactivates itself. To continue trading, the user will have to restart it.

If I come up with something, I'll post it here.

Re: Stop trading if daily profit target reached?

Well, I came up with this mod, and  I attach it for your convenience. It's very rudimentary, because my knowledge of MQL4 is very rudimentary too, but I've tested it on demo for more than 24 hours, and it works for me.

Simply set the "Close_On_Profit_Percent" parameter to the desired profit percentage (integer), and once it is reached, the EA will close all open trades (not pending orders, though) of it's current MT4 terminal instance, and then stop running. To continue trading, one must restart the mod. If you leave the percentage at "0", the Expert will run as usual. Keep in mind hovewer, that if you have other EAs running on the same MT4 instance, they might open new trades.
Most of the mod's messages show up on the experts log. I didn't use the "Comment()" function much, because I don't know, how to format the output properly. It always overwrites or is overwritten by the former text.

For now, I don't know, how it behaves when there are several instances of the mod running on different charts. Theoretically, all instances should try to close out orders at more or less the same time, thus causing conflicts and some alerts popping up, but it should work anyway.
I don't know either, what happens if you set a negative percentage. It should work like a kind of universal "stoploss", but as I saw there's already such an option on FSB, it would be kinda nonsense to use it that way, IMHO.

Feel free to mess around with the code. There is a lot of room for improvement, but I'll leave that for you, the expert programmers.

Any comments and/or improvements will be appreciated.

Cheers smile

Post's attachments

MT4-FST Expert mod close on profit.mq4 65.22 kb, 79 downloads since 2010-04-07 

You don't have the permssions to download the attachments of this post.