Since your code is for a Script, as soon as it terminates, the indicator handle is released, and consequently the Indicator that was added by it, is removed.
EDIT: Seems my logic is incorrect! My apologies for the misinformation!
Hi All,
I've searched everywhere for the answer to how to draw a MA on a newly opened chart.
The chart opens as expected, but no MA.
Here is the code, but I'm missing something somewhere.
Any help would be much appreciated.You are adding the indicator to the current chart.
You need to add it to the newly opened chart.
ChartIndicatorAdd(_longchart,0,_mahandle);
Thankyou Gentlemen, all is revealed.
Have nice days
Cheers ..... G-fer
Hi All,
Thanks for your help with the moving average issue.
I would like to add a comment to the new chart, too.
This code compiles properly, but the comments is places on the chart that was open when the script is run.
Any ideas?
Cheers ...
void OnStart() { long _longchart = ChartOpen("AUDUSD.a",60); // Open the chart of interest on the requested time frame int _mahandle=iMA("AUDUSD.a",0,60,0,MODE_SMA,PRICE_CLOSE); // get the moving average handle ChartIndicatorAdd(_longchart,0,_mahandle); // Draw the indicator Comment("This is a test comment"); }
The Comment function always applies to the current chart. As you can see from the documentation, it does not have any parameter for selecting a target chart.
However, if you read the Comment documentation, you will notice that it instructs you to also read about ChartSetString and ChartGetString.
So, instead of Comment, use the ChartSetString function with CHART_COMMENT property.
Sets the string value for a corresponding property of the specified chart
ID
Description
Property Type
Text of a comment in a chart
string
Thank you Mr. C,
I replaced
Comment("This is a test comment");
with
ChartSetString(_longchart,CHART_COMMENT,"This is a test comment");
and that worked perfectly.
Cheers ....

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
I've searched everywhere for the answer to how to draw a MA on a newly opened chart.
The chart opens as expected, but no MA.
Here is the code, but I'm missing something somewhere.
Any help would be much appreciated.