Download MetaTrader 5
To add comments, please log in or register
Post web links to other trader's signals and make profit
John
79
John 2014.08.01 14:38 

Hi, I'm coding an EA that opens Buy a Sell trades when the Price breaks the Trendline.

To do so, I'm comparing price values to trend line values. But I don't understand why it's not working.

Basically the conditions are 

--> Buy

if(Close[1] < NormalizeDouble(ObjectGetValueByShift(trendlineName,1),Digits)

&& Close[0] >  NormalizeDouble(ObjectGetValueByShift(trendlineName,0),Digits)  )

 

--> Sell

   if(Close[1] > NormalizeDouble(ObjectGetValueByShift(trendlineName,1),Digits) 

&& Close[0] < NormalizeDouble(ObjectGetValueByShift(trendlineName,0),Digits) 


Shouldn't the  ObjectGetValueByShift(trendlineName,1)  return the value of the trendline at a specific Shift 1 ??

Can anyone help me ? Thanks. 

qjol
3243
qjol 2014.08.01 14:52  
jfortes:

 

Shouldn't the  ObjectGetValueByShift(trendlineName,1)  return the value of the trendline at a specific Shift 1 ??



yes

maybe the conditions not met 

or maybe the trendlineName isn't the right name 

John
79
John 2014.08.01 15:32  

I've debugged the code and the trendlineName is correct.

The problem is that the price returned by ObjectGetValueByShift(trendlineName,1)  is not at the Shift 1 (in relation to Time[0] ) , but in relation to anchor point 2.

Can anyone confirm ? Thanks.

John
79
John 2014.08.01 16:44  

I've decided to create my own regression function that calculates the price at the Trendline, for a given time.

y = mx +b 

Thanks anyways. 

Keith Watford
Moderator
7899
Keith Watford 2014.08.01 19:09  
jfortes:

Shouldn't the  ObjectGetValueByShift(trendlineName,1)  return the value of the trendline at a specific Shift 1 ??

Yes, it works as expected on my platform (build 670)

jfortes:

The problem is that the price returned by ObjectGetValueByShift(trendlineName,1)  is not at the Shift 1 (in relation to Time[0] ) , but in relation to anchor point 2.

Are you moving the trend-line's 2nd anchor point to Close[1] in your code?
John
79
John 2014.08.02 06:37  

Anchor point 2 is static. I'm using build 670.

You can close the ticket, I've managed to resolve this issue with a linear regression function. 

Ian Venner
2583
Ian Venner 2014.08.03 14:08  
  • ObjectGetvalueByShift() works correctly.
  • None of the coordinates of a trend line are static.
  • There is no need to move anchor points to extend the trend line use OBJPROP_RAY.
  • The shift parameter is not relative to Anchor point 2. It is relative to Time[0].
/
To add comments, please log in or register