//+------------------------------------------------------------------+
//| Lock.mq4 |
//| Copyright 2018, AM2 |
//| http://www.forexsyatems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link "http://www.forexsyatems.biz"
#property version "1.00"
#property strict
extern double BLot = 0.1; // бай лот
extern double SLot = 0.05; // селл лот
extern double Pro = 30; // процент
extern int Slip = 30; // реквот
extern int Magic = 111; // магик
extern int LMagic = 222; // магик лока
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot,int mn)
{
int r=0;
color clr=Green;
if(type==1 || type==3 || type==5)
{
clr=Red;
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(NULL,type,lot,NormalizeDouble(price,Digits),Slip,0,0,"",mn,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades(int mn)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==mn)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lots(int type)
{
double lot=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==type) lot+=OrderLots();
}
}
}
return(lot);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades(Magic)<1)
{
PutOrder(0,Ask,BLot,Magic);
PutOrder(1,Bid,SLot,Magic);
}
if(Lots(1)/Lots(0)*100<Pro && Lots(0)>Lots(1)) PutOrder(1,Ask,Lots(0)*Pro*0.01-Lots(1),LMagic);
if(Lots(0)/Lots(1)*100<Pro && Lots(1)>Lots(0)) PutOrder(1,Bid,Lots(1)*Pro*0.01-Lots(0),LMagic);
Comment("\n Buy Lots: ",Lots(0),
"\n Sell Lots: ",Lots(1));
}
//+------------------------------------------------------------------+
AM2