Получаем сигналы со стороннего сервера |
//+------------------------------------------------------------------+
//| access.mq4 |
//| idarvel |
//| http://idarvel.opentraders.ru/bio/ |
//+------------------------------------------------------------------+
#property copyright "idarvel"
#property link "http://idarvel.opentraders.ru/bio/"
#property version "1.00"
#property strict
input int slippage = 20;
input int sl = 400;
input int tp = 300;
input double lot = 0.1;
input string License_Login = "idarvel";
input string License_Passwd = "password";
int magic = 12434;
string urldata = ""; // URL вида http://google.com/checklicense/
bool license = false;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
CheckLicense();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(!license) return;
// допустим мы опрашиваем сервер и ждем сигнала
// и если нет открытых сделок - откроем
if(CountTrades() < 1)
{
// опрашиваем что нам делать на текущем тике на данном символе, ожидаем ответ buy/sell
string response = WebReq("login="+License_Login+"&password="+License_Passwd+"&mode=signal");
if(response == "buy")
{
PutOrder(OP_BUY, Ask);
}
if(response == "sell")
{
PutOrder(OP_SELL, Bid);
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void CheckLicense()
{
string response = WebReq("login="+License_Login+"&password="+License_Passwd+"&mode=checklicense");
if(response == "error")
{
Print("You dont have license.");
Alert("You dont have license.");
}
else
{
license = true;
Print("License successfully accepted.");
Alert(response);
}
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string WebReq(string postdata)
{
char post[];
char result[];
string headers;
int res;
StringToCharArray(postdata,post);
ResetLastError();
res = WebRequest("POST",urldata,NULL,NULL,50,post,ArraySize(post),result,headers);
if(res == -1)
{
Print("Error code = ",GetLastError());
return "";
}
else
return CharArrayToString(result, 0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type, double price)
{
int r=0;
color clr=Green;
double s=0,t=0;
if(type==-1) return;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(sl>0) s=NormalizeDouble(price+sl*Point,Digits);
if(tp>0) t=NormalizeDouble(price-tp*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(sl>0) s=NormalizeDouble(price-sl*Point,Digits);
if(tp>0) t=NormalizeDouble(price+tp*Point,Digits);
}
r=OrderSend(NULL,type,lot,NormalizeDouble(price,Digits),slippage,s,t,"",magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Следующая запись в моем блоге ![]() Мультивалютный советник, тестируем!! +100500 пунктов(нет), мега профит(нет) |
|
07 сентября 2016
|
12 сентября 2016
|
Комментарии (0)
Зарегистрируйтесь или авторизуйтесь, чтобы оставить комментарий