Download MetaTrader 5

how to refresh window

To add comments, please log in or register
metbright
101
metbright  

Hi,

Anyone know any code to refresh window like the manual refresh (right click > Refresh) ?

I want to refresh window when i create an object via the OnChartEvent() function.

Thanks.

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
Have you ever try ...
WindowRedraw()
?
metbright
101
metbright  
deysmacro:
Have you ever try ... ?

Yes, didn't work.
Keith Watford
Moderator
10372
Keith Watford  
Try ChartRedraw
metbright
101
metbright  
I've been trying WindowRedraw(), ChartRedraw(), and RefreshRate(), didn't work.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  

Then use ...

 ChartRedraw()

after object have been created. Usually works that way.

metbright
101
metbright  
deysmacro:

Then use ...

after object have been created. Usually works that way.




didn't work.


I want to execute all code of indicator (in Oncalculate()) when an object has been created instead of wait for a new tick.

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
Show us the code and somebody will help you if it not too much to ask for help. Use SRC button to paste your code.
metbright
101
metbright  
deysmacro:
Show us the code and somebody will help you if it not too much to ask for help. Use SRC button to paste your code.

Here is some code
#property  indicator_separate_window

double sl1;

int OnInit() {
   ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true);
   IndicatorShortName("1");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

      string dis_sl1 = DoubleToStr(sl1, Digits);
      
      int chart_ID = 0;
      string object_name = "mm_edit01";
      int sub_window = WindowFind("1");
      
      ObjectCreate(chart_ID,object_name,OBJ_EDIT,sub_window,0,0);
      
      ObjectSetInteger(chart_ID,object_name,OBJPROP_XDISTANCE,412);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_YDISTANCE,120);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_XSIZE,60);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_YSIZE,19);
      ObjectSetString(chart_ID,object_name,OBJPROP_TEXT,dis_sl1);
      ObjectSetString(chart_ID,object_name,OBJPROP_FONT,"Arial");
      ObjectSetInteger(chart_ID,object_name,OBJPROP_FONTSIZE,10);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_ALIGN,ALIGN_CENTER);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_READONLY,false);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_COLOR,clrWhite);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_BGCOLOR,clrBlack);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_BORDER_COLOR,clrSilver);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_BACK,false);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_SELECTED,false);
      ObjectSetInteger(chart_ID,object_name,OBJPROP_HIDDEN,false);

      
   return(rates_total);
  }
      
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // Event ID
                  const long& lparam,   // Parameter of type long event
                  const double& dparam, // Parameter of type double event
                  const string& sparam  // Parameter of type string events
                  )
  {
//---

   
      if(id==CHARTEVENT_OBJECT_CREATE)
      {
         if(StringFind(sparam, "Horizontal Line", 0) >= 0) 
         {
            sl1 = ObjectGetDouble(ChartID(), sparam, OBJPROP_PRICE, 0);
            ObjectSetString(ChartID(), sparam, OBJPROP_TEXT, "sl1"); 
         }
         ChartRedraw();
      }
  
  }
when I create horizontal line the price will store to sl1 immediately but it will need to wait for a new tick to update the text in edit field, or I need to refresh by [right click > refresh]. I want to update the text in the edit field immediately after horizontal line has been created.
metbright
101
metbright  
Can anyone help?
Keith Watford
Moderator
10372
Keith Watford  

Maybe you should try ChartRedraw in OnCalculate

ObjectCreate(chart_ID,object_name,OBJ_EDIT,sub_window,0,0);
//You jump to the chart event function here. That is BEFORE you have set the text property
12
To add comments, please log in or register