//+------------------------------------------------------------------+
//| Binarik9.mq4 |
//| Copyright 2020, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern bool LosUsr = true;
extern double Lots = 1; // лот
extern double KLot = 2.2; // увеличение лота
extern double MaxLot = 99999; // максимальный лот
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int Slip = 3; // реквот
extern int Shift = 1; // бар индикатора
extern int Magic = 11111; // магик
extern ENUM_TIMEFRAMES TF = PERIOD_M5; // ТФ
extern string Expiration = "5"; // истечение
extern int Reverse = 0; // 1-реверс
extern string IndName = "+++Agimat BO Trigger";
extern bool Message = 1;
extern int Length = 6;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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,Expiration,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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LossUsr()
{
int loss=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0)
{
if(OrderClosePrice()-OrderOpenPrice()<0)
loss++;
if(OrderClosePrice()-OrderOpenPrice()>0)
break;
}
if(OrderType()==1)
{
if(OrderClosePrice()-OrderOpenPrice()>0)
loss++;
if(OrderClosePrice()-OrderOpenPrice()<0)
break;
}
}
}
}
return(loss);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LossPir()
{
int loss=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==1)
{
if(OrderClosePrice()-OrderOpenPrice()<0)
loss++;
if(OrderClosePrice()-OrderOpenPrice()>0)
break;
}
if(OrderType()==0)
{
if(OrderClosePrice()-OrderOpenPrice()>0)
loss++;
if(OrderClosePrice()-OrderOpenPrice()<0)
break;
}
}
}
}
return(loss);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
int Loss=0;
if(LosUsr)
{
Loss=LossUsr();
}
else
{
Loss=LossPir();
}
double lot=NormalizeDouble(Lots*MathPow(KLot,Loss),2);
if(lot>MaxLot)
lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
/*
void OnTick()
{
double up=iCustom(NULL,TF,IndName,Message,Length,1,Shift);
double dn=iCustom(NULL,TF,IndName,Message,Length,2,Shift);
bool buy=up!=EMPTY_VALUE;
bool sell=dn!=EMPTY_VALUE;
if(Reverse>0)
{
buy=dn!=EMPTY_VALUE;
sell=up!=EMPTY_VALUE;
}
if(CountTrades()<1)
{
if(buy)
{
PutOrder(0,Ask);
}
if(sell)
{
PutOrder(1,Bid);
}
}
Comment("\n Lot: ",Lot(),
"\n Up: ",up,
"\n Dn: ",dn);
}
//+------------------------------------------------------------------+
*/
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
/*
void OnTick()
{
double up=iCustom(NULL,TF,IndName,Message,Length,1,Shift);
double dn=iCustom(NULL,TF,IndName,Message,Length,2,Shift);
bool buy=up!=EMPTY_VALUE;
bool sell=dn!=EMPTY_VALUE;
if(Reverse>0)
{
buy=dn!=EMPTY_VALUE;
sell=up!=EMPTY_VALUE;
}
if(CountTrades()<1)
{
if(buy)
{
PutOrder(0,Ask);
}
if(sell)
{
PutOrder(1,Bid);
}
}
Comment("\n Lot: ",Lot(),
"\n Up: ",up,
"\n Dn: ",dn);
}
//+------------------------------------------------------------------+
*/
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double ma1=iMA(NULL,0,10,0,0,0,1);
double ma2=iMA(NULL,0,50,0,0,0,1);
bool buy=ma1>ma2;
bool sell=ma1<ma2;
if(CountTrades()<1)
{
if(buy)
{
PutOrder(0,Ask);
}
if(sell)
{
PutOrder(1,Bid);
}
}
Comment("\n Lot: ",Lot());
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
int r=0;
double pr=0;
// if(t!=Time[0])
// {
// DelOrder();
// t=Time[0];
// }
//-------------------------------------------------
//---------- блок подсчёта ордеров
int limitbuy=0;
int limitsell=0;
int stopbuy=0;
int stopsell=0;
int buy=0;
int sell=0;
int i;
for( i=OrdersTotal()-1;i>=0;i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0) buy++;
if(OrderType()==1) sell++;
if(OrderType()==2) limitbuy++;
if(OrderType()==3) limitsell++;
if(OrderType()==4) stopbuy++;
if(OrderType()==5) stopsell++;
}
}
}
//------------------------------------------------
ModifyOrders();
if(buy!=0)DelOrderS();
if(sell!=0)DelOrderB();
//------------------------------------------------
if(CountTrades(0)<1 && CountTrades(1)<1 && TimeSession(StartHour,StartMin,EndHour,EndMin,TimeCurrent()))
{
if(CountOrders(4)<1)
{
for(int i=1; i<=Count; i++)
{
pr=NormalizeDouble(Bid+Delta*i*_Point,_Digits);
r=OrderSend(NULL,4,Lots,pr,Slip,0,0,"",Magic,0,Blue);
}
}
if(CountOrders(5)<1)
{
for(int i=1; i<=Count; i++)
{
pr=NormalizeDouble(Bid-Delta*i*_Point,_Digits);
r=OrderSend(NULL,5,Lots,pr,Slip,0,0,"",Magic,0,Red);
}
}
}
//---------------------------------------------------------
if(AllProfit()>Profit && Profit>0){
CloseAll();
DelOrderS();
DelOrderB();
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| EA на индикатере 10.7 CSS.v3.8ps_withAlertsCross |
//| Copyright 2013, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| bobsley.mq4 |
//| Copyright © 2010, AM2 Group. |
//| http://www.crossmaker.narod.ru |
//+------------------------------------------------------------------+
#define MAGICMA 20101022
extern bool EA = true;
extern string symb1 = "EURUSD";
extern double StopLoss1 = 0.0035;
extern double TakeProfit1 = 0.007;
extern double delta1 = 0.5; //Разница между выбранными символами для открытия позиций
extern bool Revers1 = true;
extern double Risk = 0.1;
input ENUM_TIMEFRAMES tf_trade = PERIOD_H1;
extern double MaxLots = 1;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//-------------------
//=======================================
double usd = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",0,1);//
double eur = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",1,1);//
double gbp = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",2,1);//
double jpy = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",3,1);//
double aud = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",4,1);//
double cad = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",5,1);//
double nzd = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",6,1);//
double chf = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",7,1);//
//=======================================
eur = NormalizeDouble(eur,2);
usd = NormalizeDouble(usd,2);
jpy = NormalizeDouble(jpy,2);
cad = NormalizeDouble(cad,2);
aud = NormalizeDouble(aud,2);
nzd = NormalizeDouble(nzd,2);
gbp = NormalizeDouble(gbp,2);
chf = NormalizeDouble(chf,2);
Comment("\n\n\n\n\n\n\n\nEUR: "+DoubleToStr(eur,2)+"\nUSD: "+DoubleToStr(usd,2)+"\nJPY: "+DoubleToStr(jpy,2)+"\nCAD: "+DoubleToStr(cad,2)+"\nAUD: "+DoubleToStr(aud,2)+"\nNZD: "+DoubleToStr(nzd,2)+"\nGBP: "+DoubleToStr(gbp,2)+"\nCHF: "+DoubleToStr(chf,2));
//-------------------
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(symb1)==0) CheckForOpenEU();
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int pos=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==symbol && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL) pos++;
}
}
//---- return orders volume
if(pos>0) return(pos);
return(pos);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpenEU()
{
int res;
int dig=(int)SymbolInfoInteger(symb1,SYMBOL_DIGITS);
double ask = NormalizeDouble(MarketInfo(symb1,MODE_ASK),dig);
double bid = NormalizeDouble(MarketInfo(symb1,MODE_BID),dig);
//----
double usd = iCustom(symb1,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",0,1);//
double eur = iCustom(symb1,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",1,1);//
/*
double gbp = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",2,1);//
double jpy = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",3,1);//
double aud = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",4,1);//
double cad = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",5,1);//
double nzd = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",6,1);//
double chf = iCustom(NULL,tf_trade,"10.7 CSS.v3.8ps_withAlertsCross",7,1);//
*/
//-------------------------
if(Revers1){
//---- sell
if(usd-eur>delta1)
{
res=OrderSend(symb1,OP_BUY,Lots(),ask,3,bid-StopLoss1,ask+TakeProfit1,"",MAGICMA,0,Blue);
return;
}
//---- buy
if(eur-usd>delta1)
{
res=OrderSend(symb1,OP_SELL,Lots(),bid,3,ask+StopLoss1,bid-TakeProfit1,"",MAGICMA,0,Red);
return;
}
}
else{
//---- sell
if(usd-eur>delta1)
{
res=OrderSend(symb1,OP_SELL,Lots(),bid,3,ask+StopLoss1,bid-TakeProfit1,"",MAGICMA,0,Red);
return;
}
//---- buy
if(eur-usd>delta1)
{
res=OrderSend(symb1,OP_BUY,Lots(),ask,3,bid-StopLoss1,ask+TakeProfit1,"",MAGICMA,0,Blue);
return;
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double Lots()
{
double Lots;
Lots=AccountFreeMargin()/10000*5;
Lots=MathMin(15,MathMax(0.01,Lots));
if(Lots<0.01)
Lots=NormalizeDouble(Lots,2);
else
{
if(Lots<1) Lots=NormalizeDouble(Lots,1);
else Lots=NormalizeDouble(Lots,0);
}
if(Lots>MaxLots)Lots=MaxLots;
return(Lots);
}
//+------------------------------------------------------------------+
void CheckForOpenUСhf()
а затем передать в void OnTick() как if(CalculateCurrentOrders(symb2)==0) CheckForOpenUChf();
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades(string symb, int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==symb && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL ) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double ask1=MarketInfo(Symb1,MODE_ASK);
double ask2=MarketInfo(Symb2,MODE_ASK);
int dig1=(int)SymbolInfoInteger(Symb1,SYMBOL_DIGITS);
double bid1=MarketInfo(Symb1,MODE_BID);
double bid2=MarketInfo(Symb2,MODE_BID);
int dig2=(int)SymbolInfoInteger(Symb2,SYMBOL_DIGITS);
if(AllProfit()>Profit && Profit>0)
CloseAll();
if(AllProfit()<-Loss && Loss>0)
CloseAll();
//просто перебор "в лоб" комбинаций с открытием позиций
if(CountTrades(Symb1,OP_BUY)<1 && Type1==0){PutOrder(Symb1,0,NormalizeDouble(ask1,dig1));}
if(CountTrades(Symb1,OP_SELL)<1 && Type2==1){PutOrder(Symb1,1,NormalizeDouble(bid1,dig1));}
if(CountTrades(Symb2,OP_BUY)<1 && Type1==0){PutOrder(Symb2,0,NormalizeDouble(ask2,dig2));}
if(CountTrades(Symb2,OP_SELL)<1 && Type2==1){PutOrder(Symb2,1,NormalizeDouble(bid2,dig2));}
Comment("\n Profit : ",AllProfit());
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot(int type)
{
double lot=Lots;
if(CountTrades(type)>0)
lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades(type)),2);
if(lot>MaxLot)
lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double ask1=MarketInfo(Symb1,MODE_ASK);
double ask2=MarketInfo(Symb2,MODE_ASK);
int dig1=(int)SymbolInfoInteger(Symb1,SYMBOL_DIGITS);
double bid1=MarketInfo(Symb1,MODE_BID);
double bid2=MarketInfo(Symb2,MODE_BID);
int dig2=(int)SymbolInfoInteger(Symb2,SYMBOL_DIGITS);
if(AllProfit()>Profit && Profit>0)
CloseAll();
if(AllProfit()<-Loss && Loss>0)
CloseAll();
if(CountTrades()<1)
{
if(Type1==0)
PutOrder(Symb1,0,NormalizeDouble(ask1,dig1));
if(Type2==0)
PutOrder(Symb2,0,NormalizeDouble(ask2,dig2));
if(Type1==1)
PutOrder(Symb1,1,NormalizeDouble(bid1,dig1));
if(Type2==1)
PutOrder(Symb2,1,NormalizeDouble(bid2,dig2));
}
Comment("\n Profit : ",AllProfit());
}
//+------------------------------------------------------------------+
if(CountTrades(Symb1)<1 && Type1==0){PutOrder(Symb1,0,NormalizeDouble(ask1,dig1));}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(TrailingStop>0)
Trailing();
if(CountOrders()<1)
DelOrder();
if(Profit>0 && AllProfit()>Profit)
CloseAll();
int i;
if((trades!=CountOrders()) || (CountOrders()<1))
{
DelOrder();
if(CountTrades()<CountOrd*2)
{
if(CountOrders(4)<CountOrd)
{
for (i=1; i<=CountOrd; i++)
{
PutOrder(4,Bid+Delta*_Point*i);
}
if(CountOrders(5)<CountOrd)
{
for (i=1; i<=CountOrd; i++)
{
PutOrder(5,Bid-Delta*_Point*i);
}
}
}
}
trades=CountOrders();
}
Comment("\n Trades: ",CountTrades(),
"\n Profit: ",AllProfit(),
"\n Buy Profit: ",AllProfit(0),
"\n Sell Profit: ",AllProfit(1));
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void GridTrailing(int type,int step)
{
/*
1. находим ближайший к цене ордер
2. смотрим его смещение
3. запоминаеи на сколько он сместился
4. перемещаем остальные ордера
*/
bool mod;
double oop=0,sl=0,tp=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 && type==2) || (OrderType()==5 && type==5))
{
oop=NormalizeDouble(OrderOpenPrice()+step*Point,Digits);
if(OrderType()==2 && StopLoss>0) {sl=NormalizeDouble(oop-StopLoss*Point,Digits);}
if(OrderType()==5 && StopLoss>0) {sl=NormalizeDouble(oop+StopLoss*Point,Digits);}
if(OrderType()==2 && TakeProfit>0) {tp=NormalizeDouble(oop+TakeProfit*Point,Digits);}
if(OrderType()==5 && TakeProfit>0) {tp=NormalizeDouble(oop-TakeProfit*Point,Digits);}
mod=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
}
if((OrderType()==3 && type==3) || (OrderType()==4 && type==4))
{
oop=NormalizeDouble(OrderOpenPrice()-step*Point,Digits);
if(OrderType()==3 && StopLoss>0) {sl=NormalizeDouble(oop+StopLoss*Point,Digits);}
if(OrderType()==4 && StopLoss>0) {sl=NormalizeDouble(oop-StopLoss*Point,Digits);}
if(OrderType()==3 && TakeProfit>0) {tp=NormalizeDouble(oop-TakeProfit*Point,Digits);}
if(OrderType()==4 && TakeProfit>0) {tp=NormalizeDouble(oop+TakeProfit*Point,Digits);}
mod=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
}
}
}
}
}
//+------------------------------------------------------------------+
После открытия позиции или <code>//+------------------------------------------------------------------+ //| Удаление отложенных ордеров | //+------------------------------------------------------------------+ void DelOrder(string symb,int type=-1) { bool del; for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==symb && OrderMagicNumber()==Magic) { if(OrderType()==type || type==-1) del=OrderDelete(OrderTicket()); } } } } //+------------------------------------------------------------------+</code>
<code> //+----------------------------------------------------------------------------+ //| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru | //+----------------------------------------------------------------------------+ //| Версия : 13.06.2007 | //| Описание : Удаление ордеров. Версия функции для тестов на истории. | //+----------------------------------------------------------------------------+ //| Параметры: | //| sy - наименование инструмента ("" или NULL - текущий символ) | //| op - операция ( -1 - любая позиция) | //| mn - MagicNumber ( -1 - любой магик) | //+----------------------------------------------------------------------------+ void DeleteOrders(string sy="", int op=-1, int mn=-1) { int i, k=OrdersTotal(), ot; if (sy=="" || sy=="0") sy=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { ot=OrderType(); if (ot==OP_BUYLIMIT || ot==OP_BUYSTOP || ot==OP_SELLLIMIT || ot==OP_SELLSTOP) { if (OrderSymbol()==sy && (op<0 || ot==op)) { if (mn<0 || OrderMagicNumber()==mn) { OrderDelete(OrderTicket(), clrRed); } } } } } } //+------------------------------------------------------------------+</code>
Доработаю сам.
ssg