飞虎队张子健:Using Custom Indicator in EA (MT4)

来源:百度文库 编辑:九乡新闻网 时间:2024/04/30 05:29:45
Thread:Using Custom Indicator in EA (MT4)
0
inShare   

LinkBack
LinkBack URL About LinkBacks   Bookmark & ShareDigg this Thread!Add Thread to del.icio.usBookmark in TechnoratiTweet this thread
Thread Tools
Show Printable VersionEmail this Page…Subscribe to this Thread…
Display
Linear ModeSwitch to Hybrid ModeSwitch to Threaded Mode
04-23-2007 01:23 AM#1
jimven
Senior Member




Join Date Mar 2007
Location Upstate New York
Posts 139
Points 6,616
Level 9
Using Custom Indicator in EA (MT4)
I've been trying to code an EA in MT4 using custom indicators and I always have the following problem:
When the EA tests the value of the indicator at any shift value (I usually use 0 or 1), it often returns a value quite different for that period than the corresponding indicator value displayed on the screen. This results in opening or closing trades at the wrong time.
Is there any technique to get what the EA sees to agree with what the indicator displays for a specific period?
Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
Reply With Quote
04-23-2007 06:22 PM#2
iscuba11
Senior Member




Join Date May 2006
Location Houston
Posts 395
Points 21,378
Level 20

PHP Code:
buy_cur=iCustom(NULL,60,"Forex-Grail Trade Indicator [4]",period,0,0);//Buffer 0, Current Bar
sell_cur=iCustom(NULL,60,"Forex-Grail Trade Indicator [4]",period,1,0);//Buffer 1, Current Bar
buy_cur1=iCustom(NULL,60,"Forex-Grail Trade Indicator [4]",period,0,1);//Buffer 0, Current Bar-1 in Past
sell_cur1=iCustom(NULL,60,"Forex-Grail Trade Indicator [4]",period,1,1);Buffer 1, Current Bar-1 Bar in Past
1) Make sure you are setup with the right buffer for the right information desired. Many indicators start with buffer 0 (The actual first buffer) and may end up with 3 for a total of 4 actual buffers. If buffer 0, or 1, or 2, or 3 is the buffer in the indicator that has the data you are wanting imported into your EA, then your EA custom indicator buffer must match the same buffer number that is being used by your indicator. Apples to Apples when it comes to buffer numbers. It may be that the information you seek for your EA may be created in buffer 2 versus buffer 0 in your indicator.
In my example using my Forex-Grail Trade Indicator [4] you can create a print statement below your custom indicator statements to see what the EA Buffer 0, and Buffer 1 (Example Below): P.S. The values will show up in your Experts Tab below your graphs! If the values equal those showing up on your indicator window, then you have the right buffer number.
Print(" ",TradeLast," buy_cur= ",buy_cur,"|", "buy_cur1= ",buy_cur1);
This will print out the values for buffer 0 for the current (buy_cur) and the value for buffer 1 for the current -1 bar in past (buy_cur1).
2) Make sure the Indicator File name (Such as Forex-Grail Trade Indicator [4]) is the actual same name as the indicator file name, otherwise weird data can be acquired by the EA in each buffer input.
I hope this will help some??
Peace and Love, in Jesus Name!
Dave
<><<<<
Last edited by iscuba11; 04-23-2007 at 06:27 PM.Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
Reply With Quote
04-23-2007 08:35 PM#3
european
Senior Member




Join Date Apr 2006
Posts 281
Points 23,438
Level 21
testing buffers
or you can use a script and check what each buffer returns, place text label called say 'lx' on your chart, compile your code and d.click on the script - results will be shown in your label
ex:
double vFMACD=iCustom("GBPUSD",5,"FlatTrend w MACD",5,5,6,25,2,0);
string text = vFMACD;
ObjectSetText("lx", text, 10, "Arial", White);
Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
Reply With Quote
04-23-2007 10:57 PM#4
jimven
Senior Member




Join Date Mar 2007
Location Upstate New York
Posts 139
Points 6,616
Level 9

