if(!ObjectCreate(ChartID(),"VLine",OBJ_VLINE,0,0,0))
ok, ive tried to increment the name so its not repeated, now have an error code#0 "#define ERR_NO_ERROR"...(Edited as this is incorrect, I am get getting 4200 code error)
I am trying to create a line in the indicator_separate_window.. code amendment below
any ideas..Thanks
for (i=limit;i>=0;i--) // ...mod realtime old stmt for (i=limit-1;i>=0;i--) old stmt { MaBuf[i] = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,i)); MbBuf[i] = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,i)); } for (i=0;i<limit;i++) int lineIncrement=0; string lineName = StringConcatenate("VLine", lineIncrement); // assemble the object name { double currentRSI = MaBuf[i]; double previousRSI = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,i+1)); double currentSignal = MbBuf[i]; double previousSignal = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,i+1)); if(previousRSI < previousSignal && currentRSI > previousSignal) if(!ObjectCreate(ChartID(),lineName,OBJ_VLINE,0,0,0)) Print("Error: can't create label! code #",GetLastError()); lineIncrement++; } //---- return(0); }
Not sure why I got Code 0, NO ERROR, I now have same error as before 4200, amended code as above...
Not sure why I got Code 0, NO ERROR, I now have same error as before 4200, amended code as above...
You are still getting the same error, because you are still generating duplicates:
- An indicator's "OnCalculate()" can be called multiple times for the same indices due to various reasons, so don't assume that an Index will be calculated only once.
- Also, the number of bars (or "rates_total") can change during its lifetime so bar indexing is not guaranteed to always sync at the same bar.
- For these reasons, don't use the Bar Index for generating the Chart Names but use the bar's time instead.
- Since an indicator can be called to regenerate, you have to test for the existence of the object by using the ObjectFind() function and if found, apply a "ObjectMove()" to adjust it to its new position instead of trying to recreate it (which will give you the 4200 error).
ok, I have a line now, but the line moves along the chart and doesnt stay at the cross, I would like the line to stop at the cross i.e multiple lines on chart, I tried using ObjectSet but no good, what can you suggest
cheers
for (i=0;i<limit;i++) int lineIncrement=0; string lineName = StringConcatenate("VLine", lineIncrement); // assemble the object name { double currentRSI = MaBuf[i]; double previousRSI = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,i+1)); double currentSignal = MbBuf[i]; double previousSignal = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,i+1)); if(previousRSI < previousSignal && currentRSI > previousSignal) if(!ObjectCreate(ChartID(),lineName,OBJ_VLINE,0,TimeCurrent(),0)) if(!ObjectSet(lineName,OBJPROP_TIME1,TimeCurrent())) if(!ObjectFind(ChartID(),lineName)) if(!ObjectMove(lineName,0,TimeCurrent(),0)) Print("Error: can't create label! code #",GetLastError()); lineIncrement++; } //---- return(0); }
ok, I have a line now, but the line moves along the chart and doesnt stay at the cross, I would like the line to stop at the cross i.e multiple lines on chart, I tried using ObjectSet but no good, what can you suggest
- Well, if you don't want it to change position, then don't use "ObjectMove()". Only use it if you want to change its position! Duh!
- You should use "ObjectFind()" BEFORE using "ObjectCreate()", NOT after! What is the point of using it after the error has already been generated?
- You have code blocks in the wrong places. Your parenthesis are misplaced, especially for the "for" loop.
- You are still using the Bar Index/Counter to build the name instead of using the bar time. You did not correct that.
- Also, you are initialising the "lineIncrement" within the for loop, instead of before/outside it.
- Use parenthesis on "if" statements as well to make your code more clear and prevent incorrect logic.
ok, thanks eddie, FMIC, I see I have to sort my coding out.
thanks will let you know how i get on
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
Hello
Im trying to draw lines when the RSI and the signal line cross on a TDI indicator.
I added a loop to the code as shown to try to create vertical lines, complies but in strategy tester i get #4200 error "#define ERR_OBJECT_ALREADY_EXISTS"
Im not sure where it exists. Maybe my loop incorrect..?
Appreciate some help
Thanks Craig