Object is not automatically refreshing

 

Hi,

How to make the indicator object auto refreshing tick by tick?

On my indicator I have to change into other time frame to refresh the trend lines. I tried using       

WindowRedraw();

ChartRedraw(); inside the start() funciton, where we have the code for object calculation & drawing.

I have 3 bodies in my code.

init()

start()

deinit()

Regards

 
cashcube: How to make the indicator object auto refreshing tick by tick? On my indicator I have to change into other time frame to refresh the trend lines.
Your indicator is broken. You need to fix it; that's how.
We can't help because we can't see your code.
 
WHRoeder:
cashcube: How to make the indicator object auto refreshing tick by tick? On my indicator I have to change into other time frame to refresh the trend lines.
Your indicator is broken. You need to fix it; that's how.
We can't help because we can't see your code.

string Obj_Name;
double CalcPoint;
extern color Col1 = Blue;
extern color Col = Red; // Previous Close
extern int Stl = STYLE_DOT; 
extern int Bar = 0; // History Bar

int start()
{


 datetime ND = iTime(Symbol(),PERIOD_D1,Bar);
 datetime NDD = iTime(Symbol(),PERIOD_D1,Bar)+86400;
 
 double C = iOpen(Symbol(),PERIOD_D1,Bar);

      Obj_Name="DC";             
      ObjectCreate(Obj_Name,OBJ_TREND,0,ND,C,NDD,C);
      ObjectSet(Obj_Name,OBJPROP_RAY,FALSE);  
      ObjectSet(Obj_Name,OBJPROP_COLOR, Col);      
      ObjectSet(Obj_Name,OBJPROP_STYLE, Stl); 

WindowRedraw();
ChartRedraw();
return(0);
}


int deinit()
{
      
ObjectDelete("DC");

}

 
Now can you help please?
 
Once the object is created, use ObjectMove() when you want to give it new time/price co-ordinates
 
GumRai:
Once the object is created, use ObjectMove() when you want to give it new time/price co-ordinates

Hi tried adding this code as you recommended.

    long CI = ChartID();
if(ND!=ND)
      ObjectMove(CI,Obj_Name,1,ND,C);

 But its not working still.

 
ND will never be not equal to itself.
if(ND!=ND)
 
WHRoeder:
ND will never be not equal to itself.

Then how I can check? I use current bar 0.
 
cashcube: Hi tried adding this code as you recommended.
if(ND!=ND)
GumRai: Once the object is created, use ObjectMove() when you want to give it new time/price co-ordinates
He didn't recommend that. He said to move it.
cashcube: Then how I can check? I use current bar 0.
Check what? Why do you need to check something? Just move it.
 

@cashcube: Maybe this can help you understand how to separate the Object Create from the Object Move:

#property strict

extern color clrObjectColour = Red;
extern int   intObjectStyle  = STYLE_DOT; 
extern int   intBarShift     = 0;

string strObjectName = "DailyOpen";

void OnTick()
{
   static datetime dtDayBarTime = EMPTY;
   
   if( iBars( _Symbol, PERIOD_D1 ) > intBarShift )
   {
      datetime dtStartTime = iTime( _Symbol, PERIOD_D1, intBarShift );
      
      if( dtDayBarTime != dtStartTime )
      {
         datetime dtEndTime    = dtStartTime + 86400;
         double   dblOpenPrice = iOpen( _Symbol, PERIOD_D1, intBarShift );
   
         if( dtDayBarTime == EMPTY )
         {
            ObjectCreate( strObjectName, OBJ_TREND, 0, dtStartTime, dblOpenPrice, dtEndTime, dblOpenPrice );
            
            ObjectSet( strObjectName, OBJPROP_HIDDEN, true           ); // Prevents accidental deletion of object by user
            ObjectSet( strObjectName, OBJPROP_RAY,   false           );  
            ObjectSet( strObjectName, OBJPROP_COLOR, clrObjectColour );      
            ObjectSet( strObjectName, OBJPROP_STYLE, intObjectStyle  );
         }
         else
         {
            ObjectMove( strObjectName, 0, dtStartTime, dblOpenPrice );
            ObjectMove( strObjectName, 1, dtEndTime,   dblOpenPrice );
         }
         
         dtDayBarTime = dtStartTime;
      }
   }
}

void OnDeinit( const int reason )
{
   ObjectDelete( strObjectName );
}

EDIT1: I updated this post to make the code more efficient. In the previous code, it would update the object on every tick, while this version only updates it when a new daily bar is formed.

EDIT2: I also included a check on the number of available bars, before actually trying to access that data for the Bar Shift in question. For an example of why this is important, please read the following thread: Array out of range in strategy tester

 
WHRoeder:
cashcube: Hi tried adding this code as you recommended.
GumRai: Once the object is created, use ObjectMove() when you want to give it new time/price co-ordinates
He didn't recommend that. He said to move it.
cashcube: Then how I can check? I use current bar 0.
Check what? Why do you need to check something? Just move it.

Hi 

I did it, now it works perfectly with tick by tick data.

      ObjectMove(CI,Obj_Name,0,ND,C);
      ObjectMove(CI,Obj_Name,1,NDD,C);
 
FMIC:

@cashcube: Maybe this can help you understand how to separate the Object Create from the Object Move:

EDIT1: I updated this post to make the code more efficient. In the previous code, it would update the object on every tick, while this version only updates it when a new daily bar is formed.

EDIT2: I also included a check on the number of available bars, before actually trying to access that data for the Bar Shift in question. For an example of why this is important, please read the following thread: Array out of range in strategy tester

Hi FMIC,

Thanks a lot for sharing a such a nice code. Your one is well constructed. I will add this in future.

Regards

Reason: