Skip to content

about order's comment is null #167

Closed

Description

@zhao0876

This is the problem I encountered today.
When I get an order update from TradeMonitor
I try to pass the changed orders through the event for processing one by one.
One of the processing steps is to check the order ‘s comment.
I found it is null which will trigger .net to generate a null Exception
I think it should be a empty string.
I modified the mq4 file. But it’s still null
I don't clear the message build process, I think you can fix this problem faster.

This problem also made me discover another place for improvement.
The code in the TimerTradeMonitor line 82 looks like this:
            _timer.Elapsed -= _timer_Elapsed; //unregister from events to prevent rise condition during work with orders
            Check();
            _timer.Elapsed += _timer_Elapsed; //register again

There is event passing in Check() on TradeMonitor line 153
AvailabilityOrdersChanged?.Invoke(this, new AvailabilityOrdersEventArgs(openedOrders, closedOrders));

This null error is included in my processing event
The result is that Check() has an error.
Then _timer.Elapsed += _timer_Elapsed is not executed
So the TradeMonitor was interrupted.
At the same time, the upper order processing event was handled by my try catch.
The result is nothing happens, as if the TimerTradeMonitor did not start running.

I spent a lot of time to find the root cause of this problem.

I think adding and subtracting _timer.Elapsed is not a particularly good method.
You can consider another way to control the switch of the order check event.
Also consider whether to do exception handling when sending events

Activity

  1. zhao0876 commented on Jun 27, 2019

    @zhao0876
    Author

    I just thought of it, that is the problem I found before.
    Set comment to "" instead of null when I send a order
    After the order is executed, the real comment is not "", but the request type
    I think there are some problems in the serialization of json.
    At that time, I didn't think it was a big problem.
    maybe the current problem is related to this.

  2. vdemydiuk commented on Jul 12, 2019

    @vdemydiuk
    Owner

    Hi.
    Thank you for report of this problem.
    I will check it soon and try to fix.

  3. payam-alexander commented on Apr 17, 2020

    @payam-alexander

    Hi,
    This bug is still there.
    When I try to get an order, a wrong magic number is being returned, although I had opened the order with null and "" comment.
    There seems to be a bug in json serialization/deserialization, which causes this issue

  4. eabase commented on Dec 1, 2020

    @eabase
    Contributor

    I think we should put another more obvious default. Perhaps MTAPI?

  5. tudstudent commented on Mar 21, 2026

    @tudstudent

    Fixed in PR #297 — the MQL4 MtOrder class conditionally skipped the Comment field when it was an empty string, causing the .NET client to deserialize it as null. Now always serialized as "Comment": "".

  6. added a commit that references this issue on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions