Download MetaTrader 5
To add comments, please log in or register
Have you developed an application? Publish it in Code Base!
ruth26
21
ruth26 2016.08.23 14:10 

Hello, fellow coders!

I have an indicator that shows me the price difference between the newest candles open and 21st candle close. This is working fine except for one crucial thing - it doent update with the chart. It keeps showing the value for when it was first added to the chart.

I have tried to add RefreshRates() and similiar functions but with no success so far. This is the code:


#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  double a=Open[0]-Close[20];
    string name;
    string par =DoubleToStr((a/Point),0);
   
       if(Open[0]>Close[20])
      {
       name = "  up = ";
      }
    if(Open[0]<Close[20])
      {
       name = "down = ";
      }
     if(Open[0]==Close[20])
      {
       name = "flat = ";
      }
 
   
 
 
   //
   ObjectCreate("signal",OBJ_LABEL,0,0,0,0,0);
   ObjectCreate("signal2",OBJ_LABEL,0,0,0,0,0);
 
   //
   ObjectSet("signal",OBJPROP_XDISTANCE,650);
   ObjectSet("signal2",OBJPROP_XDISTANCE,706);
 
   //
   ObjectSet("signal",OBJPROP_YDISTANCE,12);
   ObjectSet("signal2",OBJPROP_YDISTANCE,12);
 
   //
   ObjectSetText("signal",name,12,"Tahoma",Red);
   ObjectSetText("signal2",par,12,"Tahoma",Red);
  
 
   return(0); 
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
  
//----
   return(0);
  }

//+------------------------------------------------------------------+

What should be implemented into the code and where - in order for it to automatically update to each new candle open?

Every bit of help is highly appreciated!

Once again, I want to thank all who take their time - thinking about this problem of mine - in advance.

All have a nice day,

ruth26

Keith Watford
Moderator
7979
Keith Watford 2016.08.23 14:18  

Please use the SRC button when posting code, I have done it for you this time

   ObjectCreate("signal",OBJ_LABEL,0,0,0,0,0);
   ObjectCreate("signal2",OBJ_LABEL,0,0,0,0,0);
 
   //
   ObjectSet("signal",OBJPROP_XDISTANCE,650);
   ObjectSet("signal2",OBJPROP_XDISTANCE,706);
 
   //
   ObjectSet("signal",OBJPROP_YDISTANCE,12);
   ObjectSet("signal2",OBJPROP_YDISTANCE,12);

This should be OK in Init but the rest of the code needs to be in start

ruth26
21
ruth26 2016.08.23 14:28  
GumRai:

Please use the SRC button when posting code, I have done it for you this time

This should be OK in Init but the rest of the code needs to be in start

Thanks for the information. Ill admit that I am pretty new around here. My bad with the code.

Back to the coding part though. Are you saying that if I move the rest of the code to the start() part of it - it starts to refresh on chart with each new candle formed?

Edit: I have moved the other part of the code to the start() section and indeed it refreshes itself on the chart now with each new bars open. Well done, sir! Thank you for your advice.

/
To add comments, please log in or register