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
I suspect that the object isn't drawn fully for the first 2 loops . . .
I have had problems with Comment when running the ST at max speed and grabbing a chart, the comment can lag the chart and I have had comment data that was wrong for the chart it was drawn on, as a result I switched to a Label Object and that fixed my issue.
Try this . . . run at full speed, then at the pause switch to 31 and resume.
The first 10 values are 0 because the channel stops 10 bars ago . . .
I tried your code with this modificaltion:
But it not creates even an error code! By placing a Sleep(1); after Object creating lines, the error disappears. But how we know how much time is needed to draw the object, when will be ready, if there is no error code?
I suspect that the object isn't drawn fully for the first 2 loops . . .
I have had problems with Comment when running the ST at max speed and grabbing a chart, the comment can lag the chart and I have had comment data that was wrong for the chart it was drawn on, as a result I switched to a Label Object and that fixed my issue.
Try this . . . run at full speed, then at the pause switch to 31 and resume.
The first 10 values are 0 because the channel stops 10 bars ago . . .
Interesting method. I tried it. Thanks :-)
Erzo (thank you) your Sleep(1) is the same thing basically. It looks like the regression line has been spawned to a new thread and it does not complete before the ObjectCreate command returns. Therefore some random delay is needed to make it work. That is not a robust solution and could mess up in a real time environment. I suppose we could put in a while loop and just wait until the first value of the regression line is both non-zero and equal to the value by shift function - but that seems too much of a bodge.
I think it is easier to steal the regression code from that indicator I linked to earlier.
Well here it is in a script for anyone who is interested ...
The comparison to the internal regression line is perfect and the trendline version gets covered by the other regression line, even though the trendline version is drawn afterwards.
I found the source code for the regression line from Metaquotes, linked here for reference.
https://www.mql5.com/en/forum/45148
Unsurprisingly it is almost identical with mine. The sad thing is that the calculation of the standard deviation channel is not there. Mine is close to the built in version but is in error by about 5% high or low depending on the chart and the length :-(
This code follows immediately after code above (but before the return in the DIYregress function). Using OBJ_STDDEVCHANNEL for this comparison.
This code follows on from the line ObjectSet( "DIY", OBJPROP_RAY, false );
Dabbler I discovered by testing MQ uses population deviation. It's slightly different to regular deviation, that might be the cause of your 5% dev error. Here is my test script. Place a Std Dev Channel on the chart and name it "testchannel". Script tries to find the line equations of that testchannel and then draws trendlines of them, so it should match testchannel with 3 trendlines. I let my ones ray so you can see them.