Beginner's Journey - 2 Trend line scripts (functional works in progress) Advice and feedback appreciated!

 

Greetings!

I am new to the community, working in mql4, and wanted to share my coding journey so far. I invite you all to join me towards my goal of creating a profitable EA!

I hope to learn from everyone and hopefully contribute as well!

Attached are two scripts for creating outer (major trend lines) by connecting (for downtrends) the highest point to the next highest point,and (for uptrends) the lowest point to the next lowest point, where the trend line is never intersected by price (remains unbroken).

My goal is to share what I intended to create, what I think I created, the code itself, and my future goals.


The theory for v14 is, for the given chart and timeframe it's executed on, to find the miniums/maximums (points where the previous and subsequent lows/highs are higher/lower, i.e. -+- or +-+ ), then draw a new trend line at each, and delete the old one, until an unbroken trend line is drawn.

In application, the code draws the trend line at the first combination of points, and then draws new trend lines at the highs/lows where the trend line is broken untill it makes an unbroken trend line.

The trend lines are named according to their time frame, up or down trend, and number of lines created to arrive at the final line.

This was my first attempt at creating a trend line script and looking back there are many sections that are questionable and I am still kind of figuring out how that one works.

Side note: does this happen to other coders? what do you do to be more aware of your code and its functionality? what a strange feeling when your code works but you're not sure how!


The theory for v15 is, for all time frames of the chart it's executed on, to draw trend lines from the highest/lowest points to the next highest/lowest points until an unbroken trend line is drawn.I also hoped to make one script that would apply to all time frames for the chart it is executed on.

This code finds the highest/lowest points and creates trend lines using the highest/lowest and next highest/lowest points.

If the trend line is broken, it creates a new line with the original first point and the next highest/lowest point after the bar (shift) of the break. '

It deletes the old trend line each time a new one is made.

The trend lines are named according to their time frame, up or down trend, and number of lines created to arrive at the final line.

While it can create lines based on each time frame, I find that they are only reliable for the time frame that the script is executed on. That is why I included an if statement to choose which timeframe to run it on.

 I believe this occurs because of how the bar times are structured. For example, if a high is located at minute 3, the higher time frames will have trouble accurately rendering the point because they do not incorporate a time ending in minute three, only times ending in 0 or 5. Do you have any advice on how to think of a solution for this issue?



My goals now are:

Learn from these codes and optimize them

Make an automated way to run the script on each timeframe

Share the final versions for use with the community

Plan how to turn these scripts into a profitable EA

Become a good contributor to this community


Thank you for sharing your time to read this and I look forward to communicating with you! Any advice and commentary is much appreciated!


PS - I only use these scripts on Demo account right now,

Shoutout to boolapi for their awesome EA that alerts you when trend lines are touched by price!

https://www.mql5.com/en/code/12598

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
v15.mq4  8 kb
v14.mq4  10 kb
 
Hi, remember that many optimizes EA could overfit to historical data. Good luck :) Regards Greg
 
Grzegorz Pawlak #:
Hi, remember that many optimizes EA could overfit to historical data. Good luck :) Regards Greg

Hi thank you so much for your response!

Do you mean that the EA will try to use data that is not currently available? I am not sure what overfit to historical data means


Also i see you live in Poland, that is so cool, my family name is Osowski. I wonder if you may know of any distant relatives I have?


thank you!

Reason: