Download MetaTrader 5

Return shift by...?

To add comments, please log in or register
Register at MQL5.community and leave your comments!
Roman Zhitnik
1790
Roman Zhitnik 2014.07.01 14:35 

Hello, guys. First of all, sorry for future stupid questions or parts of code may be, because I'm just learning MQL4.

So I'm trying to make it work a code that could define which price of two prices was the last by price to visit. I.e. I have two rectangles and want the indi to calculate the edge of which rectangle was last to touch - the lower one or the upper one. I'm trying to use ObjectGetShiftByValue() function but it doesn't work or may be not appliable for rectangles, I don't know. But so far it doesn't work properly. So I'm asking for help and saying big thanks in advance!

void RectangleReader()
{
   int demandShift = ObjectGetShiftByValue("Demand",OBJPROP_PRICE2);
   int supplyShift = ObjectGetShiftByValue("Supply",OBJPROP_PRICE2);
   string Obj_Name ="RectangleLabel";  
   ObjectCreate(Obj_Name,OBJ_LABEL,0,0,0);
   ObjectSet    (Obj_Name,OBJPROP_CORNER,1);
   ObjectSet    (Obj_Name,OBJPROP_XDISTANCE,60);
   ObjectSet    (Obj_Name,OBJPROP_YDISTANCE,300);
   if(demandShift<supplyShift)
   {
      ObjectSetText(Obj_Name,"Rectangle UP",10,"MS Sans Serif",Green);
   }
   else
   {   
      ObjectSetText(Obj_Name,"Rectangle DOWN",10,"MS Sans Serif",Red);
   }
}
whroeder1
14518
whroeder1 2014.07.01 15:02  
.roman.: I'm trying to use ObjectGetShiftByValue() function but it doesn't work or may be not appliable for rectangles, I
int demandShift = ObjectGetShiftByValue("Demand",OBJPROP_PRICE2);
int supplyShift = ObjectGetShiftByValue("Supply",OBJPROP_PRICE2);
want the indi to calculate the edge of which rectangle was last to touch
  1. ObjectGetShiftByValue - MQL4 Documentation takes an object and a price. Is OBJPROP_PRICE2 a price, (e.g. 1.2345)? Rectangles are horizontal (vertical,) how can you get a shift on a horizontal line?
  2. You have to do exactly that. Get the starting and ending time, convert to a bar index (iBarShift). Get the top and bottom of the rectangle. Scan the bars looking for a touch, knowing the problems working with doubles The == operand. - MQL4 forum



Roman Zhitnik
1790
Roman Zhitnik 2014.07.01 15:17  
WHRoeder:
  1. ObjectGetShiftByValue - MQL4 Documentation takes an object and a price. Is OBJPROP_PRICE2 a price, (e.g. 1.2345)? Rectangles are horizontal (vertical,) how can you get a shift on a horizontal line?
  2. You have to do exactly that. Get the starting and ending time, convert to a bar index (iBarShift). Get the top and bottom of the rectangle. Scan the bars looking for a touch, knowing the problems working with doubles The == operand. - MQL4 forum




1. Yes, that's a price.

2. Thanks a lot, I'll try to re-code my function and post it here. I'd appreciate your help a lot if something goes wrong...I've seen so many posts and according to them you have huuuuge experience on that front.

whroeder1
14518
whroeder1 2014.07.01 15:29  
.roman.:  1. Yes, that's a price.
If you had BOTHERED to click on the link provided you would have seen it go to Object Properties - MQL4 Documentation

OBJPROP_PRICE2

3

double

Double value to set/get second coordinate price part


and that OBJPROP_PRICE2 is the value 3
and that OBJPROP_PRICE2 is an enumeration
and that OBJPROP_PRICE2 is not a price.

Ian Venner
2584
Ian Venner 2014.07.01 15:56  

You should use the identifier, OBJPROP_PRICE2 in ObjectGet() to get the price. Working with charts and objects is a mishmash of enumerated identifiers and the functions they work with, it seems rather haphazard at times but you'll get used to it. You can look up the identifier in the reference to find out which function it goes in.

Roman Zhitnik
1790
Roman Zhitnik 2014.07.01 19:19  
WHRoeder:
.roman.:  1. Yes, that's a price.
If you had BOTHERED to click on the link provided you would have seen it go to Object Properties - MQL4 Documentation

OBJPROP_PRICE2

3

double

Double value to set/get second coordinate price part


and that OBJPROP_PRICE2 is the value 3
and that OBJPROP_PRICE2 is an enumeration
and that OBJPROP_PRICE2 is not a price.


Well, the current OBJPROP_PRICE2 gives correct price for the Supply zone...


I've tried to code what you said but seems like there's a logical mistake so the code doesnt' work properly still.

