MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Check MetaTrader Market in order to find your Expert Advisor

problem about cross of two trend lines

Back to topics list To post a new topic, please log in or register
avatar
32
Poll: Traders’ Estimate of the Mobile Terminal

Poll: Traders’ Estimate of the Mobile Terminal

Unfortunately, there are no clear projections available at this moment about the future of the mobile trading. However, there are a lot of speculations surrounding this matter. In our attempt to resolve this ambiguity we decided to conduct a survey among traders to find out their opinion about our mobile terminals. Through the efforts of this survey, we have managed to established a clear picture of what our clients currently think about the product as well as their requests and wishes in future developments of our mobile terminals.

avatar
32
maniac1984 2012.01.22 14:11 #
 
#property copyright ""
#property link      ""
//---Header Files-----------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 1

datetime X1 = D'2010.07.15 16:00';
double   Y1 = 1.332603;
datetime X2 = D'2010.09.10 16:00';
double   Y2 = 1.227437;
datetime X3 = D'2010.07.09 08:00';
double   Y3 = 1.22197;
datetime X4 = D'2010.09.08 00:00';
double   Y4 = 1.33196;

//--------------------------------------------------------------------
int init()
{
   return(0);
}
//---------------------------------------------------------
int deinit()
{
   return(0);
}
//---------------------------------------------------------
int start()
{
   Comment( TimeToStr(LinesCrossTime(X1,Y1,X2,Y2,X3,Y3,X4,Y4)) + " , " + DoubleToStr(LinesCrossLevel(X1,Y1,X2,Y2,X3,Y3,X4,Y4),5) );
   
   return(0);
}
//---------------------------------------------------------
datetime LinesCrossTime(datetime X1, double Y1, datetime X2, double Y2, datetime X3, double Y3, datetime X4, double Y4) 
{
   double M1 = (Y2-Y1)/(X2-X1);
   double M3 = (Y4-Y3)/(X4-X3);
   
   return ((M1*X1-M3*X3+Y3-Y1)/(M1-M3));
}
//--------------------------------------------------------
double LinesCrossLevel(datetime X1, double Y1, datetime X2, double Y2, datetime X3, double Y3, datetime X4, double Y4) 
{
   double M1 = (Y2-Y1)/(X2-X1);
   double M3 = (Y4-Y3)/(X4-X3);
   
   double crossPoint = (M1*X1-M3*X3+Y3-Y1)/(M1-M3);
   
   int i =0;
   while (Time[i]>crossPoint)
      i++;
   return(Close[i-1]);   
}  

avatar
14046
RaptorUK 2012.01.22 14:37 #
 

A trend line is a linear function, y = mx + c, so with 2 trend lines you have 2 linear functions so all you need to do is solve the 2 equations when y and x are the same for both equations. First you need the m and c values for each line, c is the offset of each line at the same time coordinate, and m is the gradient/slope. Once you have your 2 equations you use substitution and you substitute for y in one equation by using the 2nd,

e.g. y = 0.8x + 1.2 & y = 1.5x + 2.2 so 0.8x + 1.2 = 1.5x + 2.2 where the lines cross and solving this gives you x coordinate.

Not sure what happens when you have a weekend in the mix . . .

 
avatar
32
maniac1984 2012.01.22 15:53 #
 
RaptorUK:

A trend line is a linear function, y = mx + c, so with 2 trend lines you have 2 linear functions so all you need to do is solve the 2 equations when y and x are the same for both equations. First you need the m and c values for each line, c is the offset of each line at the same time coordinate, and m is the gradient/slope. Once you have your 2 equations you use substitution and you substitute for y in one equation by using the 2nd,

e.g. y = 0.8x + 1.2 & y = 1.5x + 2.2 so 0.8x + 1.2 = 1.5x + 2.2 where the lines cross and solving this gives you x coordinate.

Not sure what happens when you have a weekend in the mix . . .


at first excuse for my english.

thanks dear RaptorUK for reply.

i know that and my problem is something else.

when i change timeframe to other timeframe or zoom in or zoom out the value also changes.

and my main problem is price no time.

i need my func returns the price of crossing without any wrong.

can you help me too about this:

if i have the corner of lines and one of price from each line can i do that?

and if yes how?

thanks

best regards



 
avatar
9421
WHRoeder 2012.01.22 18:31 #
 

maniac1984:

when i change timeframe to other timeframe or zoom in or zoom out the value also changes.

and my main problem is price no time.

  1. Solve the two equations like Raptor said. The result is one x and one y. Y is price.
  2. if you change timeframes and your code generates different trendlines, of course the value will change.
  3. if you zoom in or our and your code generates different trendlines, your code is broken.
 
avatar
32
maniac1984 2012.01.22 20:04 #
 
WHRoeder:
  1. Solve the two equations like Raptor said. The result is one x and one y. Y is price.
  2. if you change timeframes and your code generates different trendlines, of course the value will change.
  3. if you zoom in or our and your code generates different trendlines, your code is broken.

thanks dear WHRoeder

i will check it.


Back to topics list  

To add comments, please log in or register