CreateObject not moving with TimeCurrent in chart

 

Hi,

I used ObjectCreate to put some objects on the chart within the strategy tester. However, TimeCurrent and the bid price seem to have no effect. I want the objects to move with current as well as the bid price but they remain static. Any ideas?

void OnTick() {

   ObjectCreate(0,"test9999",OBJ_ARROW_LEFT_PRICE,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID)-0.001);
   ObjectCreate(0,"test9991",OBJ_ARROW_RIGHT_PRICE,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID)-0.001);
   ObjectCreate(0,"test9992",OBJ_ARROW_SELL,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID)-0.001);
   ObjectCreate(0,"test9993",OBJ_VLINE,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID));

   Print(TimeCurrent());

}

 
https://www.mql5.com/en/docs/chart_operations/chartredraw
Documentation on MQL5: Chart Operations / ChartRedraw
Documentation on MQL5: Chart Operations / ChartRedraw
  • www.mql5.com
Chart Operations / ChartRedraw - Reference on algorithmic/automated trading language for MetaTrader 5
 
syrvn 0:

Hi,

I used ObjectCreate to put some objects on the chart within the strategy tester. However, TimeCurrent and the bid price seem to have no effect. I want the objects to move with current as well as the bid price but they remain static. Any ideas?

void OnTick() {

   ObjectCreate(0,"test9999",OBJ_ARROW_LEFT_PRICE,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID)-0.001);
   ObjectCreate(0,"test9991",OBJ_ARROW_RIGHT_PRICE,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID)-0.001);
   ObjectCreate(0,"test9992",OBJ_ARROW_SELL,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID)-0.001);
   ObjectCreate(0,"test9993",OBJ_VLINE,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID));

   Print(TimeCurrent());

}

You are trying to create multiple objects with the same name. It's not allowed.

You have to either delete and recreate objects on each tick or use ObjectMove().

Also, you should always check the return value of the ObjectCreate() and react if you get an error. 

 
Thank you guys for your answers. I havent had yet the time to look into your suggestions but I think that is what I was missing. I think both approaches, the ChartRedraw as well as the ObjectMove / ObjectSet, will work. I come back to you guys later and let you know. Thanks for your Support! Kindly appreciated
Reason: