//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2012, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #define PIPE_TYPE_MESSAGE 4 #define PIPE_READMODE_MESSAGE 2 #define PIPE_WAIT 0 #define PIPE_ACCESS_DUPLEX 3 #define PIPE_UNLIMITED_INSTANCES 255 #define NMPWAIT_USE_DEFAULT_WAIT 0 #define INVALID_HANDLE_VALUE -1 #define ERROR_PIPE_CONNECTED 535 #import "kernel32.dll" int CreateNamedPipeA(uchar &PipeName[],int dwOpenMode,int dwPipeMode,int nMaxInstances,int nOutBufferSize,int nInBufferSize,int nDefaultTimeOut,int lpSecurityAttributes); int ConnectNamedPipe(int hPipe,int lpOverlapped); int ReadFile(int hPipe,uchar &inBuffer[],int NumberOfBytesToRead,int &bytesRead[],int lpOverlapped); int WriteFile(int hPipe,uchar &outBuffer[],int NumberOfBytesToWrite,int &bytesWritten[],int lpOverlapped); int FlushFileBuffers(int hPipe); int DisconnectNamedPipe(int hPipe); int CloseHandle(int hPipe); #import string lastMessage=""; extern string Pipe= "Pipe1"; int start() { uchar pipeName[]; ArrayResize(pipeName,StringLen("\\\\.\\pipe\\"+Pipe)); StringToCharArray("\\\\.\\pipe\\"+Pipe,pipeName); int PipeMode=PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT; int hPipe=CreateNamedPipeA(pipeName,PIPE_ACCESS_DUPLEX,PipeMode,PIPE_UNLIMITED_INSTANCES,1024,1024,NMPWAIT_USE_DEFAULT_WAIT,NULL); if(hPipe==INVALID_HANDLE_VALUE) { Alert("CreateNamedPipe failed"); return (-1); } while(!IsStopped()) { Comment("Pipe server ready ...\nSend \"STOP\" to stop server\n",lastMessage); bool fConnected=ConnectNamedPipe(hPipe,NULL)!=0; if(!fConnected) fConnected=GetLastError()==ERROR_PIPE_CONNECTED; if(fConnected) { uchar inBuffer[512]; int bytesRead[1]; bool fSuccess=ReadFile(hPipe,inBuffer,ArraySize(inBuffer),bytesRead,NULL)!=0; if(!fSuccess || (bytesRead[0]==0)) break; string inString=CharArrayToString(inBuffer,0,bytesRead[0]); lastMessage="Last message from client: "+inString; string outString="Received ["+inString+"]"; uchar outBuffer[]; ArrayResize(outBuffer,StringLen(outString)+1); StringToCharArray(outString,outBuffer); int bytesWritten[1]; fSuccess=WriteFile(hPipe,outBuffer,ArraySize(outBuffer),bytesWritten,NULL)!=0; if(!fSuccess || bytesWritten[0]!=StringLen(outString)+1) break; if(inString=="STOP") { Comment("Pipe server stopped."); FlushFileBuffers(hPipe); DisconnectNamedPipe(hPipe); CloseHandle(hPipe); return(0); } string Symbol=StringSubstr(0,6); int cmd=StrToInteger(StringSubstr(8,1)); //int cmd = StrToInteger(ordertype.c_str()); double Volume=StrToDouble(StringSubstr(10,3)); //double Volume = StrToDouble(Vol.c_str()); double Price=StrToDouble(StringSubstr(13,2)); // double Price = StrToDouble(pr.c_str()); int Slippage=StrToInteger(StringSubstr(16,1)); //int Slippage = StrToInteger(slp.c_str()); double StopLoss=StrToDouble(StringSubstr(18,7)); //double Stoploss = StrToDouble(stl.c_str()); double TakeProfit=StrToDouble(StringSubstr(25,7)); //double TakeProfit = StrToDouble(tp.c_str()); string Comment=StringSubstr(33,4); OrderSend(Symbol,cmd,Volume,Price,Slippage,StopLoss,TakeProfit); } FlushFileBuffers(hPipe); DisconnectNamedPipe(hPipe); } CloseHandle(hPipe); return(0); } //+------------------------------------------------------------------+
Omar AlKassar:
Good day Omar,
I've made the necessary changes as per both your adivces.
Progressed has been made with only 1 remaining error.
'ordertype' - function can be decalred only in the global scope.
The code is now as;
#define PIPE_TYPE_MESSAGE 4
#define PIPE_READMODE_MESSAGE 2
#define PIPE_WAIT 0
#define PIPE_ACCESS_DUPLEX 3
#define PIPE_UNLIMITED_INSTANCES 255
#define NMPWAIT_USE_DEFAULT_WAIT 0
#define INVALID_HANDLE_VALUE -1
#define ERROR_PIPE_CONNECTED 535
#import "kernel32.dll"
int CreateNamedPipeA(uchar& PipeName[],int dwOpenMode,int dwPipeMode,int nMaxInstances,int nOutBufferSize,int nInBufferSize,int nDefaultTimeOut,int lpSecurityAttributes);
int ConnectNamedPipe(int hPipe,int lpOverlapped);
int ReadFile(int hPipe, uchar& inBuffer[],int NumberOfBytesToRead, int& bytesRead[], int lpOverlapped);
int WriteFile(int hPipe, uchar& outBuffer[], int NumberOfBytesToWrite, int& bytesWritten[], int lpOverlapped);
int FlushFileBuffers(int hPipe);
int DisconnectNamedPipe(int hPipe);
int CloseHandle(int hPipe);
#import
string lastMessage="";
extern string Pipe = "Pipe1";
int start()
{
uchar pipeName[];
ArrayResize(pipeName, StringLen("\\\\.\\pipe\\"+Pipe));
StringToCharArray("\\\\.\\pipe\\"+Pipe, pipeName);
int PipeMode = PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT;
int hPipe = CreateNamedPipeA(pipeName,PIPE_ACCESS_DUPLEX,PipeMode,PIPE_UNLIMITED_INSTANCES,1024,1024,NMPWAIT_USE_DEFAULT_WAIT,NULL);
if (hPipe == INVALID_HANDLE_VALUE) {
Alert("CreateNamedPipe failed");
return (-1);
}
while(!IsStopped()) {
Comment("Pipe server ready ...\nSend \"STOP\" to stop server\n",lastMessage);
bool fConnected = ConnectNamedPipe(hPipe, NULL) != 0;
if(!fConnected)
fConnected = GetLastError() == ERROR_PIPE_CONNECTED;
if (fConnected) {
uchar inBuffer[512];
int bytesRead[1];
bool fSuccess = ReadFile(hPipe,inBuffer,ArraySize(inBuffer),bytesRead,NULL) !=0;
if (!fSuccess || (bytesRead[0] == 0)) break;
string inString = CharArrayToString(inBuffer, 0, bytesRead[0]);
lastMessage = "Last message from client: "+inString;
string outString = "Received ["+inString+"]";
uchar outBuffer[];
ArrayResize(outBuffer, StringLen(outString)+1);
StringToCharArray(outString, outBuffer);
int bytesWritten[1];
fSuccess = WriteFile(hPipe,outBuffer,ArraySize(outBuffer),bytesWritten,NULL) != 0;
if (! fSuccess || bytesWritten[0] != StringLen(outString)+1) break;
if(inString=="STOP") {
Comment("Pipe server stopped.");
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
return(0);
}
//string inString="EURUSD,OP_BUY,0.1,1.12309,3,1.12109,1.12409,mycomment";
string sep=",";
ushort u_sep;
string result[];
u_sep=StringGetCharacter(sep,0);
int k=StringSplit(inString,u_sep,result);
string Symbol = result[0];
int ordertype = StrToInteger(result[1]);
double vol = StrToDouble(result[2]);
double Price = StrToDouble(result[3]);
int Slippage = StrToInteger(result[4]);
double StopLoss = StrToDouble(result[5]);
double TakeProfit = StrToDouble(result[6]);
string Comment = result[7];
int ordertype(string value)
{
if(value=="OP_BUY")return(0);
if(value=="OP_SELL")return(1);
return(-1);
}
int TicketNumber =(OrderSend(Symbol,ordertype,vol,Price,Slippage,StopLoss,TakeProfit));
if (TicketNumber >0)
{
Print ("Order Placed# ",TicketNumber);
}
else
{
Print ("Order Send Failed, Error #", GetLastError());
}
}
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
}
CloseHandle(hPipe);
return(0);
}
JD05:
#define PIPE_TYPE_MESSAGE 4
#define PIPE_READMODE_MESSAGE 2
#define PIPE_WAIT 0
#define PIPE_ACCESS_DUPLEX 3
#define PIPE_UNLIMITED_INSTANCES 255
#define NMPWAIT_USE_DEFAULT_WAIT 0
#define INVALID_HANDLE_VALUE -1
#define ERROR_PIPE_CONNECTED 535
#import "kernel32.dll"
int CreateNamedPipeA(uchar& PipeName[],int dwOpenMode,int dwPipeMode,int nMaxInstances,int nOutBufferSize,int nInBufferSize,int nDefaultTimeOut,int lpSecurityAttributes);
int ConnectNamedPipe(int hPipe,int lpOverlapped);
int ReadFile(int hPipe, uchar& inBuffer[],int NumberOfBytesToRead, int& bytesRead[], int lpOverlapped);
int WriteFile(int hPipe, uchar& outBuffer[], int NumberOfBytesToWrite, int& bytesWritten[], int lpOverlapped);
int FlushFileBuffers(int hPipe);
int DisconnectNamedPipe(int hPipe);
int CloseHandle(int hPipe);
#import
string lastMessage="";
extern string Pipe = "Pipe1";
int start()
{
uchar pipeName[];
ArrayResize(pipeName, StringLen("\\\\.\\pipe\\"+Pipe));
StringToCharArray("\\\\.\\pipe\\"+Pipe, pipeName);
int PipeMode = PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT;
int hPipe = CreateNamedPipeA(pipeName,PIPE_ACCESS_DUPLEX,PipeMode,PIPE_UNLIMITED_INSTANCES,1024,1024,NMPWAIT_USE_DEFAULT_WAIT,NULL);
if (hPipe == INVALID_HANDLE_VALUE) {
Alert("CreateNamedPipe failed");
return (-1);
}
while(!IsStopped()) {
Comment("Pipe server ready ...\nSend \"STOP\" to stop server\n",lastMessage);
bool fConnected = ConnectNamedPipe(hPipe, NULL) != 0;
if(!fConnected)
fConnected = GetLastError() == ERROR_PIPE_CONNECTED;
if (fConnected) {
uchar inBuffer[512];
int bytesRead[1];
bool fSuccess = ReadFile(hPipe,inBuffer,ArraySize(inBuffer),bytesRead,NULL) !=0;
if (!fSuccess || (bytesRead[0] == 0)) break;
string inString = CharArrayToString(inBuffer, 0, bytesRead[0]);
lastMessage = "Last message from client: "+inString;
string outString = "Received ["+inString+"]";
uchar outBuffer[];
ArrayResize(outBuffer, StringLen(outString)+1);
StringToCharArray(outString, outBuffer);
int bytesWritten[1];
fSuccess = WriteFile(hPipe,outBuffer,ArraySize(outBuffer),bytesWritten,NULL) != 0;
if (! fSuccess || bytesWritten[0] != StringLen(outString)+1) break;
if(inString=="STOP") {
Comment("Pipe server stopped.");
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
return(0);
}
//string inString="EURUSD,OP_BUY,0.1,1.12309,3,1.12109,1.12409,mycomment";
string sep=",";
ushort u_sep;
string result[];
u_sep=StringGetCharacter(sep,0);
int k=StringSplit(inString,u_sep,result);
string Symbol = result[0];
int ordertype = StrToInteger(result[1]);
double vol = StrToDouble(result[2]);
double Price = StrToDouble(result[3]);
int Slippage = StrToInteger(result[4]);
double StopLoss = StrToDouble(result[5]);
double TakeProfit = StrToDouble(result[6]);
string Comment = result[7];
int ordertype(string value)
{
if(value=="OP_BUY")return(0);
if(value=="OP_SELL")return(1);
return(-1);
}
int TicketNumber =(OrderSend(Symbol,ordertype,vol,Price,Slippage,StopLoss,TakeProfit));
if (TicketNumber >0)
{
Print ("Order Placed# ",TicketNumber);
}
else
{
Print ("Order Send Failed, Error #", GetLastError());
}
}
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
}
CloseHandle(hPipe);
return(0);
}
Good day Omar,
I've made the necessary changes as per both your adivces.
Progressed has been made with only 1 remaining error.
'ordertype' - function can be decalred only in the global scope.
The code is now as;
#define PIPE_TYPE_MESSAGE 4
#define PIPE_READMODE_MESSAGE 2
#define PIPE_WAIT 0
#define PIPE_ACCESS_DUPLEX 3
#define PIPE_UNLIMITED_INSTANCES 255
#define NMPWAIT_USE_DEFAULT_WAIT 0
#define INVALID_HANDLE_VALUE -1
#define ERROR_PIPE_CONNECTED 535
#import "kernel32.dll"
int CreateNamedPipeA(uchar& PipeName[],int dwOpenMode,int dwPipeMode,int nMaxInstances,int nOutBufferSize,int nInBufferSize,int nDefaultTimeOut,int lpSecurityAttributes);
int ConnectNamedPipe(int hPipe,int lpOverlapped);
int ReadFile(int hPipe, uchar& inBuffer[],int NumberOfBytesToRead, int& bytesRead[], int lpOverlapped);
int WriteFile(int hPipe, uchar& outBuffer[], int NumberOfBytesToWrite, int& bytesWritten[], int lpOverlapped);
int FlushFileBuffers(int hPipe);
int DisconnectNamedPipe(int hPipe);
int CloseHandle(int hPipe);
#import
string lastMessage="";
extern string Pipe = "Pipe1";
int start()
{
uchar pipeName[];
ArrayResize(pipeName, StringLen("\\\\.\\pipe\\"+Pipe));
StringToCharArray("\\\\.\\pipe\\"+Pipe, pipeName);
int PipeMode = PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT;
int hPipe = CreateNamedPipeA(pipeName,PIPE_ACCESS_DUPLEX,PipeMode,PIPE_UNLIMITED_INSTANCES,1024,1024,NMPWAIT_USE_DEFAULT_WAIT,NULL);
if (hPipe == INVALID_HANDLE_VALUE) {
Alert("CreateNamedPipe failed");
return (-1);
}
while(!IsStopped()) {
Comment("Pipe server ready ...\nSend \"STOP\" to stop server\n",lastMessage);
bool fConnected = ConnectNamedPipe(hPipe, NULL) != 0;
if(!fConnected)
fConnected = GetLastError() == ERROR_PIPE_CONNECTED;
if (fConnected) {
uchar inBuffer[512];
int bytesRead[1];
bool fSuccess = ReadFile(hPipe,inBuffer,ArraySize(inBuffer),bytesRead,NULL) !=0;
if (!fSuccess || (bytesRead[0] == 0)) break;
string inString = CharArrayToString(inBuffer, 0, bytesRead[0]);
lastMessage = "Last message from client: "+inString;
string outString = "Received ["+inString+"]";
uchar outBuffer[];
ArrayResize(outBuffer, StringLen(outString)+1);
StringToCharArray(outString, outBuffer);
int bytesWritten[1];
fSuccess = WriteFile(hPipe,outBuffer,ArraySize(outBuffer),bytesWritten,NULL) != 0;
if (! fSuccess || bytesWritten[0] != StringLen(outString)+1) break;
if(inString=="STOP") {
Comment("Pipe server stopped.");
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
return(0);
}
//string inString="EURUSD,OP_BUY,0.1,1.12309,3,1.12109,1.12409,mycomment";
string sep=",";
ushort u_sep;
string result[];
u_sep=StringGetCharacter(sep,0);
int k=StringSplit(inString,u_sep,result);
string Symbol = result[0];
int ordertype = StrToInteger(result[1]);
double vol = StrToDouble(result[2]);
double Price = StrToDouble(result[3]);
int Slippage = StrToInteger(result[4]);
double StopLoss = StrToDouble(result[5]);
double TakeProfit = StrToDouble(result[6]);
string Comment = result[7];
int ordertype(string value)
{
if(value=="OP_BUY")return(0);
if(value=="OP_SELL")return(1);
return(-1);
}
int TicketNumber =(OrderSend(Symbol,ordertype,vol,Price,Slippage,StopLoss,TakeProfit));
if (TicketNumber >0)
{
Print ("Order Placed# ",TicketNumber);
}
else
{
Print ("Order Send Failed, Error #", GetLastError());
}
}
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
}
CloseHandle(hPipe);
return(0);
}
Nvm that, solved it.
However when i send a command over from the Client side, it doesnt pick up the order but merely displays the string sent across.
Your help would be deeply appreciated.
Regards,
JD05

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Good Day,
Just enquiring upon writing the code, the following errors pops out, "',' - unexpected token, cmd-some operator expected and OrderSend - undeclared identifier.
Code is as;