메타트레이더 5에서 원격소켓서버와 통신 가능하게 하기 위한 설정.
Options 창에서 Allow WebRequest for listed URL 체크하고 통신대상 소켓서버의 아이피 주소 기록해둔다.

MQ5 에서 소켓통신 코드예.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+------------------------------------------------------------------+ | |
//| Socket.mq5 | | |
//| igotit | | |
//| http://igotit.tistory.com | | |
//+------------------------------------------------------------------+ | |
#property copyright "igotit" | |
#property link "http://igotit.tistory.com" | |
#property version "1.00" | |
int My_Socket_Handle = INVALID_HANDLE; | |
int OnInit() | |
{ | |
My_Socket_Handle = Socket_Connect(); | |
return(INIT_SUCCEEDED); | |
} | |
void OnDeinit(const int reason) | |
{ | |
Socket_Close(My_Socket_Handle); | |
} | |
void OnTick() | |
{ | |
string str_price_ask = DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_ASK)); | |
Socket_Send(My_Socket_Handle,str_price_ask); | |
} | |
int Socket_Connect() | |
{ | |
int h_socket = SocketCreate(SOCKET_DEFAULT); | |
if(h_socket != INVALID_HANDLE) | |
{ | |
if(SocketConnect(h_socket,"192.168.11.65",9090,2000)) | |
{ | |
Print("Connected to Socket Server"); | |
}//if(SocketConnect | |
else | |
{ | |
Print("Fail connected to Socket Server. error code : ", GetLastError()); | |
} | |
}//if(socket != INVALID_HANDLE) | |
else | |
{ | |
Print("Fail SocketCreate error code : ", GetLastError()); | |
} | |
return h_socket; | |
} | |
void Socket_Close(int socket_handle) | |
{ | |
if(socket_handle != INVALID_HANDLE) | |
{ | |
SocketClose(socket_handle); | |
My_Socket_Handle = INVALID_HANDLE; | |
Print("Socket Closed"); | |
} | |
} | |
int Socket_Send(int socket_handle,string str_data) | |
{ | |
if(socket_handle == INVALID_HANDLE) return 0; | |
uchar bytes[]; | |
int byte_size = StringToCharArray(str_data,bytes)-1; | |
return SocketSend(socket_handle,bytes,byte_size); | |
} |
실행예.
- MQL5 에서 파이썬으로 구현된 소켓서버로 틱데이터 중 Ask 가격을 실시간 전송하는 예.
연관
- 파이썬 측 소켓통신 소스 코드.
Python. 소켓통신
Python 소켓서버 구현 코드예. 소켓통신 실행 시험. - 소켓클라이언트로 하이퍼터미널 이용. 상기 파이썬 소켓서버 와 통신하는 소켓클라이언트로 하이퍼 터미널을 이용해도 된다. 아래 동영상에서는 다른 PC에 하..
igotit.tistory.com
첫등록 : 2019년 5월 8일
최종수정 :
본 글 단축주소 : https://igotit.tistory.com/2116

'트레이딩 > 메타트레이더 코딩' 카테고리의 다른 글
MQL5. EventChartCustom (0) | 2019.05.11 |
---|---|
MQL5. Custom Indicator (3) | 2019.05.10 |
MQL5. 수직선 그리기 (2) | 2019.04.29 |
MQL5. 캔들 변경 지점 검출 (0) | 2019.04.29 |
MQL5. 사각형 그리기 (2) | 2019.04.29 |
댓글