reading and useing a price from the screen
-
jjasper7
- Trader
- Posts: 87
- Joined: Mon Mar 19, 2012 11:44 pm
- Location: Mesa,AZ (near Phoenix)
reading and useing a price from the screen
how can i move the crosshairs/arrow to a point and then read its price at a past time. it would be useful for an indicator to calculate values from, perhaps to visually set a stop loss or a limit entry, or use to move my stoploss. Does anyone know of a program that gets a coordinate and a trigger that sets up an input like that, which i could modify for such an indi?
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: reading and useing a price from the screen
I'm not entirely sure what you are looking for. There are ample examples in the code here of reading the price value from a horizontal line. You could have your indicator look for this line and use its price.jjasper7 wrote:how can i move the crosshairs/arrow to a point and then read its price at a past time. it would be useful for an indicator to calculate values from, perhaps to visually set a stop loss or a limit entry, or use to move my stoploss. Does anyone know of a program that gets a coordinate and a trigger that sets up an input like that, which i could modify for such an indi?
I've done the following at one time or another, so I could give you a bit of code to help you on your way if any of these would help:
- Start an indicator from the price at a particular time, read from a vertical line
- Created boxes/fibos on screen at the point they are dropped on the screen (for later reading by the indi perhaps
- Captured data from a script and put it in the Windows clipboard (grab price and then add it to the parameters of an indicator)
George
-
jjasper7
- Trader
- Posts: 87
- Joined: Mon Mar 19, 2012 11:44 pm
- Location: Mesa,AZ (near Phoenix)
Re: reading and useing a price from the screen
thanks again, george. if those 3 suggestions are all in one indi, it sounds very much like you already have what i am trying to make... fetch a starting point (or adjust the start) and draw a fibo and zigzags from there as well. i thought i had the way to read in a vertical line for the start, but could not get it to work. please send or post the routines when you can find them and the time.
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: reading and useing a price from the screen
Since a vertical line has no price component, only a time component, you have to get a price in two steps. The following code should get the close price for the bar that the vertical line Time_Marker is on:jjasper7 wrote:thanks again, george. if those 3 suggestions are all in one indi, it sounds very much like you already have what i am trying to make... fetch a starting point (or adjust the start) and draw a fibo and zigzags from there as well. i thought i had the way to read in a vertical line for the start, but could not get it to work. please send or post the routines when you can find them and the time.
Code: Select all
if (ObjectFind("Time_Marker") != -1) {
datetime DT = ObjectGet("Time_Marker", OBJPROP_TIME1);
int bar = iBarShift(NULL,0,DT,false);
double price = Close[bar];
Alert("Time / Bar / Price: ",TimeToStr(DT,TIME_DATE|TIME_MINUTES)," / ",bar, " / ",price);
} else
Alert("Object not found");
You'll have to keep track of the returned price, so you can tell if the line gets moved.
I'm still looking for the indi I wrote that actually used the moving line, but I thought this would get you started....
George
-
garyfritz
Re: reading and useing a price from the screen
There are also ways to read the location of a mouse click. Maybe you could click to specify the price or time you want? I know this is do-able but I haven't done it myself.
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: reading and useing a price from the screen
You can get the location that you drop a script on a chart via calls to WindowPriceOnDropped() and WindowTimeOnDropped(). I'm a bigger fan of using the Time to get the price instead of calling WindowPriceOnDropped() since you generally want the Open/Close of the bar, not an exact price. Well, I generally do. For example, I use this code if I want to get the open of a bar:garyfritz wrote:There are also ways to read the location of a mouse click. Maybe you could click to specify the price or time you want? I know this is do-able but I haven't done it myself.
double target1 = Open[iBarShift(Symbol(),0,WindowTimeOnDropped())];
I just suck at dropping it exactly where I want.
Unfortunately, these functions don't work on indicators or EAs, so you'd be stuck using a script to drop a line that is read by your indicator/ea.
George
-
jjasper7
- Trader
- Posts: 87
- Joined: Mon Mar 19, 2012 11:44 pm
- Location: Mesa,AZ (near Phoenix)
Re: reading and useing a price from the screen
there is so much i still do not understand about mql, i appreciate your guidance. your snippit showed that my call to ibarshift was wrong. i have a project due this week, and will have to get back to the code next week. if you discover your example code and wouldn't mind sharing it, please do - not only is working code very helpful, but your stuff is so much more elegant than my crude code that i would like to use it if available. i really miss having some sort of a 'breakpoint' routine to help debugging. i guess i almost always had one in the past, and working back from error messages is so much more difficult (just crying, i guess).
-
jjasper7
- Trader
- Posts: 87
- Joined: Mon Mar 19, 2012 11:44 pm
- Location: Mesa,AZ (near Phoenix)
Re: reading and useing a price from the screen
i am placing a line on the chart, often (not always),it does not draw, even though i can then find it in the objects list, and it does not consistently fail (even without recompiling it will occasionally work). are there some strange things to watch for that keep it from painting? i have noticed the same failure to paint consistently on trying to paste a wingding. the values have been checked.
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: reading and useing a price from the screen
I've never had a problem with lines being drawn. When you examine it in the object list everything is complete? Post the code that draws the line and I can look at it.jjasper7 wrote:i am placing a line on the chart, often (not always),it does not draw, even though i can then find it in the objects list, and it does not consistently fail (even without recompiling it will occasionally work). are there some strange things to watch for that keep it from painting? i have noticed the same failure to paint consistently on trying to paste a wingding. the values have been checked.
George
-
jjasper7
- Trader
- Posts: 87
- Joined: Mon Mar 19, 2012 11:44 pm
- Location: Mesa,AZ (near Phoenix)
Re: reading and useing a price from the screen
can anyone observe what i am doing wrong in these code snippets? the wingdings and lines sometimes show but more often do not. their values do show up in the objects list, but are frequently not painted. and no code differences between when they paint and when they fail.
-------------------------------------------
void MarkV( string name, double price, int bar, int wingdng, color colr)
{
// wingdings: 228/230 buy/sell arrows,
// colors; buy/sell Aqua/Maroon
name=name+bar;
ObjectCreate(name ,OBJ_ARROW,0,Time[bar],price);
ObjectSet(name,OBJPROP_ARROWCODE,wingdng);
ObjectSet(name,OBJPROP_COLOR,colr);
}
// ex. MarkV("mtm5", Low[1], 0, 190, Black);
------------------------------
void DrawLine(string name, datetime time1, double val1, datetime time2, double val2, color col, int width, int style, bool ray)
{
//Plots a line with the given parameters
ObjectDelete(name);
ObjectCreate(name, OBJ_TREND, 0, time1, val1, time2, val2);
ObjectSet(name, OBJPROP_COLOR, col);
ObjectSet(name, OBJPROP_WIDTH, width);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSet(name, OBJPROP_RAY, ray);
}//End void DrawLine()
// ex. DrawLine("ttnl "+Bars, Time[3], High[3], Time[2],High[3]+2*spread, Brown, 2, STYLE_SOLID, false);
// ex2. DrawLine(" Aline ", Time[startA],Avalue, Time[0],Avalue, Brown, 3, STYLE_SOLID, false);
-------------------------------------------
void MarkV( string name, double price, int bar, int wingdng, color colr)
{
// wingdings: 228/230 buy/sell arrows,
// colors; buy/sell Aqua/Maroon
name=name+bar;
ObjectCreate(name ,OBJ_ARROW,0,Time[bar],price);
ObjectSet(name,OBJPROP_ARROWCODE,wingdng);
ObjectSet(name,OBJPROP_COLOR,colr);
}
// ex. MarkV("mtm5", Low[1], 0, 190, Black);
------------------------------
void DrawLine(string name, datetime time1, double val1, datetime time2, double val2, color col, int width, int style, bool ray)
{
//Plots a line with the given parameters
ObjectDelete(name);
ObjectCreate(name, OBJ_TREND, 0, time1, val1, time2, val2);
ObjectSet(name, OBJPROP_COLOR, col);
ObjectSet(name, OBJPROP_WIDTH, width);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSet(name, OBJPROP_RAY, ray);
}//End void DrawLine()
// ex. DrawLine("ttnl "+Bars, Time[3], High[3], Time[2],High[3]+2*spread, Brown, 2, STYLE_SOLID, false);
// ex2. DrawLine(" Aline ", Time[startA],Avalue, Time[0],Avalue, Brown, 3, STYLE_SOLID, false);