double sma = iMA(NULL,0,n,0,MODE_SMA,PRICE_OPEN,0); ObjectCreate(0,"Horiz_Line",OBJ_HLINE,0,0,sma); ObjectSetInteger(0,"Horiz_Line",OBJPROP_WIDTH,3); ObjectSetInteger(0,"Horiz_Line",OBJPROP_COLOR,clrGreen);
What is the value of n?
Make sure that the object "Horiz_Line" has not already been created as it may be elsewhere and off screen.
What is the value of n?
Make sure that the object "Horiz_Line" has not already been created as it may be elsewhere and off screen.
Sorry, Keith, I've changed the value of n to 10.
It hasn't already been created, upon OnInit() I set it to clear all objects on the chart to ensure that no "residual" objects remain, so it should'nt be offscreen either :)
Sorry, Keith, I've changed the value of n to 10.
It hasn't already been created, upon OnInit() I set it to clear all objects on the chart to ensure that no "residual" objects remain, so it should'nt be offscreen either :)
Then GetLastError() after the code to create the object (If it fails).
Code updated:
double sma = iMA(NULL,0,10,0,MODE_SMA,PRICE_OPEN,0); if(!ObjectCreate(0,"Horiz_Line",OBJ_HLINE,0,0,sma)){ PrintFormat("Draw Line Error %d",_LastError); } else { Print("Your line has been drawn, you just can't see the blighter!"); ObjectSetInteger(0,"Horiz_Line",OBJPROP_WIDTH,3); ObjectSetInteger(0,"Horiz_Line",OBJPROP_COLOR,clrGreen); }
The print result is the following:
2022.06.09 10:50:48.633 xxx EURCHF,H4: Your line has been drawn, you just can't see the blighter!
So no ObjectAlreadyExists error is returning, which says to me it's either plotting somewhere else off of the chart, or it's not picking up with width or the colour.
Odd. :)
Hello,
I didn't find the problem in your code.
double sma = iMA(NULL,0,10,0,MODE_SMA,PRICE_OPEN,0); Print("sma: ",sma); ObjectCreate(0,"Horiz_Line",OBJ_HLINE,0,0,sma); ObjectSetInteger(0,"Horiz_Line",OBJPROP_WIDTH,3); ObjectSetInteger(0,"Horiz_Line",OBJPROP_COLOR,clrGreen);
On my chart, I found your green horizontal line :)
or you can try to give another color for that horizontal line.
Who knows that way you can see it.
Don't do that. Someone searching might find this thread and still be clueless. What was the problem? What solved what?
How To Ask Questions The Smart Way. (2004)
When You Ask.
Follow up with a brief note on the solution.
Don't do that. Someone searching might find this thread and still be clueless. What was the problem? What solved what?
How To Ask Questions The Smart Way. (2004)
When You Ask.
Follow up with a brief note on the solution.
Fair point.
I initiated an ObjectDeleteAll() on OnInit after the ObjectCreate() function, meaning that as the programme reads down the page, it created the plotted lines then immediately deleted them, as it was programmed to do.
I did place an ObjectDeleteAll() to remove any objects from the chart which may have been drawn/plotted during the previous session, so the EA initialises on a fresh chart. This is also in case there were errors on the code which resulted in the EA not deleting any objects from previous sessions, as a time-saving function.
It was just a simple solution of placing the ObjectDelete() function BEFORE the ObjectCreate() function so the EA initialises with just the lines plotted after any other object is deleted. It deletes any objects on the chart, and then it created the plotted lines.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Morning,
So I'm plotting a horizontal line on my chart, except I'm not.
My code is the following:
For demonstration purposes I have simply plotted the line to be at the current SMA price. The place I actually want to plot the line requires significant coding and so wanted to keep it simple for here, as per Forum guidelines.
I don't see what the problem is here.
All the best,