Download MetaTrader 5
To add comments, please log in or register
Traders have already contributed more than 300 articles. Write your own one!
sethblackstone
19
sethblackstone 2016.01.25 21:57 

I know this topic has been bashed around a lot on various forums,  but I have tried everything that I can find and nothing works,  including the ever popular

  if(hwnd == 0) {

    hwnd = WindowHandle(_Symbol, RTimeFrame);

    if(hwnd == 0) {

      return;

    } else {

      Print ("Offline Chart Window for ",_Symbol," detected.");

    }

  }

  if(MT4InternalMsg == 0) {

    MT4InternalMsg = RegisterWindowMessageA("MetaTrader4_Internal_Message");

    if(MT4InternalMsg == 0) 

      return;

  }        

  if(PostMessageA(hwnd, WM_COMMAND, MT4_WMCMD_UPDATE_DATA, 0) == 0) {

    hwnd = 0;

  } else {

    PostMessageA(hwnd, MT4InternalMsg, 2, 1);

  } 

 

I have reworked this code in everyway imaginable and I cannot generate a NewTick Event on an Offline Chart window,  now as you might imagine I can get by with timer events on some less important management tasks,  but there are some things that simply must work on every tick.  It seems very odd to me that I cant raise an event in a given window, what is up with that??

 Can You please tell me how to send a NewTick Event to a Offline chart window??

 I am well aware that this code worked in previous builds of the MT4 Terminal,  but it will not work in the aforementioned build, no way, no how.

 Thanks in advance. 

honest_knave
969
honest_knave 2016.01.25 22:00  

Use PostMessageW not PostMessageA and you should get on fine

(strings are now unicode)

sethblackstone
19
sethblackstone 2016.01.25 22:23  
honest_knave:

Use PostMessageW not PostMessageA and you should get on fine

 

 

Still No Joy,  I am talking about the NewTick Event with the new Compiler,  build 600+  here is the routine that I am using at present.

 void UpdateChartWindow() {

  static int MT4InternalMsg = 0;

  static CChart MyOffLineChart;

  long chart_id = ChartNext(0);

 

  if(MT4InternalMsg == 0) {

    MT4InternalMsg = RegisterWindowMessageA("MetaTrader4_Internal_Message");

    if(MT4InternalMsg == 0) 

      return;

  }

  while(chart_id != -1 ) {

    if(StringCompare(ChartSymbol(chart_id),_Symbol) == 0 && ChartGetInteger(chart_id,CHART_IS_OFFLINE)) {

      MyOffLineChart.Attach(chart_id);

      PostMessageW(MyOffLineChart.WindowHandle(), WM_COMMAND, MT4_WMCMD_UPDATE_DATA, 0);

      PostMessageW(MyOffLineChart.WindowHandle(), MT4InternalMsg, 2, 1);

      break;

    } else {

      chart_id = ChartNext(chart_id);  

    }

  }

  if(chart_id == -1) {

    MyOffLineChart.Attach(MyOffLineChart.Open(_Symbol,PERIOD_M2));

    MyOffLineChart.ApplyTemplate(TemplateFile);

  }

  return;

}

Now this statement is working

      PostMessageW(MyOffLineChart.WindowHandle(), WM_COMMAND, MT4_WMCMD_UPDATE_DATA, 0);

My chart is drawing as I pump data to the .hst file,  but the OnTick() handler is not firing.  Any ideas?? 

honest_knave
969
honest_knave 2016.01.25 23:48  
All strings are unicode - RegisterWindowMessageW too
sethblackstone
19
sethblackstone 2016.01.26 17:50  

Nevermind, I just discovered the EventChartCustom func,  just call OnTick from the OnChartEvent handler in the receiving chart and viola.

here is the code

class MyRenkoChart : public CChart {

public:

  void SendMyTick(void) {

    EventChartCustom(m_chart_id,69,0.0,0.0,"");

  }

};

void UpdateChartWindow() {

  static MyRenkoChart MyOffLineChart;


  if(MyOffLineChart.ChartId() != INVALID_HANDLE) {

    PostMessageW(MyOffLineChart.WindowHandle(), WM_COMMAND, MT4_WMCMD_UPDATE_DATA, 0);

    MyOffLineChart.SendMyTick();

  } else {

    MyOffLineChart.FirstChart();

    

    while(MyOffLineChart.ChartId() != INVALID_HANDLE ) {

      if(StringCompare(MyOffLineChart.Symbol(),_Symbol) == 0 && MyOffLineChart.GetInteger(CHART_IS_OFFLINE)) {

        PostMessageW(MyOffLineChart.WindowHandle(), WM_COMMAND, MT4_WMCMD_UPDATE_DATA, 0);

        MyOffLineChart.SendMyTick();

        break;

      } else {

        MyOffLineChart.NextChart();  

      }

    }

    if(MyOffLineChart.ChartId() == INVALID_HANDLE) {

      MyOffLineChart.Attach(MyOffLineChart.Open(_Symbol,2));

      MyOffLineChart.ApplyTemplate(TemplateFile);

    }

  }  

  return;

}

/
To add comments, please log in or register