Is it possbile to set a different color for all (trend)lines in the chart at once (maybe a script)? - page 3

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
This will only be correct when i == 1
Wow, it seems to be much harder then I thought. But I understand that it is wrong to create the Objects every tick. But how can I do it instead? I read that the start() code is executed on every tick. Where can I create the Objects? Or do I have to check if the Objects exist before creating them? I also have to idea what init() is for. Maybe I have to check for objects or clear all objects in the init() part?
@WHRoeder: I don't really understand how the calculation to find the midnight-bar really works. I googled how to find this particular bar and found that solution. But I have no idea how to correct my error with iTime(). It would be great if you explained me how exactly I find the midnight-bar (or some other specified bar). I don't mean the code, I mean the logic. Unfortunately I really don't understand a little bit what these midnight-formulas are about. I understand the syntax but here again not the logic itself.. What does it mean when something is multiplied with PERIOD_H1 ? 24*PERIOD_H1*60 makes absolutely no sense to me..
What you wrote (iTime(NULL, Period_D1, 0)) to find the last midnight bar is clear to me. But then how many bars do I have to go back to find the midnight before when I don't know which timeframe is used. It is so complicated for a beginner...
Nevertheless I appreciate your help, guys!
If you look at the documentation for PERIOD_H1, you will see that it represents an integer that is equal to the chart time-frame in minutes.
So on the H1 chart, it is 60. Multiplying this by 60 will give the seconds in 1 hour, datetime is in seconds, so you need to calculate with seconds.
You could just use 3600, but using PERIOD_H1 makes the code easily readable.
Hello GumRai,
thank you, that helped me a lot! I didn't know that datetime is in seconds. That makes many things much more understandable for me.
I still have no idea how to do ti that the lines are not printed every tick but I understand how to find the correct datetime now..
Hello GumRai,
thank you, that helped me a lot! I didn't know that datetime is in seconds. That makes many things much more understandable for me.
I still have no idea how to do ti that the lines are not printed every tick but I understand how to find the correct datetime now..
You know the name of the object, so use ObjectFind() to see if the object already exists.
Ok, now I check it before. Is that ok? Now I only have to calculate the correct highs and lows to start the lines. Finding the correct midnights is still a problem for me. Especially when I consider weekends, as WHRoeder said.