项目演示ppt模板:Programming confusion on an EA @ Forex Factor...

来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 07:19:32
Programming confusion on an EA
Community Links
Member List
Search Forums
Show Threads   Show Posts

Advanced Search
Go to Page...

1
Thread ToolsBookmarkSearch this Thread
#1
Feb 18, 2010 4:20pm
nondisclosure00
Gettin' kick in the nutz every day!
Member Since Apr 2007
470 Posts
Programming confusion on an EA
I'm trying to grab values from an angle object on a chart (see attached picture). I can get the properties like so: Code:
double angleprice2=ObjectGet("Angle",OBJPROP_PRICE2); double angleprice1=ObjectGet("Angle",OBJPROP_PRICE1); datetime angletime2=ObjectGet("Angle",OBJPROP_TIME2); datetime angletime1=ObjectGet("Angle",OBJPROP_TIME1);
What I can't seem to do is this: Code:
int bar1=iBarShift(NULL,0,angletime1,false); int bar2=iBarShift(NULL,0,angletime2,false);
bar1 is the orgin point. bar2 is what I have in the rectangle in the pic. when I try to get the bar, I get either 65000+ or -1 depending on iBarshift exact.
I'm trying to get the "rise/run" out of the angle so in code, so I can tell where the angle's price is on candle 0.
Any ideas? thanks.

__________________
"And now, folks, it's time for "Who do you trust!" Hubba, hubba, hubba! Money, money, money! Who do you trust? Me?."

#2
Feb 18, 2010 5:12pm
hanover
Commercial Member
Member Since Sep 2006
  3,813 Posts

iBarShift() returns the number of any already existing candle (0 = currently forming candle; 1 = the most recently completed candle; 2 = the next one to the left; and so on). I can't say for sure, but I expect that the unpredictable results could be due to your time values being related to candles that haven't yet occurred, i.e. the 'whitespace' area at the right of the chart.
__________________
For a list of indicators and EAs written by hanover, see the foot ofthis post.

#3
Feb 18, 2010 6:42pm
nondisclosure00
Gettin' kick in the nutz every day!
Member Since Apr 2007
470 Posts

Yep, that's what it is. But, oddly enough, I can get the time value from that point. Maybe there is a way to subract one time value from another.
Thoughts?
Quote:
Originally Posted by hanover
iBarShift() returns the number of any already existing candle (0 = currently forming candle; 1 = the most recently completed candle; 2 = the next one to the left; and so on). I can't say for sure, but I expect that the unpredictable results could be due to your time values being related to candles that haven't yet occurred, i.e. the 'whitespace' area at the right of the chart.
__________________
"And now, folks, it's time for "Who do you trust!" Hubba, hubba, hubba! Money, money, money! Who do you trust? Me?."

#4
Feb 18, 2010 11:06pm
sangmane
Member
Member Since Apr 2009
  591 Posts

different of bars between angletime1 and angletime2 :
PHP Code:
int bardiff = (angletime2-angletime1)/(60*Period());

#5
Feb 20, 2010 12:39am
tomhliles
Multiple Usernames
Member Since Dec 2006
135 Posts

you can get the value from the object at 0 bar by using
ObjectGetValueByShift("name", 0);

#6
Mar 6, 2010 1:24pm
nondisclosure00
Gettin' kick in the nutz every day!
Member Since Apr 2007
470 Posts