I greatly appreciate replies from both of you, however I would like to add the following.
I have inserted print statements in my test EA to see what the indicator is returning and have found that these values are correct for the EA. That is, they make sense in terms of the range and values. Also, I have verified that I am using the correct indicator name and buffer number.
But here's what I think might be happening:
When the indicator displays on the screen, it uses historical data, which consists only of OHLC values and time. When I perform a backtest (and this is where the problem occurs), the MT4 simulator injects fractal price values and/or lower timeframe values so that for a specific period, the indicator now reports to the EA a different value than it did when it was just displaying and using just the OHLC values.
Therefore, what looked like a good strategy on the screen does not work out in practice because the indicator results are different. I believe that if I could get the indicator to report exactly as it did on historical data, it would again become useful because it would do what it does on the screen.
I have attached a test EA and a picture of some of the results. Clearly, the test EA is not doing what is intended or expected, based on the indicator. It should never close a "BUY" trade unless the indicator bar is RED, which is buffer 3, and has a value of -4. In the jpg attached, this doesn't happen except on the far right. So how do I get the indicator value shown on the screen to be reported to the EA? What I expected was that a "Buy" trade would open if there are any light green or dark green bars showing and would close only when the Red bar appeared.
Attached Thumbnails  Attached FilesTest 5 Minute.mq4‎ (3.4 KB, 181 views)
Last edited by jimven; 04-24-2007 at 08:20 PM.Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
Reply With Quote
05-25-2007 06:09 PM#5
nittany1
Senior Member




Join Date Dec 2006
Location Sarasota, FL
Posts 207
Points 66,461
Level 38
pull correct numbers from this SMI, don't know what statement to use
Originally Posted by european
or you can use a script and check what each buffer returns, place text label called say 'lx' on your chart, compile your code and d.click on the script - results will be shown in your label
ex:
double vFMACD=iCustom("GBPUSD",5,"FlatTrend w MACD",5,5,6,25,2,0);
string text = vFMACD;
ObjectSetText("lx", text, 10, "Arial", White);
Does anyone know how to pull the numbers from this SMI indicator? I'm writing an EA for it, actually it's written already and I'm using stochastic crosses but I want to try this indicator too.
Attached FilesSMI.mq4‎ (3.9 KB, 143 views)
Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
The best things in life come from open source development.
MyspaceFacebook My Indicators:Trade AssistantTrend FriendToRCCI Helper
Holder ofUS Patent 6,774,788
Reply With Quote
05-28-2007 11:35 AM#6
nittany1
Senior Member




Join Date Dec 2006
Location Sarasota, FL
Posts 207
Points 66,461
Level 38
Originally Posted by nittany1
Does anyone know how to pull the numbers from this SMI indicator? I'm writing an EA for it, actually it's written already and I'm using stochastic crosses but I want to try this indicator too.
Nevermind, I figured it out!
Attached Thumbnails
Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
The best things in life come from open source development.
MyspaceFacebook My Indicators:Trade AssistantTrend FriendToRCCI Helper
Holder ofUS Patent 6,774,788
Reply With Quote
06-04-2009 01:15 PM#7
wapzzoo
Junior Member




Join Date May 2009
Posts 2
Points 1,692
Level 3
Hello Jimven,
Did you found an answer to your problem ?
I have the same problem, data indicator in EA are different from data indicator on screen.
Regards
Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
Reply With Quote
06-05-2009 08:19 AM#8
luxinterior
Senior Member




Join Date Nov 2006
Posts 342
Points 5,902
Level 8
Originally Posted by wapzzoo
Hello Jimven,
Did you found an answer to your problem ?
I have the same problem, data indicator in EA are different from data indicator on screen.
Regards
You just bumped a thread from two years ago!
Welcome to the forum.
Lux
Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
Build An Expert Advisor. FREE E-courseAs Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUSTRead This
Reply With Quote
06-06-2009 02:45 PM#9
wapzzoo
Junior Member




Join Date May 2009
Posts 2
Points 1,692
Level 3
Thank you for receive me
Thank you for receive me in this forum.
wap
Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
Reply With Quote
06-01-2010 01:15 PM#10
keyrama
Junior Member




Join Date Apr 2010
Posts 4
Points 1,059
Level 2
Hello,
I apologize for upping this old thread, but since not public answer have been posted, I would like too, know the solution !
Thanks,
keyrama
Share Share this post on
Digg
Del.icio.us
Technorati
Twitter
Reply With Quote