Displaying more information

The OnChartEvent callback returns a number of parameters. I wrote another small utility class to display the details of these parameters.

struct ChartEvent
{
    static string ToString(int id)
    {
        switch (id)
        {
            case CHARTEVENT_KEYDOWN:       return "keystroke";
            case CHARTEVENT_MOUSE_MOVE:    return "mouse event (move or click)";
            case CHARTEVENT_OBJECT_CREATE: return "graphical object creation";
            case CHARTEVENT_OBJECT_CHANGE: return "object property change via the properties dialog";
            case CHARTEVENT_OBJECT_DELETE: return "graphical object deletion";
            case CHARTEVENT_CLICK:         return "mouse click";
            case CHARTEVENT_OBJECT_CLICK:  return "graphical object mouse click";
            case CHARTEVENT_OBJECT_DRAG:   return "graphical object mouse drag";
            case CHARTEVENT_OBJECT_ENDEDIT:return "text box entry complete";
            case CHARTEVENT_CHART_CHANGE:  return "chart change";
            case CHARTEVENT_CUSTOM_LAST:   return "custom id max";
            default:                       return "custom id " + IntegerToString(id);
        }
        return "unknown";
    }
    
    static string DisplayInfo(int id, long l, double d, const string& s)
    {
        string ret = ToString(id) + " ";
        switch (id)
        {
            case CHARTEVENT_KEYDOWN:       ret += KeyEvent(l);                   break;
            case CHARTEVENT_MOUSE_MOVE:    ret += MouseMove(l,(long)d,s);        break;
            case CHARTEVENT_OBJECT_CREATE: ret += ObjectCreated(s);              break;
            case CHARTEVENT_OBJECT_CHANGE: ret += ObjectChanged(s);              break;
            case CHARTEVENT_OBJECT_DELETE: ret += ObjectDeleted(s);              break;
            case CHARTEVENT_CLICK:         ret += ChartClick(l,(long)d);         break;
            case CHARTEVENT_OBJECT_CLICK:  ret += ChartObjectClick(l,(long)d,s); break;
            case CHARTEVENT_OBJECT_DRAG:   ret += ObjectDragged(s);              break;
            case CHARTEVENT_OBJECT_ENDEDIT:ret += ObjectEndEdit(s);              break;
            case CHARTEVENT_CHART_CHANGE:                                        break;
            case CHARTEVENT_CUSTOM_LAST:                                         break;
            default:                                                             break;
        }
        return ret;
    }
    
    static string KeyEvent(long l)
    {
        return "key_code=" + IntegerToString(l);
    }
    
    static string MouseMove(long x, long y, const string& s)
    {
        return "x=" + IntegerToString(x) + ", y=" + IntegerToString(y) + ", status=" + s;
    }
    
    static string ObjectCreated(const string& s)
    {
        return "object=" + s;
    }
    
    static string ObjectChanged(const string& s)
    {
        return "object=" + s;
    }
    
    static string ObjectDeleted(const string& s)
    {
        return "object=" + s;
    }
    
    static string ChartClick(long x, long y)
    {
        return "x=" + IntegerToString(x) + ", y=" + IntegerToString(y);
    }
    
    static string ChartObjectClick(long x, long y, const string& s)
    {
        return "x=" + IntegerToString(x) + ", y=" + IntegerToString(y) + ", object=" + s;
    }
    
    static string ObjectDragged(const string& s)
    {
        return "object=" + s;
    }
    
    static string ObjectEndEdit(const string& s)
    {
        return "object=" + s;
    }
};        

I then display the details information in my callback:

void OnChartEvent(const int     id, // Event ID
                  const long&   l,  // Parameter of type long event
                  const double& d,  // Parameter of type double event
                  const string& s)  // Parameter of type string event
{
    Print(__FUNCTION__ + " " + ChartEvent::DisplayInfo(id, l, d, s));
}

Displaying some information

I now add some information about the status of the EA, and the parameters passed to the callbacks.

The call to OnDeinit passes an integer value called ‘reason’. I wrote a simple class with a static function which will translate the integer into a string.

struct UninitReason
{
    static string ToString(int id)
    {
        switch (id)
        {
            case REASON_ACCOUNT:     return "account was changed";
            case REASON_CHARTCHANGE: return "symbol or timeframe was changed";
            case REASON_CHARTCLOSE:  return "chart was closed";
            case REASON_PARAMETERS:  return "input-parameter was changed";
            case REASON_RECOMPILE:   return "program was recompiled";
            case REASON_REMOVE:      return "program was removed from chart";
            case REASON_TEMPLATE:    return "new template was applied to chart";
        }
        return "unknown " + IntegerToString(id);
    }
};

I then called the static function ToString from my OnDeinit callback function:

void OnDeinit(const int reason)
{
    Print(__FUNCTION__ + "; reason=" + UninitReason::ToString(reason));
}