If price touch the shap

 

Hi

I draw a rectangle on the screen and want to call a function if price touch the rectangle.

Is there an elegant way to do this?  if so what is it?


Thanks

 

Yes.

if(Bid > ObjectGetDouble(0,"objectname",OBJPROP_PRICE,0))
 {
  //Do something
 }

if(Bid < ObjectGetDouble(0,"objectname",OBJPROP_PRICE,0))
 {
  //Do something else
 }
 
   double rectP1 = ObjectGetDouble(0,"objectname",OBJPROP_PRICE1);
   double rectP2 = ObjectGetDouble(0,"objectname",OBJPROP_PRICE2);
double rectTop = MathMax(rectP1, rectP2);
double rectBot = MathMin(rectP1, rectP2);

if(rectBot <= Bid && Bid <= rectTop) // inside the rect price levels.

That assumes you don't want to stop when past the rectangle. Otherwise you'll have to compare time to rectangle end.

If you want to see if the last candle touched

double h=...; l=...;
bool neverTouched = h < retBot || l > retTop;
 

whroeder1:

Why is there 0 and 1 as the prop_modifier? I could not understand it from the docs, my best guess is the top and bottom of the shape, is that correct? if so, what if the shape is ellipse?


The code needs to call a function only if the price hits the shape "price and time". Thus I think this line will need to be used

int startTime = ObjectGetInteger(0, "objectname",OBJPROP_TIME,0);
int endTime = ObjectGetInteger(0, "objectname",OBJPROP_TIME,1);

But not sure how to incorporate the time in this solution.

Maybe something like this:

if (price hit && current time is less then endTime)

do stuff...

Yes???

 

samjesse: Why is there 0 and 1 as the prop_modifier?

if (price hit && current time is less then endTime)

  1. That's wrong, the modifier shouldn't be use at all. (The OBJPROP_PRICE confused me.) A rectangle has two coordinates (price and time) You use ObjectGet(name, OBJPROP_PRICE1) or 2, or ObjectGetDouble(0,name, OBJPROP_PRICE1)
  2. Yes
 
whroeder1:
  1. That's wrong, the modifier shouldn't be use at all. (The OBJPROP_PRICE confused me.) A rectangle has two coordinates (price and time) You use ObjectGet(name, OBJPROP_PRICE1) or 2, or ObjectGetDouble(0,name, OBJPROP_PRICE1)

Then why bother and use "if (price hit && current time is less then endTime)"? since the time can be obtained based on your comment above.

Could you please modify your code so that I can see it better.