test_group/ba/RusBafet3.mq5

165 lines
11 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:31:23 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| web.mq5 |
//| Copyright 2018, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright " CAA:89 0D5B"
#property link "https://www.alexeybogachev.ru"
#property version "1.01"
#include <Trade\Trade.mqh>
CTrade trade;
enum sell_or_buy1
{
sell,// ?@>40BL
buy, // :C?8BL
all // >10
};
input int timer=15; // =B5@20; 2@5<5=8
input double lot=0.01; // ;>B=>ABL ?> C<>;G0=8N
/*input double lot_gold=0.01; // 5B0;K (;>B=>ABL)
input double lot_oil=0.01; // (;>B=>ABL)
input string oil1="#LCOM0"; // BRENT
input string oil2="#CLK0"; // WTI
input string ngold2="XAUUSD"; // name Gold
*/
input sell_or_buy1 sell_or_buy=all; // ">@3>2;O ?> B@5=4C
input string ig1=""; // 3=>@8@>20BL 8=AB@C<5=B 1
input string ig2=""; // 3=>@8@>20BL 8=AB@C<5=B 2
input string ig3=""; // 3=>@8@>20BL 8=AB@C<5=B 3
input string domen="http://rusbafet.ru/fx/"; //><5=
input int userId=0;//! ?>;L7>20B5;O
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
EventSetTimer(timer);
//Alert( openlink("https://wlink.ru/fx/fx.txt"));
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
string str=openlink(domen+"fx"+userId+".txt");
if(StringLen(str)>0){
string sep=" "; // @0745;8B5;L 2 2845 A8<2>;0
ushort u_sep; // :>4 A8<2>;0 @0745;8B5;O
string result[]; // <0AA82 4;O ?>;CG5=8O AB@>:
//--- ?>;CG8< :>4 @0745;8B5;O
u_sep=StringGetCharacter(sep,0);
//--- @07>1L5< AB@>:C =0 ?>4AB@>:8
int k=StringSplit(str,u_sep,result);
string res=result[1];
string sym=result[0];
ulong mid;
double olot;
if(ArraySize(result)>2)olot=result[2];
else
olot=lot;
//if(sym=="GOLD" || sym=="SILVER" || sym==ngold2)olot=lot_gold;
//if(sym==oil1 || sym==oil2)olot=lot_oil;
if(res=="sell" || res=="buy"){
ulong ticket;
//string type;
uint total=PositionsTotal();
int i;
for(uint i=0; i<total; i++)
{
//--- ?>;CG8< B8:5B >@45@0 ?> 53> ?>78F88 2 A?8A:5
if((ticket=PositionGetTicket(i))>0){
if(PositionGetString(POSITION_SYMBOL)==sym)mid=PositionGetInteger(POSITION_IDENTIFIER);
}
}
}
string s_o_b=EnumToString(sell_or_buy);
if(sym!=ig1 && sym!=ig2 && sym!=ig3){
if(res=="sell"){
trade.PositionClose(mid);
if(s_o_b=="sell" || s_o_b=="all")
{
trade.Sell(olot,result[0]);
openlink(domen+"in.php?del="+userId);
string push="sell"+result[0];
SendNotification(push);
}
}
//Alert(PositionsTotal());
if(res=="buy"){
trade.PositionClose(mid);
if(s_o_b=="buy" || s_o_b=="all"){
trade.Buy(olot,result[0]);
openlink(domen+"in.php?del="+userId);
string push="buy"+result[0];
SendNotification(push);
}
} }
// ?> >H81:5
}
}
string openlink(string url) {
string cookie=NULL,headers;
char post[],result[];
//string url="https://finance.yahoo.com";
//--- 4;O @01>BK A A5@25@>< =5>1E>48<> 4>1028BL URL "https://finance.yahoo.com"
//--- 2 A?8A>: @07@5H5==KE URL (;02=>5 <5=N->!5@28A->0AB@>9:8, 2:;04:0 "!>25B=8:8"):
//--- >1=C;O5< :>4 ?>A;54=59 >H81:8
ResetLastError();
//--- 703@C7:0 html-AB@0=8FK A Yahoo Finance
int res=WebRequest("GET",url,cookie,NULL,500,post,0,result,headers);
if(res==-1)
{
Print("H81:0 2 WebRequest. >4 >H81:8 =",GetLastError());
//--- 2>7<>6=>, URL >BACBAB2C5B 2 A?8A:5, 2K2>48< A>>1I5=85 > =5>1E>48<>AB8 53> 4>102;5=8O
MessageBox("5>1E>48<> 4>1028BL 04@5A '"+url+"' 2 A?8A>: @07@5H5==KE URL 2> 2:;04:5 '!>25B=8:8'","H81:0",MB_ICONINFORMATION);
}
else
{
if(res==200)
{
//--- CA?5H=0O 703@C7:0
PrintFormat("$09; CA?5H=> 703@C65=, @07<5@ %d 109B.",ArraySize(result));
//PrintFormat("03>;>2:8 A5@25@0: %s",headers);
//--- A>E@0=O5< 40==K5 2 D09;
int filehandle=FileOpen("in.txt",FILE_WRITE|FILE_BIN);
if(filehandle!=INVALID_HANDLE)
{
//--- A>E@0=O5< A>45@68<>5 <0AA820 result[] 2 D09;
FileWriteArray(filehandle,result,0,ArraySize(result));
//--- 70:@K205< D09;
FileClose(filehandle);
}
else
Print("H81:0 2 FileOpen. >4 >H81:8 =",GetLastError());
}
else
PrintFormat("H81:0 703@C7:8 '%s', :>4 %d",url,res);
}
return CharArrayToString(result);
}
//+------------------------------------------------------------------+