//+------------------------------------------------------------------+
//| Poshnik.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 500; // лось
extern int TakeProfit = 500; // язь
extern int Delta = 100; // расстояние от цены
extern int BuySell = 0; // 1-buy 2-sell 0-off
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
//+------------------------------------------------------------------+
//| 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;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0)
sl=NormalizeDouble(price+StopLoss*_Point,_Digits);
if(TakeProfit>0)
tp=NormalizeDouble(price-TakeProfit*_Point,_Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0)
sl=NormalizeDouble(price-StopLoss*_Point,_Digits);
if(TakeProfit>0)
tp=NormalizeDouble(price+TakeProfit*_Point,_Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,_Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()<2)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MarketOOP()
{
double oop=0;
if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()<2)
oop=OrderOpenPrice();
}
return(oop);
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder(int type=-1)
{
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()==type || type==-1)
del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double MarketLot()
{
double lot=0;
if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()<2)
lot=OrderLots();
}
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(Lots==0)
lot=MarketLot();
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastType()
{
int type=8;
if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()<2)
type=OrderType();
}
return(type);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double StopOOP()
{
double oop=0;
if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()>1)
oop=OrderOpenPrice();
}
return(oop);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1)
{
DelOrder();
if(BuySell==1)
PutOrder(0,Ask);
if(BuySell==2)
PutOrder(1,Bid);
}
if(MarketOOP()>0 && StopOOP()!=NormalizeDouble(MarketOOP()-Delta*_Point,_Digits) && LastType()==0)
PutOrder(5,MarketOOP()-Delta*_Point);
if(MarketOOP()>0 && StopOOP()!=NormalizeDouble(MarketOOP()+Delta*_Point,_Digits) && LastType()==1)
PutOrder(4,MarketOOP()+Delta*_Point);
}
//+------------------------------------------------------------------+
igrun