• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 7:27am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 7:27am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

EA "Close all positions at profit target" closed all positions at loss ? 8 replies

Help with EA to close all the open positions in profit pips 0 replies

Mt4 Close Profit positions before Market closed on weekend? 1 reply

Looking for EA to close all Buy Or all Sell trades when in profit 0 replies

Close all pending orders and open orders once they reach profit target 3 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 7
Attachments: EA fix: Close all positions at profit target X
Exit Attachments

EA fix: Close all positions at profit target X

  • Last Post
  •  
  • Page 1 2 3
  • Page 1 2 3
  •  
  • Post #1
  • Quote
  • First Post: Edited at 10:51pm May 11, 2010 12:37am | Edited at 10:51pm
  •  Hedginghog
  • Joined Nov 2009 | Status: Member | 202 Posts
Hello programming experts. This simple EA allows multiple (usually hedged) trades to be closed when an inputed profit target is reached. It is potentially very useful.

However, like other simple EA's of its kind I've tested, once the profit target is reached, it will start to close positions, but then it will stop closing positions when that floating profit drops below the target level (easy to happen if the price is changing or the negative trades are the last to be closed).. so it tends to leave 1 or 2 trades still open.. and then will close them only if the profit target returns again... not a good situation for hedged trades as you remain exposed to the market one way or another..

Can anyone fix this: Once the profit target is hit it should close 100% of open trades and ignore any change to that floating profit level during the execution process.

If anyone can fix this out of the goodness of their heart then well and good, but if someone with a good history on FF (multiple vouchers) wants me to pay them a modest sum for their services then please send me a PM. Thanks!
Attached File
File Type: mq4 close all positions at profit target.mq4   5 KB | 9,378 downloads
  • Post #2
  • Quote
  • May 12, 2010 1:54pm May 12, 2010 1:54pm
  •  tradingviper
  • | Joined Aug 2009 | Status: Member | 137 Posts
Hi Hedgehog,
The code you have should work to close everything unless there is an error - like the price is too close or slippage is too great.

I made a quick change that is more aggressive. If certain positions have errors, it just keeps trying - forever. I believe they will close eventually.

I am not at my computer with MT4, so I was unable to compile it, but I think it is OK. Give it a shot.

Viper
Attached File
File Type: mq4 close all positions at profit target.mq4   5 KB | 9,572 downloads
 
1
  • Post #3
  • Quote
  • May 12, 2010 3:58pm May 12, 2010 3:58pm
  •  forexsaint
  • Joined Jun 2009 | Status: <-That's how u gonna b, in the END! | 1,508 Posts
So the viper is back?
But still at office !
Let's kidnap his Boss
100 Fold Challenge->Interested? ->https://www.forexfactory.com/thread/32152
 
 
  • Post #4
  • Quote
  • May 13, 2010 12:34am May 13, 2010 12:34am
  •  Hedginghog
  • Joined Nov 2009 | Status: Member | 202 Posts
Quoting tradingviper
Disliked
Hi Hedgehog,
The code you have should work to close everything unless there is an error - like the price is too close or slippage is too great.

I made a quick change that is more aggressive. If certain positions have errors, it just keeps trying - forever. I believe they will close eventually.

I am not at my computer with MT4, so I was unable to compile it, but I think it is OK. Give it a shot.

Viper
Ignored
Many thanks for your help Viper. I have run a few tests today in demo mode and it has not yet tripped up in closing all positions - so far so good, and I will keep throwing more scenarios at it over the coming days.
Thanks again, and if there is any way I can ever return the favour, please don't hesitate to let me know.
Cheers.
 
 
  • Post #5
  • Quote
  • May 13, 2010 12:29pm May 13, 2010 12:29pm
  •  tradingviper
  • | Joined Aug 2009 | Status: Member | 137 Posts
No problem at all. Let me know how it works out. If you stumble on a million dollar strategy, just share ;-)

Viper

Quoting Hedginghog
Disliked
Many thanks for your help Viper. I have run a few tests today in demo mode and it has not yet tripped up in closing all positions - so far so good, and I will keep throwing more scenarios at it over the coming days.
Thanks again, and if there is any way I can ever return the favour, please don't hesitate to let me know.
Cheers.
Ignored
 
 
  • Post #6
  • Quote
  • May 17, 2010 5:38am May 17, 2010 5:38am
  •  Hedginghog
  • Joined Nov 2009 | Status: Member | 202 Posts
Quoting tradingviper
Disliked
No problem at all. Let me know how it works out. If you stumble on a million dollar strategy, just share ;-)

Viper
Ignored
Viper - just wanted to let you know that this 'close all' EA is working brilliantly, demo and live. It does not stumble if the floating profit changes during the closure process, unlike all the others I tried.

Great work - thanks again.

Cheers
 
 
  • Post #7
  • Quote
  • Jul 6, 2010 12:12pm Jul 6, 2010 12:12pm
  •  dancingphil
  • Joined May 2009 | Status: Member | 667 Posts
TradingViper - seems you are the gun at closing multiple trades while in profit. Perhaps you can help with this need.

