//+------------------------------------------------------------------+
//| Real.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double Risk = 5; // риск
extern double StopLoss = 500; // лось
extern double TakeProfit = 500; // язь
extern int Step = 200; // шаг
extern int Orders = 5; // макс ордеров в рынке
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Slip = 30; // реквот
extern int CloseSig = 0; // 1-закрытие по сигналу
extern int Magic = 123; // магик
extern bool Buy = true; // buy
extern bool Sell = true; // sell
extern string IndName="Real Trend";
extern int SignalPeriod= 15;
extern int ArrowPeriod = 2;
//+------------------------------------------------------------------+
//| 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;
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void ClosePos()
{
double buy=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,2,Shift);
double sell=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,3,Shift);
if(sell>0)
{
CloseAll(0);
}
if(buy>0)
{
CloseAll(1);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
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()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
double lotstep=MarketInfo(Symbol(),MODE_LOTSTEP);
double MinLot=MarketInfo(Symbol(),MODE_MINLOT);
double MaxLot=MarketInfo(Symbol(),MODE_MAXLOT);
if(Lots==0) lot=AccountBalance()/100000*Risk;
lot=NormalizeDouble(lot/lotstep,0)*lotstep;
if(lot<MinLot) lot=MinLot;
if(lot>MaxLot) lot=MaxLot;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastPrice()
{
double lp=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) lp=OrderOpenPrice();
break;
}
}
}
return(lp);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastType()
{
int tp=8;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) tp=OrderType();
break;
}
}
}
return(tp);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
double buy=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,2,Shift);
double sell=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,3,Shift);
if((CountTrades()<1 && buy>0 && Buy) || (CountTrades()<Orders && LastType()==0 && Bid-LastPrice()>Step*Point)) PutOrder(0,Ask);
if((CountTrades()<1 && sell>0 && Sell) || (CountTrades()<Orders && LastType()==1 && LastPrice()-Bid>Step*Point)) PutOrder(1,Bid);
if(CloseSig>0) ClosePos();
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Kanal.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // торговый объем ордера
extern double MaxLot = 5; // максимальный торговый объем
extern double KLot = 2; // увеличение лота
extern double Price = 1.19; // цена
extern int StopLoss = 500; // лось
extern int TakeProfit = 200; // язь
extern int Delta = 200; // дельта
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
bool b=1,s=1;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot)
{
int r=0;
color clr=clrNONE;
double sl=0,tp=0;
datetime expiration=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 CountOrders(int type)
{
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()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder(int type)
{
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) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastType()
{
int tp=8;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) tp=OrderType();
break;
}
}
}
return(tp);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastLot()
{
double lt=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) lt=OrderLots();
break;
}
}
}
return(lt);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Bid>Price && CountTrades()<1)
{
if(CountOrders(3)<1) PutOrder(3,Bid+Delta*Point,Lots);
if(CountOrders(2)<1) PutOrder(2,Bid-Delta*Point,Lots);
}
if(CountOrders(3)<1 && s)
{
DelOrder(2);
if(CountOrders(2)<1) PutOrder(2,Price-Delta*Point,LastLot()*KLot);
s=0;b=1;
}
if(CountOrders(2)<1 && b)
{
DelOrder(3);
if(CountOrders(3)<1) PutOrder(3,Price+Delta*Point,LastLot()*KLot);
b=0;s=1;
}
Comment("");
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Kanal.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // торговый объем ордера
extern double MaxLot = 5; // максимальный торговый объем
extern double KLot = 2; // увеличение лота
extern double Price = 1.19; // цена
extern int StopLoss = 500; // лось
extern int TakeProfit = 200; // язь
extern int Delta = 200; // дельта
extern int BuySell = 0; // 0-buy 1-sell 2-both
extern int Step = 100; // шаг
extern int Slip = 30; // реквот
extern bool MA = false; // фильтр
extern int Magic = 123; // магик
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot)
{
int r=0;
color clr=clrNONE;
double sl=0,tp=0;
datetime expiration=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 CountOrders(int type)
{
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()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder(int type)
{
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) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastType()
{
int tp=8;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) tp=OrderType();
break;
}
}
}
return(tp);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastLot()
{
double lt=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) lt=OrderLots();
break;
}
}
}
return(lt);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Bid>Price && CountTrades()<1)
{
if(CountOrders(3)<1) PutOrder(3,Bid+Delta*Point,Lots);
if(CountOrders(2)<1) PutOrder(2,Bid-Delta*Point,Lots);
}
if(CountOrders(3)<1)
{
DelOrder(2);
if(CountOrders(2)<1) PutOrder(2,Price-Delta*Point,LastLot()*KLot);
}
if(CountOrders(2)<1)
{
DelOrder(3);
if(CountOrders(3)<1) PutOrder(3,Price+Delta*Point,LastLot()*KLot);
}
Comment("");
}
//+------------------------------------------------------------------+
ras78