void RectangleReader()
{
   double lowerEdgePrice = ObjectGet("Supply",OBJPROP_PRICE2), upperEdgePrice = ObjectGet("Demand",OBJPROP_PRICE1);
   datetime startTimeDemand = ObjectGet("Supply",OBJPROP_TIME1), startTimeSupply = ObjectGet("Demand",OBJPROP_TIME1);
   int barsSinceSupplyStart = iBarShift(NULL, 0, startTimeDemand), barsSinceDemandStart = iBarShift(NULL, 0, startTimeSupply);
   int barNumberTillSupTouch = 0, barNumberTillDemTouch = 0;
   for(int a=0;a<=barsSinceSupplyStart;a++)
   {
      if (DoubleToStr(High[a],5)>=DoubleToStr(lowerEdgePrice,5)) barNumberTillSupTouch = a;
   }
   for(int b=0;b<=barsSinceDemandStart;b++)
   {
      if (DoubleToStr(Low[b],5)<=DoubleToStr(upperEdgePrice,5))  barNumberTillDemTouch = b;
   }
   string Obj_Name ="Lbl";
   ObjectCreate(Obj_Name,OBJ_LABEL,0,0,0);
   ObjectSet(Obj_Name,OBJPROP_CORNER,1);
   ObjectSet(Obj_Name,OBJPROP_XDISTANCE,110);
   ObjectSet(Obj_Name,OBJPROP_YDISTANCE,300);
   if(a>b)ObjectSetText(Obj_Name,"Rectangle UP",10,"MS Sans Serif",Green);
   else ObjectSetText(Obj_Name,"Rectangle DOWN",10,"MS Sans Serif",Red);
}
Ian Venner
2584
Ian Venner 2014.07.02 01:56  
We already told you what is wrong but you don't listen.
Roman Zhitnik
1790
Roman Zhitnik 2014.07.02 10:53  
I've sorted out the problems with the code and it's working. Thanks for giving the direction and feel free to put some adjustments if you see.
void RectangleReader()
{
   double supplyEdgePrice = ObjectGet("Supply",3), demandEdgePrice = ObjectGet("Demand",1);
   int barsSinceSupplyStart = iBarShift(NULL, 0, ObjectGet("Supply",0)), barsSinceDemandStart = iBarShift(NULL, 0, ObjectGet("Demand",0));
   int barNumberTillSupTouch = 0, barNumberTillDemTouch = 0 ;
   int a,b;
   for(a=0; High[a]<=supplyEdgePrice; a++)
   {
      barNumberTillSupTouch = a;
   }
   for(b=0;Low[b]>=demandEdgePrice;b++)
   {
      barNumberTillDemTouch = b;
   }
   string Obj_Name ="Lbl";
   ObjectCreate(Obj_Name,OBJ_LABEL,0,0,0);
   ObjectSet(Obj_Name,OBJPROP_CORNER,1);
   ObjectSet(Obj_Name,OBJPROP_XDISTANCE,3);
   ObjectSet(Obj_Name,OBJPROP_YDISTANCE,300);
   if(barNumberTillSupTouch!=0 && barNumberTillSupTouch<barNumberTillDemTouch)ObjectSetText(Obj_Name,"Rect DOWN",10,"MS Sans Serif",Red);
   else ObjectSetText(Obj_Name,"Rect UP",10,"MS Sans Serif",Green);
}
P.S. I want to get the values of similar rectangles on other timeframes but I have no idea how it could be done codingwise. Could you give some hints please?
Ian Venner
2584
Ian Venner 2014.07.02 14:31  

Use ObjectGetInteger(), ObjectGetDouble()

If you are working with objects and charts I suggest you bring up the F1 help in meta-editor and familiarize yourself with all the relevant functions and enums that go with them, there are a lot of new ones.

Roman Zhitnik
1790
Roman Zhitnik 2014.07.02 19:39  
SDC:

Use ObjectGetInteger(), ObjectGetDouble()

If you are working with objects and charts I suggest you bring up the F1 help in meta-editor and familiarize yourself with all the relevant functions and enums that go with them, there are a lot of new ones.


I got stuck into this problem, seems like :\

In overall, my task is to get parameters of the rectangles (that are automatically drawn by the indi) on other timeframes that are not opened in charts, i.e. I have EU 1H chart opened but the Daily and Weekly TFs of EU(that I have to get the rectangles parametres from) are not. And it should be done for all the opened instruments. I'm not sure if it affects somehow the coding, just for note...

So ObjectGetDouble() is used to get price values from certain chart and it uses the chart_id according to the docs. That's what I've found on the forum https://www.mql5.com/en/forum/150505 and according to what I've checked chart with each needed TF on every instrument should be opened to get different IDs. But with my task I have to find out the parametres of the rectangles on the same chart but on different TFs. So seems like the more preferable for my task is to use this identifiers if it's possible of course https://docs.mql4.com/constants/chartconstants/enum_timeframes . But if I'm wrong feel free to correct me, please.

Roman Zhitnik
1790
Roman Zhitnik 2014.07.03 16:58  
Found the answer myself. As far as they are drawn on other TFs but don't disappear I've used the global variebles to get all the parametres using the GlobalVariableGet() and it works good so far.
12
To add comments, please log in or register