MoveTrendLine function
Posted: 28 Jul 2010
NOTE: The final version is attached to the last post. Please read that post and study the functions before using them.
I have always found that moving trend lines was more of a challenge than it should be so I finally wrote this function to do it for me properly. I searched and this appears to be the first function like this. It can save you a lot of headaches in strange trend line moves.
So far it works. I tested it moving a trend line to various places in every combination I could come up with and could not get it to fail. My test script is included in the zip but it requires an external program to signal it for running so it may not be of any value to you. I just wrote it yesterday so it has not had long term testing. Therefore, if someone does find a situation where it does not measure up and you create a fix for it please let me know.
You have to submit the date1 and time1 as in the past relative to the date2 and time2 set which are to be in the future. If you invert them it aborts the function. There is a caller field at the very start where you can indicate where you called it from to help with debugging if these date/time pairs ever get flipped the wrong way. I already have found this useful in finding a bug in my external program which was submitting the date1/time1 to date2/time2 pairs in the incorrect order. I had 25 calls to the function in the study and I gave each call to this function a letter from "A" through to "Y". By doing that I found the problem within 3 or 4 minutes (and like I said the problem was outside the study so without this technique it could have been hours before I found the problem).
Note1: It does not seem to require you create any fine adjustments to the value1 and value2 to get it to work. It works no matter what you give it and no matter where the trend line is already. Just make sure that your trend line start date/time info is alway more in the past than your trend line end date/time info.
Note2: I find it is always better to create my trend lines in advance on currentbar = 1, hiding them and when I need to see them move them into place when I need then. This way I avoid deletion commands which can cause problems in MC. I often switch the ID to negative as a way to have the logic know in advance that the line is hidden and inactive. Hide them with negative value and black.
Here is a sample call:
value1 = A_MoveTrendLine("CallLocA",TL_ID,Date1,Time1,Value1,Date2,Time2,Value2);
I have always found that moving trend lines was more of a challenge than it should be so I finally wrote this function to do it for me properly. I searched and this appears to be the first function like this. It can save you a lot of headaches in strange trend line moves.
So far it works. I tested it moving a trend line to various places in every combination I could come up with and could not get it to fail. My test script is included in the zip but it requires an external program to signal it for running so it may not be of any value to you. I just wrote it yesterday so it has not had long term testing. Therefore, if someone does find a situation where it does not measure up and you create a fix for it please let me know.
You have to submit the date1 and time1 as in the past relative to the date2 and time2 set which are to be in the future. If you invert them it aborts the function. There is a caller field at the very start where you can indicate where you called it from to help with debugging if these date/time pairs ever get flipped the wrong way. I already have found this useful in finding a bug in my external program which was submitting the date1/time1 to date2/time2 pairs in the incorrect order. I had 25 calls to the function in the study and I gave each call to this function a letter from "A" through to "Y". By doing that I found the problem within 3 or 4 minutes (and like I said the problem was outside the study so without this technique it could have been hours before I found the problem).
Note1: It does not seem to require you create any fine adjustments to the value1 and value2 to get it to work. It works no matter what you give it and no matter where the trend line is already. Just make sure that your trend line start date/time info is alway more in the past than your trend line end date/time info.
Note2: I find it is always better to create my trend lines in advance on currentbar = 1, hiding them and when I need to see them move them into place when I need then. This way I avoid deletion commands which can cause problems in MC. I often switch the ID to negative as a way to have the logic know in advance that the line is hidden and inactive. Hide them with negative value and black.
Here is a sample call:
value1 = A_MoveTrendLine("CallLocA",TL_ID,Date1,Time1,Value1,Date2,Time2,Value2);