MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
MetaTrader Market: we have 650 Expert Advisors for algorithmic trading!

Angled Trendlines

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
5
depasqda 2007.10.13 12:11
 

Hi Eveyone

I would like to know if anyone knows how to code an angled trendline.

I am wanting to draw an angled trendline from point a to point b then point c etc,

After I have coded the angled trendlines then I would like to store the angles from each trendline and put them in an array for later us.

If anyone has any pointers that would be great

thanks

dd

 
Credit Suisse has hiked pay. And it’s hiring
Credit Suisse’s third quarter results are out. Inexplicably, the Swiss bank is deferring its full financial release until October 31st, but in the meantime there’s still plenty to go on. Credit Suisse’s current investment banking staff will be pleased to hear that pay is up. Credit Suisse’s would-be investment banking staff will also be pleased to hear that the bank might be doing some hiring.
avatar
2646
phy 2007.10.13 17:41 #
 

Certainly.

Angle and slope are synonymous.

Draw a line with a slope of 0.618 for example:

int start(){
 string name = "a";
 double theSlope= 0.618;
 int startBar = 39;
 int runBars = 7; 
 double price = Close[startBar];
 double angle;
 if(ObjectFind(name) != -1) ObjectDelete(name);
 ObjectCreate(name, OBJ_TREND, 0, Time[startBar], price, Time[startBar-runBars], price + (runBars * theSlope * Point));
 angle = MathArctan(theSlope)/ 3.1415965 * 180;
 Comment("The angle of line "+name+" is "+DoubleToStr(angle, 2)+" degrees");
 return(0);
}

By rearranging things a bit, you can find the angle of an arbitrary line, or draw a line at an arbitrary angle.

The angle will be "visually" correct only on a squared chart (in chart properties scale fix 1:1).

 
avatar
5
depasqda 2007.10.15 15:49 #
 

Hi PHY

Thanks for your input, had me a lot

dd

avatar
597
irusoh1 2007.10.17 20:11 #
 
There is an object in MT called trendline by angle, if it is any use to you.
avatar
2646
phy 2007.10.17 21:13 #
 

Trendline by angle is usable on a squared chart only. It is a "visual" angle tied to the monitor, not the chart.

A 45 degree Trendline by Angle is a visual 45 degree line on your display. zoom in zoom out or squeeze the
vertical price scale, the line stays put at a 45 degree visual angle.

Therefore, it has no relation to time or price, unless you happen to know the ratio of pips to time you have on
the chart.

The only "known" setup is 1:1, and that is useless for higher timeframes.

For trading purposes, an angle needs to be defined in terms of price and time, thus sticking it to the chart. In
that scenario, a 45 degree line is a slope of 1 unit of price change in 1 uint of time change, with units defined
by your imagination or application.

 
avatar
476
bonechair 2007.11.14 09:54 #
 
phy wrote:

Certainly.

Angle and slope are synonymous.

Draw a line with a slope of 0.618 for example:

int start(){
 string name = "a";
 double theSlope= 0.618;
 int startBar = 39;
 int runBars = 7; 
 double price = Close[startBar];
 double angle;
 if(ObjectFind(name) != -1) ObjectDelete(name);
 ObjectCreate(name, OBJ_TREND, 0, Time[startBar], price, Time[startBar-runBars], price + (runBars * theSlope * Point));
 angle = MathArctan(theSlope)/ 3.1415965 * 180;
 Comment("The angle of line "+name+" is "+DoubleToStr(angle, 2)+" degrees");
 return(0);
}

By rearranging things a bit, you can find the angle of an arbitrary line, or draw a line at an arbitrary angle.

The angle will be "visually" correct only on a squared chart (in chart properties scale fix 1:1).


Hi

Howdo you get the slope of the line. It says here 0.618 but how do you get that slope off OBJ_TREND?
 
avatar
2646
phy 2007.11.14 10:07 #
 
avatar
476
bonechair 2007.11.14 16:43 #
 
I was hoping for a quicker solution. Does this mean I have to draw a x and y line on the middle of my trendline and then figure out the xy of it?
 
avatar
2646
phy 2007.11.14 20:25 #
 

The geometry examples use X and Y often for the coordinate system.

Q. What is the coordinate system on a chart?

A. Time and Price -- X and Y

Ponder some more...

 
avatar
476
bonechair 2007.11.14 22:14 #
 
I did try this before:
double theSlope = (price2 - price1)/(Time[0]-Time[n]);
Comment(theSlope);
Not sure howto put it. Im getting 0 output.
 
avatar
2646
phy 2007.11.14 22:57 #
 

Use bar count, not clock time

Back to topics list   | 1 2  

To add comments, please log in or register