vdemydiuk / mtapi

MetaTrader API (terminal bridge)
http://mtapi4.net/
MIT License
514 stars 277 forks source link

can not build connection for mt5 #184

Closed guzuomuse closed 4 years ago

guzuomuse commented 4 years ago

@vdemydiuk thanks for your great work. this libary seems very intresting.

is there doc for how to build connection? i have tried the code below,but always shows disconnected

        var client =new MtApi5Client();
        client.BeginConnect(8228);
        Console.WriteLine(client.ConnectionState);

explain it, i have attached the ea onto the terminal chart

vdemydiuk commented 4 years ago

Hi. Function BeginConnect is asynchronous. If you try to check connection immediately after begin connect you will have state disconnected. You need to subscribe on event ConnectionStateChanged to get changes of connection state.

guzuomuse commented 4 years ago

i'm now learning how to use mtapi5. i will try as you suggested if we have a document for MtApi5Client Class would be much better :) thanks for your reply.

guzuomuse commented 4 years ago

@vdemydiuk ,after some digging on this scenario, i dont know how to handel it. let say i want to do get data from a indicator: int handel_1=client.iMA("USDCAD", ENUM_TIMEFRAMES.PERIOD_H4, 21, 0, ENUM_MA_METHOD.MODE_SMA, ENUM_APPLIED_PRICE.PRICE_CLOSE); but how we are sure the connection established already? could be that we must check the connection state is Mt5ConnectionState.Connected first? C# is not my first lanauge. so, could you be kind to teach me how to assure the connection is established before calling some functions like IMA etc. thank you very much