Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Metatrader 4


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-28-2006, 06:16 AM
Junior Member
 
Join Date: Nov 2005
Posts: 14
iPlayGames is on a distinguished road
number of bars on a chart

my EA depends on a text file to open trades. the text file is created by an Indicator. the EA and the Indicator does not talk to each other, they communicate through the text file.

the text file is in the format of "type @ price".

now what my EA does is that it opens the text file to get two values - "type" and "price" of the last trade signal recorded by my Indicator. then it opens another text file, which was created by the EA itself upon successful opening of a trade, to get another two values and name them "lastType" and "lastPrice". then it compares "type" with "lastType", "price" with "lastPrice". if they are all the same, then no new trades. otherwise new trades will be opened according to the indicator's record.

my problem is, on the off event that my EA got disconnected, a new trade signal was recorded by the Indicator. if this signal happens to be exactly the same type and at the same price as the last trade, then my EA wouldn't open a new trade as it should.

although this hasn't happened yet, it is enough of a trouble to make me worry. the only solution I can think of is to tell my indicator to record also the number of bars before the signal bar to the text file, then EA will compare it with its own record, if Indicator's record is greater, then new trades, otherwise no new trades.

because of the nature of my EA, I can not backtest. so I won't know if this will work until a few trades have been made. besides, I'm not sure I know how to tell an EA to find out the number of bars on a chart.

if you know it works, could you please tell me how to do it? if not, do you have any other suggestions?

looking forward to hearing from you.

iPG
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-28-2006, 06:41 AM
FX_Sniper's Avatar
Senior Member
 
Join Date: Jan 2006
Location: South Africa
Posts: 201
FX_Sniper is on a distinguished road
Hi, not quite sure if this will help, but perhaps it could give you some other directions to think about.

Why not serialize your trades from both the indicator and the EA. In other words, say your indicator starts with its first signal, it would reference this signal as trade long 10001, the next time it generates a signal, it would call it say trade long 10002 and then later on trade long 10003 etc etc….

Your EA records trades it placed by referencing to which signal from the indicator it took, say it takes trade 10002, it would record it in it’s own file… also in perhaps a separate file you could record all the trade number it IGNORED, that way, when you loose EA connection, and get it back, when the EA gets a new signal from the indicator, it could check to see if its reference number is in the trade log or in the ignored log, if it is NOT, then obviously it was skipped and should be considered now if the price has not moved to far etc etc…

Bottom line, serializing your signals in a signal log, your actual trades taken in a trade log and the ignored signals in an ignored log, you can easily locate missed signals…play around a bit with this thought.

To find the number of bars visible on any chart use:

int VisibleBars = WindowBarsPerChart();

Cya

FX Sniper
__________________
"I do not need a compass to tell me which way the wind is shining."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-28-2006, 09:55 AM
Junior Member
 
Join Date: Nov 2005
Posts: 14
iPlayGames is on a distinguished road
thank you! FX Sniper! I thought about this and it seems that to give each record a unique serial number the Indicator will have to open the file and read it. it can be done but I very much prefer to keep my Indicator as simple as possible, because I'll be running it on many charts. though what you suggested probably is the best solution, I'll certainly take this approach if all else fails.

somebody else has suggested that I embed the indicator logic into my EA. though it won't work with my trading method, I'm quite intrigued by this suggestion. I thought about this and could see its merits, but I've never done it before, though I remember there was an article by codersguru on this subject. but in his example the indicator he embedded was quite a simple one, I wonder if it applies to all kinds of indicators? do you perhaps have any experience in this?

iPG
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-28-2006, 03:50 PM
Junior Member
 
Join Date: Nov 2005
Posts: 14
iPlayGames is on a distinguished road
I just gave embedding a try. by the time I got a working version, I realised that it wouldn't really work. :-(

suppose you have the following trading rules:

1. buy when price breaks the last 20 day's high,
2. sell when price breaks the last 20 day's low,
3. only take the 1st signal of the breaking. that means, for example, if you missed a buy signal, you can not buy no matter how long the price keeps breaking the last 3 day's high.

now if I got my EA to give me signals by checking for the breaking of the last 3 day's high/low, what would happen if it got disconnected and missed the first break to the upside? it wouldn't know, and it would place a new order as soon as price broke again to the upside, thus violating my trading rule.

though this problem could be solved by instructing the EA to look further back in time, when buy conditions were met, until it found a sell signal, then the 1st buy signal after that would be the original signal that should have been taken.

but there is still another problem. this looking back in time has to be triggered by either fulfilling the buy or the sell conditions. waht if right after breaking to the upside, price drops back within the last 3 day's range, and stayed there for 2 days, then unexpectedly, it shoots up, way above the original buying point. EA would be triggered to look back for signals now, but it'll be too late when it returns with the correct findings, price is already out of reach...

though this could be avoided by having the EA always check for signals, instead of checking only when either condition was met. but the rule is to take the 1st signal only, and only once. what if EA starts, sees that there is no order in the pool, looks back in time, finds a signal, and sends the order without knowing that the order had already been taken, and that it was either stopped out or took profit? again this would be violating the rules...

though this could be solved by keeping a trade log, EA starts, reads the log, finds old signal, compare the two. if same, no trade, otherwise, issue new trade. then we come back to my original question - how to make sure that new trades won't be missed by doing this?

the last record could be from two or more trades ago, and it happened to be the same as the new signal. will a serial number solve this problem? I'll have to think about it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-28-2006, 04:33 PM
FX_Sniper's Avatar
Senior Member
 