The situation is that my EA may have 50+ trades open - especially during sideways movements, say 20-30 Buys and 20-30 sells.

But when a breakout signal comes in, I want only the profitable "other side" trades to close, not to close the open trades which are already in favour of the breakout.

That is, I don't use take profit or stop loss settings. A new signal will come in saying "breakout" north or south, and the profitable "wrong way bets" need to be closed.

Remaining "wrong way bet" trades get picked up later during retracement etc - I am not worried about the dregs left over.

I want to whack this "close in profits" code into my existing EA.

If this can be done, then the profitable trades opposing the breakout can be closed out sweetly, and then trades on the right side of the breakout get more leverage.

I don't see this as a seperate EA, I see it is a Take Profit upon signal method within the existing EA.

Hope you can help
 
 
  • Post #8
  • Quote
  • Jul 7, 2010 1:25am Jul 7, 2010 1:25am
  •  tradingviper
  • | Joined Aug 2009 | Status: Member | 137 Posts
Hey Phil,

This sounds simple enough. Point me to where the EA is (all files) and I will add this for you. Should only take a few minutes, assuming the EA is written well enough for me to decipher where to add this code...

Keep Dancing,
Viper

Quoting dancingphil
Disliked
TradingViper - seems you are the gun at closing multiple trades while in profit. Perhaps you can help with this need.

The situation is that my EA may have 50+ trades open - especially during sideways movements, say 20-30 Buys and 20-30 sells.

But when a breakout signal comes in, I want only the profitable "other side" trades to close, not to close the open trades which are already in favour of the breakout.

That is, I don't use take profit or stop loss settings. A new signal will come in saying "breakout" north or south, and the profitable...
Ignored
 
 
  • Post #9
  • Quote
  • Jul 13, 2010 6:09pm Jul 13, 2010 6:09pm
  •  dancingphil
  • Joined May 2009 | Status: Member | 667 Posts
Hey Viper Trading,

Sorry for the late reply - your conditions have been hard to meet as I am new to this coding racket stuff.

My bot is not so mature that it would be ready for your "Cool Hand Luke" stuff (old Paul Newman film, showing my age I guess).

I think I have sorted the Take Profit by Order Type issue. Per the below pic,

I added

extern int minTPbuy
extern int minTPsell

at the top of my code, and then added
Inserted Code
 
 
            if (Order == SIGNAL_CLOSESELL && ( OrderProfit() >= minTPsell) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

As an example of closing sells at a minimum profit.

Actually, I find the closing quite functional.

I AM VERY CURIOUS about all the "void" stuff in your EA and that of the OP.

What's this void code about?
Attached Image (click to enlarge)
Click to Enlarge

Name: tradingviper 1.JPG
Size: 139 KB
 
 
  • Post #10
  • Quote
  • Jul 20, 2010 4:17am Jul 20, 2010 4:17am
  •  dnabrasil
  • Joined Jun 2010 | Status: 18 pips per day ---> 100% per month | 485 Posts
Quoting tradingviper
Disliked
Hi Hedgehog,
The code you have should work to close everything unless there is an error - like the price is too close or slippage is too great.

I made a quick change that is more aggressive. If certain positions have errors, it just keeps trying - forever. I believe they will close eventually.

I am not at my computer with MT4, so I was unable to compile it, but I think it is OK. Give it a shot.

Viper
Ignored
hi viper..

i've a question,

i paste the scripts in my experts/scripts folder, but, how can i choose TP?
 
 
  • Post #11
  • Quote
  • Mar 6, 2011 11:41pm Mar 6, 2011 11:41pm
  •  saifulwan
  • | Joined Mar 2011 | Status: Junior Member | 2 Posts
Hi.....


can you help me


Close All Lot (instant and pending order) when current price retracement and achieving to any take profit . And close all lot for this pair only. Not yet for the other pair. Because we have put on separate condition



Thank You.
 
 
  • Post #12
  • Quote
  • Mar 30, 2011 12:13am Mar 30, 2011 12:13am
  •  nahnufrx
  • | Joined Sep 2009 | Status: Junior Member | 1 Post
Quoting Hedginghog
Disliked
Hello programming experts. This simple EA allows multiple (usually hedged) trades to be closed when an inputed profit target is reached. It is potentially very useful.

However, like other simple EA's of its kind I've tested, once the profit target is reached, it will start to close positions, but then it will stop closing positions when that floating profit drops below the target level (easy to happen if the price is changing or the negative trades are the last to be closed).. so it tends to leave 1 or 2 trades still open.. and then will close...
Ignored
i fail to download the ea. can anyone send me through email>>> [email protected]
 
 
  • Post #13
  • Quote
  • Apr 2, 2013 10:11pm Apr 2, 2013 10:11pm
  •  cidekdc
  • | Joined Apr 2013 | Status: Junior Member | 1 Post
Quoting tradingviper
Disliked
Hi Hedgehog, The code you have should work to close everything unless there is an error - like the price is too close or slippage is too great. I made a quick change that is more aggressive. If certain positions have errors, it just keeps trying - forever. I believe they will close eventually. I am not at my computer with MT4, so I was unable to compile it, but I think it is OK. Give it a shot. Viper {file}
Ignored
Hi Sir Viper! Will you be able to re-code and compile it to .LUA so I can use it with FXTS Marketscope Strategy? Credits to hedginghog as this is one strategy I am looking for for ages.

Thank you!
 
 
  • Post #14
  • Quote
  • Dec 12, 2013 3:13pm Dec 12, 2013 3:13pm
  •  Mroue26
  • | Joined Dec 2013 | Status: Member | 304 Posts
Quoting tradingviper
Disliked
Hi Hedgehog, The code you have should work to close everything unless there is an error - like the price is too close or slippage is too great. I made a quick change that is more aggressive. If certain positions have errors, it just keeps trying - forever. I believe they will close eventually. I am not at my computer with MT4, so I was unable to compile it, but I think it is OK. Give it a shot. Viper {file}
Ignored
MR TRADINGVIPER YOU ARE MY HEROOOOOOOOOOOOOOOOO... thanx alot for ur effort and for sharing this amazing EA, ive been lookin around for a long time and i have dozens just to do exactly as this 1 does.. all expert advisors didnt close exactly on the same targeted price, my broker have HUGE take profit conditions now im done with it by this great tool..

i wanted to ask if u can make another copy of it but targeting the profitable trades ammount by PIPS not the value (bcz u know 1 pip for silver is different than 1 pip of EUR/USD).. all i want is to define profits by How many pips in profit
i.e: (2 pips) not ($10.0) is it possible please ?????
 
 
  • Post #15
  • Quote
  • Dec 12, 2013 7:52pm Dec 12, 2013 7:52pm
  •  fxdaytrader_
  • Joined Jan 2011 | Status: UberTroll | 1,847 Posts
pls. try attached, I extended the onscreen-comment also
2 new external vars added, should be self-explanatory ...
Attached File
File Type: mq4 Close all positions at profit target v1.1.mq4   8 KB | 5,855 downloads
PM me with coding requests and I'll probably put you on my ignore list
 
1
  • Post #16
  • Quote
  • Dec 25, 2013 8:15am Dec 25, 2013 8:15am
  •  Mroue26
  • | Joined Dec 2013 | Status: Member | 304 Posts
Quoting fxdaytrader_
Disliked
pls. try attached, I extended the onscreen-comment also 2 new external vars added, should be self-explanatory ... {file}
Ignored
thank you so much @fxdaytrader_ i just saw the reply i swear i didnt get an email that some1 replied to the post thank you so much for ur help
 
 
  • Post #17
  • Quote
  • Jan 8, 2014 11:51pm Jan 8, 2014 11:51pm
  •  huckyfu
  • | Joined May 2013 | Status: Member | 8 Posts
If there a simple way to make this work at a certain loss target?

example, if equity <= 800 then close all positions. I tried to change the ">=" to "<=" in the mql file and it didn't work.

" if(BuyProfit+SellProfit <= ProfitTarget) CloseAll(); "

it just closed any trades straight away like the original.

Thank you so much!
 
 
  • Post #18
  • Quote
  • Oct 31, 2014 5:09pm Oct 31, 2014 5:09pm
  •  taru
  • | Joined Jul 2013 | Status: Member | 263 Posts
Quoting fxdaytrader_
Disliked
pls. try attached, I extended the onscreen-comment also 2 new external vars added, should be self-explanatory ... {file}
Ignored
I've been looking for an EA to close a basket of trades at profit in pips. This EA is great but it considers ALL the trades on the account to calculate the profit. Can anyone modify the code so that the EA will close trades only on one pair.
The trader IS the holy grail.
 
 
  • Post #19
  • Quote
  • May 12, 2015 4:09pm May 12, 2015 4:09pm
  •  Rolas
  • | Joined Mar 2015 | Status: Member | 13 Posts
Quoting tradingviper
Disliked
Hi Hedgehog, The code you have should work to close everything unless there is an error - like the price is too close or slippage is too great. I made a quick change that is more aggressive. If certain positions have errors, it just keeps trying - forever. I believe they will close eventually. I am not at my computer with MT4, so I was unable to compile it, but I think it is OK. Give it a shot. Viper {file}
Ignored
Than you,you are great. Cheers
logitech
 
 
  • Post #20
  • Quote
  • Aug 5, 2015 1:43pm Aug 5, 2015 1:43pm
  •  holdocu82
  • | Joined Aug 2015 | Status: Member | 18 Posts
Quoting fxdaytrader_
Disliked
pls. try attached, I extended the onscreen-comment also 2 new external vars added, should be self-explanatory ... {file}
Ignored
That's exactly what I have been looking for but close target should be the price, not money or pips. Just one price target. Is it possible?
 
 
  • Platform Tech
  • /
  • EA fix: Close all positions at profit target X
  • Reply to Thread
    • Page 1 2 3
    • Page 1 2 3
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022