I found the below mentioned snippet somewhere online and am trying to use it inside `OnCaculate()` function to draw a horizontal line on, let's say the maximum value in last 5 minutes.
I see this error in the log window:
"OnCalculate: Failed to create a horizontal line! Error code =4200"
What is wrong in this snippet? If it is incorrect, please guide me with a correct way.
![4200 Object Already Exists Error for Chart Object. 4200 Object Already Exists Error for Chart Object.](https://c.mql5.com/36/82/4200-object-already-exists-error.jpg)
- 2021.11.30
- www.mql5.com
Every tick arriving causes OnCaculate to execute. The first call it creates the horizontal line but the next call there is error 4200 because the object already exists.
One solution is removing object using ObjectDelete before creating it again.
Every tick, OnCalculate is called. You are trying to create the same object every tick. It exists after the first tick, thus the error 4200.
Create the line in OnInit. Delete it in OnDeinit. Move it to the new location in OnCalculate.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I found the below mentioned snippet somewhere online and am trying to use it inside `OnCaculate()` function to draw a horizontal line on, let's say the maximum value in last 5 minutes.
I see this error in the log window:
"OnCalculate: Failed to create a horizontal line! Error code =4200"
What is wrong in this snippet? If it is incorrect, please guide me with a correct way.