Join Date: Jan 2006
Location: South Africa
Posts: 201
FX_Sniper is on a distinguished road
How can your EA go offline but not the indicator also, are they not both relying on the MT4 terminal connection to the server. The reason I ask is, it seems odd that the EA could go "off-line" but your platform is still running somehow and indicators are creating signals etc...

I have been coding Metatrader indics for about 3 years now and have done some pretty strange things and stretched the code far into C++ even but in my complete Forex trading career of about 5 years, have NEVER EVER made an EA , so I am not well versed with the nuances of EA's, but as said, it does sound a bit odd to loose only partial connection to the server... unless the problem is on the server side which for some reason is not taking orders...

Have you actually seen this happening?

It would seem that what you are trying to do is, have a situation where your EA goes "blind" / "off-line" for some reason but your MT4 terminal is still functioning and generating signals, you then would need some log system which would cache say your last 20 trade signals so that when your EA comes back online, it would scan the trade log to find missing trades, but you should bear in mind, that even if it finds missing trades, the market has most probably moved on, and having a list of trades you "wished" it would of taken is actually pretty useless, they are opportunities lost, they are gone.

The best I suppose you could do in such a event is assess the current market situation with regards to your open trades, say your have been long, and while your EA was out for pizza, a exit signal came by which it did not take, so now it has finished licking up the last crumbs in the pizza box and back online. I would think the first and most important thing to check for now is: Has there not been a reversal signal, then worry about adding, protect open positions first, you can do something about them still, but you can do nothing about lost opportunities…

It sounds also that perhaps when your EA comes back to work, you would like for it not to simply take a new 20 bar high/low breach as a trade, but should trace it back to the first break, by doing so it could then refuse a new trade and figure out that the opportunity is gone, not sure if this is also what you are meaning to say…

Your rules as described sounds pretty close to the well known Turtle trading setup for which you can use the basic Donchian channel break in MT4 etc… to find the last bar just before the initial break could be done by finding two bars where the Donchian channel top was equal and next to each other. That I would suppose is the definition of a channel top, to have at least 2 bars of the same 20 bar high or low etc etc…

Unfortunately I do not have a lot of spare time, otherwise I would of tried to help you put the whole thing together, perhaps if you try to search for some EA’s based on the Turtle rules, you might find a good template to work from.

Best of luck,

FX Sniper
__________________
"I do not need a compass to tell me which way the wind is shining."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-28-2006, 04:37 PM
FX_Sniper's Avatar
Senior Member
 
Join Date: Jan 2006
Location: South Africa
Posts: 201
FX_Sniper is on a distinguished road
Addendum to my last post:

Perhaps rather fix your indicators so that they do the checking for an initial 20 bar break at the indicator level and ignore subsequent breaks, that way your EA does not have to bother with such things and can safely assume that all trades in the log file created by the indicator where in fact real trades.

__________________
"I do not need a compass to tell me which way the wind is shining."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-28-2006, 04:41 PM
FX_Sniper's Avatar
Senior Member
 
Join Date: Jan 2006
Location: South Africa
Posts: 201
FX_Sniper is on a distinguished road
This thread has some breakout EA's apparently related to Turtle system:

The Original Turtle System
__________________
"I do not need a compass to tell me which way the wind is shining."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-29-2006, 06:36 AM
Junior Member
 
Join Date: Nov 2005
Posts: 14
iPlayGames is on a distinguished road
I was rewritting my Indicator when I realised that serial numbers wouldn't work.

when I start MT4 the following will happen.

1. Indicator checks for the last valid signal on the chart and finds it, let's call it the newSig, it has 2 properties: type and price;
2. indicator reads the last recorded signal from a log file, let's call it the lastSig, it has three values: type, price and serial,
3. indicator then tries to compare newSig with lastSig. because it's impossible to get newSig's serial number (because it doesn't have one in the 1st place), the comparison won't work. indicator will either ignore the newSig or ignore the lastSig, depends on how it was configured. either won't be desirable.

so I went back to my number of bars before signal solution.

1. indicator checks for the last valid signal on the chart and fins it, records it to a file with three values: type, price, number of bars before.
2. EA reads the 3 values from the file, if there are no entries in its own log, it makes the trade, and record the same 3 values to its own log.
3. if it already had a log, it opens and reads from it the 3 vlaues, and compare them with the indicator's records. if the number of bars from the indicator's record is greater than from the EA's, new trade, otherwise, no new trade.

the only problem with this approach is that before I can use the EA on a chart for the 1st time, I have to manually download all the available historical data from the server (by pressing the 'end' key while the chart window is active), afterwards the EA and the indicator will work just fine. I have given up on the embedding attempt for the time being, it requires too radical a structural change of my EA, maybe at some later time I will have a go at it again. meanwhile, I'm going to check out the link you provided on the turtle system. :-)

have a good day.
iPG
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Close after 5 bars carllos Metatrader 4 3 05-15-2007 09:14 PM
Appendix 1 - BARS codersguru Lessons 16 02-19-2007 06:52 PM
Inside Bars biggo Metatrader 4 0 01-21-2007 11:56 PM
Reversal Bars Foreverold Indicators - Metatrader 4 14 01-20-2007 11:23 PM
Day Bars Jonmem Setup Questions 2 12-12-2006 06:31 PM


All times are GMT. The time now is 07:43 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.