is it possible to send a faketick from OnInit() before OnInit() is completely done??

Back to topics list To post a new topic, please log in or register
avatar
23
GoS 2015.10.10 19:35
 

Hi,

 is it possible to send a faketick from OnInit() before OnInit() is completely done?? 

My problem is, i want my EA to delete all running indicators from the chart before starting. At the OnInit()-section the EA runns this function:

bool            WindowSubWindowsDelete  (const  long                    cl_chartID                      = 0,
                                                                         const  bool                    cb_debugMode            = false) export
        { //--- WindowSubWindowsDelete body start
                                                                                        int                             i                                       = 0;
                                                                                        int                             j                                       = 0;
                                                                                        int                             i_windowsTotal          = 0;
                                                                                        int                             i_indicatorsTotal       = 0;
                                                                                        string                  s_indicatorName         = "NULL";
        //-----------------------------------------------------------------------------------------
        i_windowsTotal = ChartWindowsTotal(cl_chartID, cb_debugMode);
        for(i = i_windowsTotal - 1; i >= 0; i--) // - 1: number to index
                {
                i_indicatorsTotal = ChartIndicatorsTotal(cl_chartID, i);
                for(j = i_indicatorsTotal - 1; j >= 0; j--) // - 1: number to index
                        {
                        s_indicatorName = ChartIndicatorName(cl_chartID, i, j);
                        ChartIndicatorDelete(cl_chartID, i, s_indicatorName);
                        if(cb_debugMode) Print(__FUNCTION__, "(): ErrorCode=", GetLastError(), ", i=", i, ", j=", j, ", s_indicatorName=", s_indicatorName);
                        }
                }
//      SendFakeTick(cl_chartID, cb_debugMode);
        return(true);
        } //--- WindowSubWindowsDelete body end

 This code is doing well, but (MQL4 Reference): Removes an indicator with a specified name from the specified chart window. The command is added to chart message queue and executed only after all previous commands have been processed.

So i have to send one faketick. Therefor i have the SendFakeTick()-function:

#import "user32.dll"
        int PostMessageA(int hWnd, int Msg, int wParam, int lParam);
        int RegisterWindowMessageA(string lpString);
#import
int                     SendFakeTick                    (const  long                    cl_chartID                      = 0,
                                                                         const  bool                    cb_debugMode            = false) export
        { //--- SendFakeTick body start
                                                                //       const  int                             ci_hWnd                         = ChartWindowHandle(cl_chartID, cb_debugMode);
                                                                         const  int                             ci_hWnd                         = WindowHandle(Symbol(), Period());
                                                                         const  int                             ci_Msg                          = RegisterWindowMessageA("MetaTrader4_Internal_Message");
                                                                         const  int                             ci_wParam                       = 2;
                                                                         const  int                             ci_lParam                       = 1;
                                                                                        int                             i_return                        = 0;
        //-----------------------------------------------------------------------------------------------------------------------------------
        i_return = PostMessageA(ci_hWnd, ci_Msg, ci_wParam, ci_lParam);
        if(cb_debugMode) Print(__FUNCTION__, "(): i_return=", DoubleToStr(i_return, 0));
        return(i_return);
        } //--- SendFakeTick body end

 I'm not sure if this really sends a faketick, because even if i set the timer and run SendFakeTick() at OnTimer(), all open subwindows and indicators stay on the chart.

... and also I wonder, because if i send one tick with mt4ticker, all subwindows and indicators are deleted.


avatar
12985
WHRoeder 2015.10.11 02:20 #
 
GoS: i want my EA to delete all running indicators from the chart before starting.
Why? The EA can't see them, it has no eyes.
avatar
23
GoS 2015.10.11 13:06 #
 
WHRoeder:
Why? The EA can't see them, it has no eyes.

the EA calculates the trades depending on multi-symbol and multi-timeframe signals from a set of 5 indicators. And i want to see all the calculated values at the mainwindow, so i need all the availabe space.

i know, I can delete all indicators and subwindows on my own before running the ea, but since the EA is doing very well and the major part of coding is done, I'm looking for some extra-work on it. 

avatar
12985
WHRoeder 2015.10.11 14:22 #
 
GoS: the EA calculates the trades depending on multi-symbol and multi-timeframe signals from a set of 5 indicators. And i want to see all the calculated values at the mainwindow, so i need all the availabe space.
Then don't attach the indicators to the chart. The EA doesn't need them attached. Just get the values.
avatar
23
GoS 2015.10.11 15:20 #
 
WHRoeder:
Then don't attach the indicators to the chart. The EA doesn't need them attached. Just get the values.

Hi WHRoeder

i really don't want to criticize you.. you are one of a few whose postings are very useful for me and i've used many code-snippets from you..

but in this case the question is:   is it possible to send a faketick from OnInit() before OnInit() is completely done??

and not: what should i do with open indicators ??

.. i've tried the following:

#property       strict
#include        <_V1_Header.mqh>
#define         SYSTEM_MODULE   "TradeManager"
//---------------------------------------------------------------------------------------------------------------------
int                     OnInit                                  (               void)
        { //--- OnInit body start
        EventSetMillisecondTimer(1000);
        return(INIT_SUCCEEDED);
        } //--- OnInit body end
//---------------------------------------------------------------------------------------------------------------------
void            OnDeinit                                (const  int                             ci_reason)
        { //--- OnDeinit body start
        return;
        } //--- OnDeinit body end
//---------------------------------------------------------------------------------------------------------------------
void            OnTick                                  (               void)
        { //--- OnTick body start
        Print("FakeTick");
        return;
        } //--- OnTick body end
//---------------------------------------------------------------------------------------------------------------------
void            OnTimer                                 (               void)
        { //--- OnTimer body start
        SendFakeTick(0, true);
        return;
        } //--- OnTimer body end
//---------------------------------------------------------------------------------------------------------------------
void            OnChartEvent                    (const  int                             ci_id,
                                                                         const  long&                   crl_parameter,
                                                                         const  double&                 crd_parameter,
                                                                         const  string&                 crs_parameter)
        { //--- OnChartEvent body start
        return;
        } //--- OnChartEvent body end
//---------------------------------------------------------------------------------------------------------------------

 Timer runns every one second and should "produce" one tick

 but the print("Faketick"); isn't done..

Therefore i think the problem is not the location of SendFakeTick() at OnInit(), but SendFakeTick() or PostMessageA(ci_hWnd, ci_Msg, 2, 1) doesn't produce really a faketick ??

avatar
23
GoS 2015.10.12 21:24 #
 

Hi,

big thanks to gooly @ https://forum.mql4.com/69682 "You have to import and use "ShellExecuteW" since b600+!"

PostMessageA() and RegisterWindowMessageA() replaced by PostMessageW() and RegisterWindowsMessageW()

and now SendFakeTick() produces one single faketick inside of OnInit()... WindowSubWindowsDelete() does what it should

 

Back to topics list  

To add comments, please log in or register