//+------------------------------------------------------------------+
//| Modnik.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, AM2"
#property link "http://www.forexsystems.biz"
#property description "BBands expert advisor"
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern double MACDLevel = 0.001; // максимальный лот
extern int StopLoss = 5000; // лось
extern int TakeProfit = 5000; // язь
extern int StartHour = 0; // час начала торговли
extern int StartMin = 30; // минута начала торговли
extern int EndHour = 23; // час окончания торговли
extern int EndMin = 30; // минута окончания торговли
extern int Shift = 1; // сдвиг
extern int Slip = 30; // слипаж
extern bool MACD = true; // MACD включен
extern int Magic = 123; // магик
//----
extern string IndName1 = "BBands_Stop_v1";
extern int Length = 20; // период BB
extern int Deviation = 2; // отклонение ВВ
extern double MoneyRisk = 1; // Offset Factor
extern string IndName2 = "MACD_MOD";
input int InpFastEMA = 12; // Fast EMA Period
input int InpSlowEMA = 26; // Slow EMA Period
input int InpSignalSMA = 9; // Signal SMA Period
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr;
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(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 30.04.2009 |
//| Описание : Возвращает флаг разрешения торговли по времени. |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| hb - часы времени начала торговли |
//| mb - минуты времени начала торговли |
//| he - часы времени окончания торговли |
//| me - минуты времени окончания торговли |
//+----------------------------------------------------------------------------+
bool isTradeTimeInt(int hb=0,int mb=0,int he=0,int me=0)
{
datetime db, de; // Время начала и окончания работы
int hc; // Часы текущего времени торгового сервера
db=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+(string)hb+":"+(string)mb);
de=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+(string)he+":"+(string)me);
hc=TimeHour(TimeCurrent());
if(db>=de)
{
if(hc>=he) de+=24*60*60; else db-=24*60*60;
}
if(TimeCurrent()>=db && TimeCurrent()<=de) return(True);
else return(False);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
//--- get Ind
double BBBlue = iCustom(NULL,0,IndName1,Length,Deviation,0,Shift);
double BBRed = iCustom(NULL,0,IndName1,Length,Deviation,1,Shift);
double BBBlue2 = iCustom(NULL,0,IndName1,Length,Deviation,0,Shift+1);
double BBRed2 = iCustom(NULL,0,IndName1,Length,Deviation,1,Shift+1);
double blue = iCustom(NULL,0,IndName2,InpFastEMA,InpSlowEMA,InpSignalSMA,1,Shift);
double red = iCustom(NULL,0,IndName2,InpFastEMA,InpSlowEMA,InpSignalSMA,0,Shift);
bool buy,sell;
if(MACD)
{
buy = BBBlue>0 && BBRed2>0 && red<1000 && red>MACDLevel;
sell = BBRed>0 && BBBlue2>0 && blue<1000 && blue<-MACDLevel;
}
if(!MACD)
{
buy = BBBlue>0 && BBRed2>0;
sell = BBRed>0 && BBBlue2>0;
}
if(sell)
{
PutOrder(1,Bid);
}
if(buy)
{
PutOrder(0,Ask);
}
//---
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1 && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin)) OpenPos();
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| OAO.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 50; // лось
extern int TakeProfit = 70; // язь
extern int Expiration = 10; // истечение ордера
extern bool BSDel = true; // удалим байстоп после пересечения
extern bool SSDel = true; // удалим селстоп после пересечения
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
bool b=true,s=true;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr;
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,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CrossBars()
{
int bar=0;
for(int i=0;i<100;i++)
{
double ao1=iAO(NULL,0,i);
double ao2=iAO(NULL,0,i+1);
if((ao1>0 && ao2<0) || (ao1<0 && ao2>0))
{
bar=i;
break;
}
}
return(bar);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
double ao1=iAO(NULL,0,1);
double ao2=iAO(NULL,0,2);
double ao3=iAO(NULL,0,3);
double low=Low[iLowest(NULL,0,MODE_LOW,CrossBars(),1)];
double high=High[iHighest(NULL,0,MODE_HIGH,CrossBars(),1)];
if(CountTrades()<1)
{
if(ao1>0 && ao2>ao1 && ao2>ao3 && CountOrders(4)<1 && Bid<high && b)
{
PutOrder(4,high);
b=false;s=true;
}
if(ao1<0 && ao2<ao1 && ao2<ao3 && CountOrders(5)<1 && Bid>low && s)
{
PutOrder(5,low);
s=false;b=true;
}
}
if((ao1>0 && ao2<0 && SSDel) || (ao1<0 && ao2>0 && BSDel)) DelOrder();
Comment(CrossBars());
}
//+------------------------------------------------------------------+
Советник должен устанавливать отложку только когда АО в первый раз пересекает нулевую линию, и в первый раз появляется бар противоположного цвета, и после этого больше не устанавливать отложки, до нового пересечения нуля.
Андрей сова молчит вот настройки
extern int Expiration = 10; // истечение ордера
//+------------------------------------------------------------------+
//| Breakout.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern double Lots = 0.1; // лот
extern int TakeProfit = 300; // язь
extern int TrailingStop = 0; // трал
extern int TrailingStep = 20; // шаг трала
extern int Delta = 100; // расстояние от коробки
extern int Expiration = 10; // истечение ордера
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
extern string IndName = "Indicator_GUBreakout_V.0.4.2";
extern int iNumber = 123; //
extern int GMT = 1; //
extern string Start = "23:00";
extern string End = "01:00";
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double sl,double tp)
{
int r=0;
color clr;
if(type==1 || type==3 || type==5)
{
clr=Red;
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>TrailingStop*Point)
{
if(OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if(OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss()==0)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
double ind=iCustom(NULL,0,IndName,"",iNumber,"",GMT,Start,End);
double up=ObjectGetDouble(0,"GUB01231",OBJPROP_PRICE1);
double dn=ObjectGetDouble(0,"GUB11231",OBJPROP_PRICE1);
if(CountTrades()<1)
{
if(CountOrders(4)<1 && Bid<up) PutOrder(4,up+Delta*Point,dn-Delta*Point,up+Delta*Point+TakeProfit*Point);
if(CountOrders(5)<1 && Bid>dn) PutOrder(5,dn-Delta*Point,up+Delta*Point,dn-Delta*Point-TakeProfit*Point);
}
if(TrailingStop>0) Trailing();
}
//+------------------------------------------------------------------+
AM2