Trendline in my EA - page 2

 
ydrol:

Hi

There is no built in automatic trendline function for exactly the same reasons I've spelt out in my last two posts.

However you're getting there in the detail, but still think you are making some assumptions about things, and ignoring the fact that a line does not often exactly touch the 3 points, if you look very closely.

Some of the indicators you will find are automated, and may even do what you want, if the author was after the same thing.

Other than that you will have to roll your own or get a programmer to help, just be aware that trendlines ( and Support/Resistance) are somewhat subjective and open to interpretation and this is why there are no built in indicators.

But it is possible :)

So use the first two points for two simulaneous equations price1 = m * bar1 + c and price2 = m * bar2 + c, and solve for m and c. Then, as mentioned before (in fact in almost every post I've made to this thread) you will need a tolerance for the 3rd point. ie. m * bar3 + c is approximately equal to price3.

In fact I think your lines may be better approximations if you first pick the two ends and then look for 3rd point in the middle.

Also you have to make sure no intermediate points significantly breach the line. (ie the line is above all other highs). Tha'ts fairly simple, for all other bars make sure: m * barN + c +some margin <= priceN (for highs - reverse for lows)

[This can be checked at the same time you are looking for the 3rd point, as the equation is the same. IF the price is withing tolerance then its a point 'on the line' otherwise if price is well above expected price then line is broken.]


Once you have selected your points you can just assume the line is y=mx + c or recalculate a best fit line for the 3 points (eg using use least squares to draw trendline, )

For 'x' part of the equation, if you use barnumber, You may have to code around weekend bars depending on what broker sends (unless these are intraday trend lines)

Another option is to use the actual time rather than the bar number.

Simple :)


Ok i will try to study your solution it looks really interesting.That equation looks like the line equation y=ax+b, and there was an equation where you can implement with an intersecting point, the 3rd one.I`m starting to feel myself in back to school days in math class :D.Anyway you mentioned a margin of error, which i guess will be needed to let even the bad setups pass our filter which i guess is bad.I mean a trendline is just a line and everything what goes beyond it is considered a fakeout or breakout.But in my EA thats the point,sorry if i didnt mentioned it earlier but this would be a scalper EA which trades these fakeouts.So there is no room for margin of error because we will miss good trades there.

The other solution i was thinking about would be much simplier we could use a simple moving average which is set to period 1 and shift 1 that would be our price action's variable.And we could plot not all but some local maximum/minimums in forms of the extreme max/min High/Lows and test them.The algorithm would be to pick local max/min points and check if they are ascending/descending via the previous ones and then compare them with the price action MA, what do you think?

Anyways i appreciate your help,thanks!

 

I've not played with MA,shift but immediate thoughts are 1) you cant shift into the future so it will always be laggy or missing information, and MA would lose accuracy which you desire. Stick to your trendline IMO.

Again I suspect there is an indicator out there which will do what you want (with or without tweaking),

as there are many different trendline indicators because it seems such an obvious feature gap (for good reason as discussed before), but many have endeavoured to fill the gap just as you are doing?

You may even find an active author of a trendline indicator willing to enhance/modify it to your requirements? The detail above is certainly enough (now :) ) to make a first coding attempt/prototype and review the results ...

 
Proximus:
I dont think this is the one, this needs manual line to be drawn, while my EA is fully automated.

don't agree come with a good comment after you tested the indicator not before

that way you don't have to say I dont think this is the one

and come then with something totally nonsens like you did now this needs manual line to be drawn

your wrong makes me think you didn't look what the indicator is doing on a chart see QuickFib

 
Proximus:

Isn't there a build in function in MQL4 which can handle trendlines, just as normal moving averages,but straight ones to keep it simple?


https://docs.mql4.com/objects/ObjectGetValueByShift
 
Proximus:
2) The next question i believe how i select high/lows.Well thats easy, i will have a variable called "CHECKBARS" which will be an int and can be set to check as many bars back in history as i want.Lets say it is set to 30 then we will check back 30 bars excluding the current bar.The entire "trendline code" will be inside a for() .Which will go from CHECKBARS down to 1, exluding 0 the current bar.So we will go through 30 bars and pick the every high that comes along and test if there is any other 2 highs in the 30 bars that could form a line, so for example if it finds High[CHECKBARS] and High[CHECKBARS-5] to align perfectly with High[CHECKBARS-7] then you got a nice downtrend.But we must test all combinations available to be accurate.


You write about _where_ you want to find the highs, not about _how_ you want to find them.

Trendlines are created by connecting lower swing highs or higher swing lows, like on the link I sent earlier.

BTW, 30 bars are not always enough to find the second point of the TL.

If you want to use simply the High[] of the bars then TL is not what you want, I think you should use something like MA(10) of price_high and MA(10) of price_low (applied price).

 
Proximus:

Isn't there a build in function in MQL4 which can handle trendlines, just as normal moving averages,but straight ones to keep it simple?

szgy74:

https://docs.mql4.com/objects/ObjectGetValueByShift


Hi, Proxmus means he wants the trendline computed. - not just referencing an existing trendline.
 
Proximus:

Anyway you mentioned a margin of error, which i guess will be needed to let even the bad setups pass our filter which i guess is bad.I mean a trendline is just a line and everything what goes beyond it is considered a fakeout or breakout.But in my EA thats the point,sorry if i didnt mentioned it earlier but this would be a scalper EA which trades these fakeouts.So there is no room for margin of error because we will miss good trades there.



this has nothing to to with fakeouts, you simply won't (or very rarely) find a TL where 3 points match exactly the same line to the 5th digits - maybe only on very low timeframes.

In many cases price does not touch exactly the line but moves to some point near the line. I suggest spend more time on studying trendlines.

 
ydrol:

Hi, Proxmus means he wants the trendline computed. - not just referencing an existing trendline.

OK, it's only about avoiding the math for finding the 3rd point.
 
szgy74:

OK, it's only about avoiding the math for finding the 3rd point.

Ah makes sense! Nice and easy... Not sure about performance, as potentially many lines to draw, but very simple to code.
 
deVries:

don't agree come with a good comment after you tested the indicator not before

that way you don't have to say I dont think this is the one

and come then with something totally nonsens like you did now this needs manual line to be drawn

your wrong makes me think you didn't look what the indicator is doing on a chart see QuickFib

You are right for a moment i was confusing it with another one.They have similar name.Actually this ones is nice,but I need trendlines independently without fibo first.Plus even if i`d need this it doesnt have buffers from where to extract the data.This is the problem with many good indicators, either they need manual intervention or they dont have buffers :(

Now this one is getting very close to my desires.Can you please detail it since the documentation is always not very informative.

szgy74:


this has nothing to to with fakeouts, you simply won't (or very rarely) find a TL where 3 points match exactly the same line to the 5th digits - maybe only on very low timeframes.

In many cases price does not touch exactly the line but moves to some point near the line. I suggest spend more time on studying trendlines.

Just let that be my problem.This system is designed for short term trend trading on M5 or M1 so yes it is on low TF.