actually, I can't. All I get back is 0.
I've even tried to get back the angle value by setting time1/price1 and time2/price2. And still all I get back is 0.
Here's the code:
Code:
#property copyright "Copyright © 2010, Nondisclosure007" #property link "http://no.link.yet" #property indicator_chart_window #property indicator_buffers 2 double floor[]; double ceiling[]; int init() { IndicatorBuffers(2); IndicatorDigits(Digits); SetIndexBuffer(0,floor); SetIndexLabel(0,"Lower Angle"); SetIndexBuffer(1,ceiling); SetIndexLabel(1,"Upper Angle"); SetIndexEmptyValue(0,0.0); SetIndexEmptyValue(1,0.0); ArraySetAsSeries(floor,true); ArraySetAsSeries(ceiling,true); return(0); } int deinit() { ObjectDelete("LowerAngle");ObjectDelete("UpperAngle"); return(0); } int start() { int i, k, limit, counted_bars=IndicatorCounted(); limit = Bars-counted_bars-1; double varLowMACurrent, varLowMALast, varHighMALast, varHighMACurrent; datetime varTime; for(i=limit; i>=0; i--) { varLowMACurrent=iMA(NULL,0,34,0,MODE_EMA,PRICE_LOW,i+1); varLowMALast=iMA(NULL,0,34,0,MODE_EMA,PRICE_LOW,i+2); varHighMACurrent=iMA(NULL,0,34,0,MODE_EMA,PRICE_HIGH,i+1); varHighMALast=iMA(NULL,0,34,0,MODE_EMA,PRICE_HIGH,i+2); if (ObjectFind("LowerAngle")==-1) {ObjectCreate("LowerAngle",OBJ_TRENDBYANGLE,0,Time[i+2],varLowMALast,Time[i+1],varLowMACurrent);} ObjectSet("LowerAngle",OBJPROP_STYLE,STYLE_DOT); ObjectSet("LowerAngle",OBJPROP_TIME1,Time[i+2]); ObjectSet("LowerAngle",OBJPROP_TIME2,Time[i+1]); ObjectSet("LowerAngle",OBJPROP_PRICE1,varLowMALast); ObjectSet("LowerAngle",OBJPROP_PRICE2,varLowMACurrent); ObjectSet("LowerAngle",OBJPROP_COLOR,Magenta); ObjectSet("LowerAngle",OBJPROP_RAY,true); floor[i]=ObjectGet("LowerAngle",OBJPROP_ANGLE); if (ObjectFind("UpperAngle")==-1) {ObjectCreate("UpperAngle",OBJ_TRENDBYANGLE,0,Time[i+2],varHighMALast,Time[i+1],varHighMACurrent);} ObjectSet("UpperAngle",OBJPROP_STYLE,STYLE_DOT); ObjectSet("UpperAngle",OBJPROP_TIME1,Time[i+2]); ObjectSet("UpperAngle",OBJPROP_TIME2,Time[i+1]); ObjectSet("UpperAngle",OBJPROP_PRICE1,varHighMALast); ObjectSet("UpperAngle",OBJPROP_PRICE2,varHighMACurrent); ObjectSet("UpperAngle",OBJPROP_COLOR,Magenta); ObjectSet("UpperAngle",OBJPROP_RAY,true); ceiling[i]=ObjectGet("UpperAngle",OBJPROP_ANGLE); WindowRedraw(); } return(0); } //+------------------------------------------------------------------+
Quote:
Originally Posted by tomhliles
you can get the value from the object at 0 bar by using
ObjectGetValueByShift("name", 0);
__________________
"And now, folks, it's time for "Who do you trust!" Hubba, hubba, hubba! Money, money, money! Who do you trust? Me?."

#7
Mar 7, 2010 10:10pm
tomhliles
Multiple Usernames
Member Since Dec 2006
135 Posts

it works, theres some other problem
tl by angle only uses price1 and time1
paste this in any indy, then create a tl or tl by angle or a hor line, itl return the value of that object at current bar
if the object doesnt exist, itl return 0
Print(ObjectGetValueByShift("name", 0));

#8
Mar 8, 2010 3:04pm
nondisclosure00
Gettin' kick in the nutz every day!
Member Since Apr 2007
470 Posts

Thanks Tom. I tried that a while ago, and it didn't work either. But, I added floor[i]=0; ceiling[i]=0; at the begining of the for loop and now I get the values. I don't know why, but it works.
You can use 2 times and 2 prices to set tl by angle (the manual for mql4 is slightly wrong on this one). One time and price w/ angle is the minimum.
I'm curious when you say it worked. What build of MT4 are you using? I've got build 225 that I'm working in.
Quote:
Originally Posted by tomhliles
it works, theres some other problem
tl by angle only uses price1 and time1
paste this in any indy, then create a tl or tl by angle or a hor line, itl return the value of that object at current bar
if the object doesnt exist, itl return 0
Print(ObjectGetValueByShift("name", 0));
__________________
"And now, folks, it's time for "Who do you trust!" Hubba, hubba, hubba! Money, money, money! Who do you trust? Me?."

#9
Mar 8, 2010 10:37pm
tomhliles
Multiple Usernames
Member Since Dec 2006
135 Posts

i just meant the line printed the value, i didnt try your code
glad u got it working