<code> //+------------------------------------------------------------------+ //| Chart.mq4 | //| Copyright 2022, AM2 | //| https://www.forexsystems.biz | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, AM2" #property link "https://www.forexsystems.biz" #property version "1.00" #property strict bool cl=0; datetime time=0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- включение сообщений о перемещении мыши по окну чарта ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,1); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectsDeleteAll(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void PutButton(string name,int x,int y,string text) { ObjectCreate(0,name,OBJ_BUTTON,0,0,0); //--- установим координаты кнопки ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y); //--- установим размер кнопки ObjectSetInteger(0,name,OBJPROP_XSIZE,80); ObjectSetInteger(0,name,OBJPROP_YSIZE,30); //--- установим угол графика, относительно которого будут определяться координаты точки ObjectSetInteger(0,name,OBJPROP_CORNER,2); //--- установим текст ObjectSetString(0,name,OBJPROP_TEXT,text); //--- установим шрифт текста ObjectSetString(0,name,OBJPROP_FONT,"Arial"); //--- установим размер шрифта ObjectSetInteger(0,name,OBJPROP_FONTSIZE,12); //--- установим цвет текста ObjectSetInteger(0,name,OBJPROP_COLOR,Red); //--- установим цвет фона ObjectSetInteger(0,name,OBJPROP_BGCOLOR,White); //--- установим цвет границы ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,Blue); //--- скроем (true) или отобразим (false) имя графического объекта в списке объектов ObjectSetInteger(0,name,OBJPROP_HIDDEN,0); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, // идентификатор события const long& lparam, // параметр события типа long const double& dparam, // параметр события типа double const string& sparam // параметр события типа string ) { if(id==CHARTEVENT_MOUSE_MOVE) { Comment("POINT: ",(int)lparam,",",(int)dparam, "\n","MouseState=",(uint)sparam, "\n time=",time, "\n TimeCurrent()=",TimeCurrent()); if((uint)sparam==1) { time=TimeCurrent(); } if((uint)sparam!=1) { if(time+10<TimeCurrent()) { ObjectsDeleteAll(); ChartRedraw(); } } } //--- нажатие кнопки на клавиатуре if(id==CHARTEVENT_KEYDOWN && time+10>TimeCurrent()) { if(lparam==81) { PutButton("c",33,33,"BUTON"); time=TimeCurrent(); } } } //+------------------------------------------------------------------+ </code>
//+------------------------------------------------------------------+
//| TimeIsMoney.mq4 |
//| Copyright 2022, Ve |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, Ve"
#property link ""
#property version "1.00"
#property strict
extern double Lots = 0.01; //Лот
extern int Distance = 100; //Расстояние от цены
extern int TakeProfit = 200; //Тейк
extern int StopLoss = 500; //Cтоп-лосс
extern double KLot = 2; //умножение лота при лосе
extern int TrailingStop = 40; //трейлинг
extern int TrailingStep = 50; //шаг трейлинга
extern int LifeTime = 600; //Время жизни ордеров
extern int Slip = 10; //Reqot
extern int Magic = 123; //Magic
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
datetime time=TimeCurrent()+LifeTime;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(TakeProfit>0)
tp=NormalizeDouble(price-TakeProfit*_Point,_Digits);
if(StopLoss>0)
sl=NormalizeDouble(price+StopLoss*_Point,_Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(TakeProfit>0)
tp=NormalizeDouble(price+TakeProfit*_Point,_Digits);
if(StopLoss>0)
sl=NormalizeDouble(price-StopLoss*_Point,_Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,time,clr);
GetLastError();
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(LastDealResult()==0)
lot=NormalizeDouble(LastLot()*KLot,_Digits);
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastLot()
{
double lot=0;
int oticket,ticketNumber=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2)
{
oticket=OrderTicket();
if(oticket>ticketNumber)
{
ticketNumber=oticket;
lot=OrderLots();
}
}
}
}
}
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealResult()
{
int result=2,oticket,ticketNumber=0;
double ord=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2)
{
oticket=OrderTicket();
if(oticket>ticketNumber)
{
ticketNumber=oticket;
ord=OrderProfit();
}
}
}
}
}
if(ord>0) result=1;//tp
if(ord<0) result=0;//sl
return(result);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type=-1)
{
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()>1 && type==-1)||(OrderType()<6 && type==6))
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()>1)
del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
double all=0,count=0,sl=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2)
{
all+=OrderOpenPrice()*OrderLots();
count+=OrderLots();
}
}
}
}
if(count>0)
all=NormalizeDouble(all/count,_Digits);
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)
{
if(Bid-all>TrailingStop*_Point)
{
if(OrderStopLoss()<Bid-(TrailingStop+TrailingStep)*_Point)
{
sl=NormalizeDouble(Bid-TrailingStop*_Point,_Digits);
if(OrderStopLoss()!=sl)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Yellow);
}
}
}
if(OrderType()==OP_SELL)
{
if(all-Ask>TrailingStop*_Point)
{
if((OrderStopLoss()>(Ask+(TrailingStop+TrailingStep)*_Point)) || (OrderStopLoss()==0))
{
sl=NormalizeDouble(Bid+TrailingStop*_Point,_Digits);
if(OrderStopLoss()!=sl)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Yellow);
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(TrailingStop>0)//если значение трейлинга больше 0
Trailing(); //тогда тралим позицию
if(CountOrders()<2)//если отложенных ордеров меньше двух,
DelOrder(); // тогда оставшийся удаляем.
if(CountOrders(6)<1 )//если нет ни открытых позиций ни отложенных ордеров
{
PutOrder(4,Ask+Distance*_Point);//тогда выставляем байстоп
PutOrder(5,Bid-Distance*_Point);// и селлстоп ордераю
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| TimeIsMoney.mq4 |
//| Copyright 2022, Ve |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, Ve"
#property link ""
#property version "1.00"
#property strict
extern double Lots = 0.01; //Лот
extern int Distance = 100; //Расстояние от цены
extern int TakeProfit = 200; //Тейк
extern int StopLoss = 500; //Cтоп-лосс
extern double KLot = 2; //умножение лота при лосе
extern int LifeTime = 600; //Время жизни ордеров
extern int Slip = 10; //Reqot
extern int Magic = 123; //Magic
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
datetime time=TimeCurrent()+LifeTime;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(TakeProfit>0)
tp=NormalizeDouble(price-TakeProfit*_Point,_Digits);
if(StopLoss>0)
sl=NormalizeDouble(price+StopLoss*_Point,_Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(TakeProfit>0)
tp=NormalizeDouble(price+TakeProfit*_Point,_Digits);
if(StopLoss>0)
sl=NormalizeDouble(price-StopLoss*_Point,_Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,time,clr);
GetLastError();
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(LastDealResult()==0)
lot=NormalizeDouble(LastLot()*KLot,_Digits);
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastLot()
{
double lot=0;
int oticket,ticketNumber=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2)
{
oticket=OrderTicket();
if(oticket>ticketNumber)
{
ticketNumber=oticket;
lot=OrderLots();
}
}
}
}
}
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealResult()
{
int result=2,oticket,ticketNumber=0;
double ord=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2)
{
oticket=OrderTicket();
if(oticket>ticketNumber)
{
ticketNumber=oticket;
ord=OrderProfit();
}
}
}
}
}
if(ord>0) result=1;//tp
if(ord<0) result=0;//sl
return(result);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type=-1)
{
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()>1 && type==-1)||(OrderType()<6 && type==6))
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()>1)
del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountOrders()<2)
DelOrder();
if(CountOrders(6)<1 )
{
PutOrder(4,Ask+Distance*_Point);
PutOrder(5,Bid-Distance*_Point);
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| pair trading.mq4 |
//| Copyright 2021, Ve |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Ve"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
extern string s1="===============";
extern string S1 ="EURUSD"; //первая пара
extern double Lots1 =0.01; //Лот 1 пара
enum Trade_direction1
{
Buy1=0, //Buy
Sell1=1 //Sell
};
input Trade_direction1 Trade1 =0; //направление сделки
extern string s2="===============";
extern string S2 ="GBPUSD"; //вторая пара
extern double Lots2 =0.01; //Лот 2 пара
enum Trade_direction2
{
Buy2=0, //Buy
Sell2=1 //Sell
};
input Trade_direction2 Trade2 =0; //направление сделки
extern string s3="===============";
extern int Profit =10; //общий профит
extern int Slip = 30; //проскальзывание
extern int Magic = 123; //Magic
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,string symbol,double lot)
{
int r=0;
color clr=Lime;
double MINLOT = MarketInfo(symbol,MODE_MINLOT);
double MAXLOT = MarketInfo(symbol,MODE_MAXLOT);
if(lot<MINLOT)
lot=MINLOT;
if(lot>MAXLOT)
lot=MAXLOT;
if(type==1 || type==3 || type==5)
{
clr=Red;
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(symbol,type,lot,NormalizeDouble(price,Digits),Slip,0,0,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit()
{
double pr=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderSymbol()==S1 || OrderSymbol()==S2) && OrderMagicNumber()==Magic)
{
if(OrderType()==0)
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1)
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll()
{
bool cl;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderSymbol()==S1 || OrderSymbol()==S2) && OrderMagicNumber()==Magic)
{
if(OrderType()==0)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades(string symbol)
{
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()<2)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double bid_s1= MarketInfo(S1,MODE_BID);
double bid_s2= MarketInfo(S2,MODE_BID);
double ask_s1=MarketInfo(S1,MODE_ASK);
double ask_s2=MarketInfo(S2,MODE_ASK);
if(AllProfit()>0 && AllProfit()>=Profit)
CloseAll();
if(CountTrades(S1)<1)
{
switch (Trade1)
{
case 0: PutOrder(0,ask_s1,S1,Lots1);break;
case 1: PutOrder(1,bid_s1,S1,Lots1);break;
}
}
if(CountTrades(S2)<1)
{
switch (Trade2)
{
case 0: PutOrder(0,ask_s2,S2,Lots2);break;
case 1: PutOrder(1,bid_s2,S2,Lots2);break;
}
}
}
//+------------------------------------------------------------------+
"430.20000000", //Цена открытия (Open)
string url="https://api.binance.com/api/v3/ticker/24hr?symbol=BTCUSDT";
{
"symbol": "BNBBTC", // пара
"priceChange": "-94.99999800", // изменение цены за сутки
"priceChangePercent": "-95.960", // изменение цены за сутки %
"weightedAvgPrice": "0.29628482", //Средневзвешенная цена
"prevClosePrice": "0.10002000", // Предыдущая цена закрытия
"lastPrice": "4.00000200", // Последняя цена
"lastQty": "200.00000000", // Последний объем
"bidPrice": "4.00000000", // Цена покупки
"askPrice": "4.00000200", // Цена продажи
"openPrice": "99.00000000", // Цена открытия
"highPrice": "100.00000000", // Самая высокая цена
"lowPrice": "0.10000000", // Самая низкая цена
"volume": "8913.30000000", // Объем торгов базовой валюты
"quoteVolume": "15.30000000", // Объем торгов квотируемой
"openTime": 1499783499040, // Время открытия
"closeTime": 1499869899040, // Время закрытия
"fristId": 28385, // Id первой сделки
"lastId": 28460, // Id последней сделки
"count": 76 // Кол-во сделок
}
Правильно понял?
verta81