Download MetaTrader 5
To add comments, please log in or register
Do you want to write a trading robot? Find solution in MQL5 Reference!
Mimi
501
Mimi 2016.04.18 08:17 

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

whroeder1
14457
whroeder1 2016.04.18 11:59  
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.
Mimi
501
Mimi 2016.04.18 12:55  
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?
Keith Watford
Moderator
9597
Keith Watford 2016.04.18 13:13  
Once the object is created, use ObjectMove() when you want to give it new time/price co-ordinates
Mimi
501
Mimi 2016.04.19 14:02  
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.

whroeder1
14457
whroeder1 2016.04.19 18:18  
ND will never be not equal to itself.
if(ND!=ND)
Mimi
501
Mimi 2016.04.20 05:29  
WHRoeder:
ND will never be not equal to itself.

Then how I can check? I use current bar 0.
whroeder1
14457
whroeder1 2016.04.20 12:52  
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.
Fernando Carreiro
2353
Fernando Carreiro 2016.04.20 13:37  

@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

Mimi
501
Mimi 2016.04.21 05:02  
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);
Mimi
501
Mimi 2016.04.21 05:03  
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

/ /12
To add comments, please log in or register