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

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

FP Markets - Hidden Gem for Traders? 22 replies

Nice EMA Cross Indicator...needs slight work please 7 replies

Central Banks and Big Players: Slight change in code reqd 7 replies

Slight mod needed for session indicator 4 replies

A Gem from Merlin 21 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 12
Attachments: Gem of an EA needs a slight change
Exit Attachments
Tags: Gem of an EA needs a slight change
Cancel

Gem of an EA needs a slight change

  • Last Post
  •  
  • Page 1 23 4
  • Page 1 23 4
  •  
  • Post #1
  • Quote
  • First Post: May 11, 2010 7:25am May 11, 2010 7:25am
  •  Toothman
  • | Joined Aug 2006 | Status: Member | 1,242 Posts
This EA http://cdn.forexfactory.com/images/attach/mq4.gif swb grid 4.1.mq4
takes advantage of small retraces in price. I've only back tested on the EUR/USD but it does well even through the chaos of Oct. of 2008. Limit your lot size and don't go more than 7 or 8 levels. I need a change in the code however to make this EA more profitable. As it's coded now, at TP it closes the largest lot first ( that's good) but then it pokes around closing the rest of the open trades. It looks like it closes one trade at a time with each tic in price. While it's poking around closing trades, price is moving against you a lot of the time and this cuts into your profit for the group of trades. Could someone alter the code to close all open trades at TP at exactly the same time at the same price. thank you
  • Post #2
  • Quote
  • May 11, 2010 5:29pm May 11, 2010 5:29pm
  •  CodeMeister
  • Joined Sep 2009 | Status: Making Code While Making Pips | 1,672 Posts
I took a look at the code and it is attempting to close all orders as quickly as possible once the proper conditions are met. An order can't be closed until the server responds and this may be why you think the program is waiting for the next tick. In fact it might happen on the next tick or several ticks later. Sorry, there are limitations in MT4 and the code is doing the best it can to handle the situation.
 
 
  • Post #3
  • Quote
  • May 11, 2010 6:06pm May 11, 2010 6:06pm
  •  Ronald Raygun
  • Joined Jul 2007 | Status: 32 y/o Investor/Trader/Programmer | 5,016 Posts
A potential alternative is to set the SL/TP such that the profit conditions are met when those are hit.
 
 
  • Post #4
  • Quote
  • May 11, 2010 6:47pm May 11, 2010 6:47pm
  •  CodeMeister
  • Joined Sep 2009 | Status: Making Code While Making Pips | 1,672 Posts
Quoting Ronald Raygun
Disliked
A potential alternative is to set the SL/TP such that the profit conditions are met when those are hit.
Ignored
RR's idea should work and I think the existing code allows for it if you turn off Stealth Mode and set Use_SL_and_TP.
 
 
  • Post #5
  • Quote
  • May 11, 2010 7:05pm May 11, 2010 7:05pm
  •  ecTrade
  • | Joined Jul 2009 | Status: Member | 1,163 Posts
Is it closing the last order first, based upon the TP value? If so, you can set it up to modify all other orders to the same TP value, and that should take care of it.
 
 
  • Post #6
  • Quote
  • May 11, 2010 7:20pm May 11, 2010 7:20pm
  •  Toothman
  • | Joined Aug 2006 | Status: Member | 1,242 Posts
Quoting ecTrade
Disliked
Is it closing the last order first, based upon the TP value? If so, you can set it up to modify all other orders to the same TP value, and that should take care of it.
Ignored
That's what Im after exactly. Have the EA modify all open trades to close at the same TP value. Yes it is closing the last trade first
 
 
  • Post #7
  • Quote
  • May 11, 2010 7:27pm May 11, 2010 7:27pm
  •  Toothman
  • | Joined Aug 2006 | Status: Member | 1,242 Posts
Quoting Ronald Raygun
Disliked
A potential alternative is to set the SL/TP such that the profit conditions are met when those are hit.
Ignored
RR,
Setting a fixed TP manually is a problem since you would need a different TP value for each additional level opened wouldn't you. I'm looking for a $5 profit on the total of trades open but EA is too slow getting all trades closed. Can we have EA modify all trades to close at the same price when TP is reached?
 
 
  • Post #8
  • Quote
  • May 11, 2010 7:32pm May 11, 2010 7:32pm
  •  Ronald Raygun
  • Joined Jul 2007 | Status: 32 y/o Investor/Trader/Programmer | 5,016 Posts
Closing multiple trades at the same price is quite unrealistic if you try to manage that from the client side (Metatrader). By setting the trade's takeprofit so they are all the same, you move the job of closing orders on the client side to the server side (broker). However, you still will experience slippage. Slippage is a cost of doing business, so instead of trying to take profit at $5, try taking profit at $7, basically, factor in slippage.
 
 
  • Post #9
  • Quote
  • Edited 9:36pm May 11, 2010 9:11pm | Edited 9:36pm
  •  ecTrade
  • | Joined Jul 2009 | Status: Member | 1,163 Posts
I don't know about this other problem, but you can try this to modify TP's. It looks like there's already a TP and SL modification feature in place but, I'm not sure what it's supposed to do? I suspect this is what CodeMeister was referring to. If this is so, then what I added is not necessary. So you might want to check.

Anyway, you are free to try this if you like. It's setup to sort by Symbol() and MagicNumber(). If it's not setup to do this (it looks like it is), then it won't work properly.

There's also a closeall feature down at the bottom that I disabled. If you want to enable it, change if(Ask!=Ask) to if(Ask==Ask). The same holds true for the fix, except that it's enabled. If you wish to disable it, do the opposite.

It's also setup to modify all Buy orders at once or, all Sell orders at once, but not both. So, I don't know whether this poses a problem or not?
Attached File(s)
File Type: mq4 swb grid 4.1.0.mq4   14 KB | 271 downloads
 
 
  • Post #10
  • Quote
  • May 11, 2010 9:29pm May 11, 2010 9:29pm
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,604 Posts
hey toothman.... it's never a good policy to talk about someone else's code......

if it were me, the int signal() function would be kept and everything else rewritten...... and written in a precise manner.....

//----

in my experience, you should be able to close many trades at the same price in normal markets..... my experience is limited to ibfx...... it's not unusual for me to close 10 trades in a row at the same price ..... and you should be able to close hundreds in a row about as fast as you can count in typical speech.... it's not unusual for me to close hundreds in a minute....

of course this depends on proper coding... the picture shows one of my real live accounts used for experts testing..... you can see many times quite a few trades closed at the same price.....


//-----
something possibly important to consider.... when using a single symbol total() profit target, the price must have moved in your prefered direction to have triggered the closeall().... so this almost implys some of the last trades closed might be at a better price......

when using a typical single symbol totalpips() trailing stop the price must have moved against your prefered direction to have activated the trailing stop.... this almost implys the last trades closed will be at a worse price.....

you might have to give that some thought, but 10's of thousands of live trades have proved it to me.......


//-----

the trades in the picture are red not because they were losses, they were wins..... they are red because the market moved against them so the trailing function took them out..... even so, with the market moving obviously against me, they closed at the same price..... occasionaly some might be 1 pip worse.....

//----

all this is to say, if the trades are not closing neatly and orderly in normal markets, the code needs to be improved.....

lookin at the ea, verifys that thought......h
Attached Image (click to enlarge)
Click to Enlarge

Name: dentist.jpg
Size: 296 KB
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #11
  • Quote
  • May 11, 2010 9:43pm May 11, 2010 9:43pm
  •  Toothman
  • | Joined Aug 2006 | Status: Member | 1,242 Posts
Quoting hayseed
Disliked
hey toothman.... it's never a good policy to talk about someone else's code......

if it were me, the int signal() function would be kept and everything else rewritten...... and written in a precise manner.....

//----

in my experience, you should be able to close many trades at the same price in normal markets..... my experience is limited to ibfx...... it's not unusual for me to close 10 trades in a row at the same price ..... and you should be able to close hundreds in a row about as fast as you can count in typical speech.... it's...
Ignored
Hayseed,
Do you have any ideas on why EA is opening and closing trades for a loss during a TP. Are you a programmer? Can you fix this bug and also get EA to modify TP's to close at the same price? If you or someone can, I think we can make some money here. I think the basic concept of the EA is good with the RSI and Stochs. initiating the trade.
 
 
  • Post #12
  • Quote
  • Edited 10:11pm May 11, 2010 9:56pm | Edited 10:11pm
  •  ecTrade
  • | Joined Jul 2009 | Status: Member | 1,163 Posts
Quoting Toothman
Disliked
That's what Im after exactly. Have the EA modify all open trades to close at the same TP value. Yes it is closing the last trade first
Ignored
Actually, I just backtested the EA and it's not setting TP or SL values, but is probably based on AccountEquity() or AccountBalance(), or something similar. This is why my fix won't work.
 
 
  • Post #13
  • Quote
  • May 11, 2010 10:15pm May 11, 2010 10:15pm
  •  Ronald Raygun
  • Joined Jul 2007 | Status: 32 y/o Investor/Trader/Programmer | 5,016 Posts
