how to refresh window

 

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.

 
Have you ever try ...
WindowRedraw()
?
 
deysmacro:
Have you ever try ... ?

Yes, didn't work.
 
Try ChartRedraw
 
I've been trying WindowRedraw(), ChartRedraw(), and RefreshRate(), didn't work.
 

Then use ...

 ChartRedraw()

after object have been created. Usually works that way.

 
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.

 
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.
 
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.
 
Can anyone help?
 

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