Quoting hayseed
Disliked
the trades in the picture are red not because they were losses, they were wins..... they are red because the market moved against them so the trailing function took them out..... even so, with the market moving obviously against me, they closed at the same price..... occasionaly some might be 1 pip worse.....
Ignored
All of those trades seem to be closed because the stoploss price was hit. What if the EA sent a close order instead? Would the slippage have increased in your case?


Quoting hayseed
Disliked
//----

all this is to say, if the trades are not closing neatly and orderly in normal markets, the code needs to be improved.....

lookin at the ea, verifys that thought......h
Ignored
As I understood previous attempts at modifying this code, it was supposed to close the largest orders first, the logic being larger orders closed sooner results in a lower overall slippage cost.
 
 
  • Post #14
  • Quote
  • May 11, 2010 10:26pm May 11, 2010 10:26pm
  •  ecTrade
  • | Joined Jul 2009 | Status: Member | 1,163 Posts
Quoting Ronald Raygun
Disliked
All of those trades seem to be closed because the stoploss price was hit. What if the EA sent a close order instead? Would the slippage have increased in your case?
Ignored
No, I think it is closing based upon some equity target or, a certain percentage over break even point. It looks like a grid system with a bit of Martingale, where lot sizes get larger the further out you go.
 
 
  • Post #15
  • Quote
  • May 11, 2010 10:35pm May 11, 2010 10:35pm
  •  Ronald Raygun
  • Joined Jul 2007 | Status: 32 y/o Investor/Trader/Programmer | 5,016 Posts
Quoting ecTrade
Disliked
No, I think it is closing based upon some equity target or, a certain percentage over break even point. It looks like a grid system with a bit of Martingale, where lot sizes get larger the further out you go.
Ignored
I'm referring to hayseed's picture.
 
 
  • Post #16
  • Quote
  • May 11, 2010 10:56pm May 11, 2010 10:56pm
  •  ecTrade
  • | Joined Jul 2009 | Status: Member | 1,163 Posts
Quoting Ronald Raygun
Disliked
I'm referring to hayseed's picture.
Ignored
Fair enough. I just thought he had backtested Toothman's EA (without fully reading the post) and this was a picture of that.
 
 
  • Post #17
  • Quote
  • May 12, 2010 5:17am May 12, 2010 5:17am
  •  Toothman
  • | Joined Aug 2006 | Status: Member | 1,242 Posts
Guys,
The EA not closing at the same price is a problem but I'm even more concerned with the flash trade for a loss as a level 4 is closing. Here's what's happening. I get to a level 4, price reverses and gets to my $5 target, trades start shutting down but in the few seconds it takes to close the 4 trades, a flash trade opens and closes immediately for a loss. It doesn't have this problem while running on the back tester. Does anyone see what could be causing this in the code? thank you
 
 
  • Post #18
  • Quote
  • May 12, 2010 5:30am May 12, 2010 5:30am
  •  ecTrade
  • | Joined Jul 2009 | Status: Member | 1,163 Posts
Sounds like you need some sort of latch that suspends trading until count goes back down to zero. This is generally the way I setup my EA's when doing a Close-All. That way it's like starting over from scratch. Plus, if there are any stragglers left over from the first round, it will ensure they are deleted first before proceeding.
 
 
  • Post #19
  • Quote
  • May 12, 2010 5:41am May 12, 2010 5:41am
  •  Toothman
  • | Joined Aug 2006 | Status: Member | 1,242 Posts
Quoting ecTrade
Disliked
Sounds like you need some sort of latch that suspends trading until count goes back down to zero. This is generally the way I setup my EA's when doing a Close-All. That way it's like starting over from scratch. Plus, if there are any stragglers left over from the first round, it will ensure they are deleted first before proceeding.
Ignored
Ec,
The thing is, it's opening the flash trade (while closing a level 4 trade) even though conditions to initiate a trade are not met. A trade shouldn't be opening again until RSI and STOCH. are at extremes again.
 
 
  • Post #20
  • Quote
  • Edited 7:37am May 12, 2010 6:18am | Edited 7:37am
  •  ecTrade
  • | Joined Jul 2009 | Status: Member | 1,163 Posts
And, if it waited until after the last trade closes, then what? Maybe it will reset after that ... I don't know? Or, if not, will have to figure out what he/she is using as a reset.

You might want to try this and see if it works anyway. Basically I wrapped it around all instances where it looks like it's opening new trades.

ETA: Modified to specify symbol and magic number ... it still doesn't work.
Attached File(s)
File Type: mq4 swb grid 4.1.0.1.mq4   13 KB | 243 downloads
 
 
  • Platform Tech
  • /
  • Gem of an EA needs a slight change
  • Reply to Thread
    • Page 1 23 4
    • Page 1 23 4
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 / ©2023