
//+------------------------------------------------------------------+
//| ValeriyVist.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, AM2"
#property link "http://www.forexsystems.biz"
#property description "Not simple expert advisor"
//------- Внешние параметры советника --------------------+
extern double Lot = 0.01; // Лот buy/sell ордера
extern double Lot1 = 0.02; // Лот 1-го limit ордера
extern double Lot2 = 0.04; // Лот 2-го limit ордера
extern double Lot3 = 0.07; // Лот 3-го limit ордера
extern double Lot4 = 0.15; // Лот 4-го limit ордера
extern double Lot5 = 0.3; // Лот 5-го limit ордера
extern double Lot6 = 0.6; // Лот 6-го limit ордера
extern double Lot7 = 1.2; // Лот 7-го limit ордера
extern double Lot8 = 2.5; // Лот 8-го limit ордера
extern double Lot9 = 5.0; // Лот 9-го limit ордера
extern double Lot10 = 10.0; // Лот 10-го limit ордера
extern int Step1 = 50; // Шаг 1-го limit ордера
extern int Step2 = 50; // Шаг 2-го limit ордера
extern int Step3 = 50; // Шаг 3-го limit ордера
extern int Step4 = 50; // Шаг 4-го limit ордера
extern int Step5 = 50; // Шаг 5-го limit ордера
extern int Step6 = 50; // Шаг 6-го limit ордера
extern int Step7 = 50; // Шаг 7-го limit ордера
extern int Step8 = 50; // Шаг 8-го limit ордера
extern int Step9 = 50; // Шаг 9-го limit ордера
extern int Step10 = 50; // Шаг 10-го limit ордера
extern int TP = 30; // Take profit buy/sell ордера
extern int TP1 = 30; // Take profit после 1-го limit ордера
extern int TP2 = 30; // Take profit после 2-го limit ордера
extern int TP3 = 30; // Take profit после 3-го limit ордера
extern int TP4 = 30; // Take profit после 4-го limit ордера
extern int TP5 = 30; // Take profit после 5-го limit ордера
extern int TP6 = 30; // Take profit после 6-го limit ордера
extern int TP7 = 30; // Take profit после 7-го limit ордера
extern int TP8 = 30; // Take profit после 8-го limit ордера
extern int TP9 = 30; // Take profit после 9-го limit ордера
extern int TP10 = 30; // Take profit после 10-го limit ордера
extern int SL = 400; // Stop Loss для всех ордеров
extern int Slip = 30; // Проскальзывание цены
extern int Magic = 123; // Идентификатор ордера
int k=0;
int tp[10],step[10];
double lot[10];
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
k=0;
tp[0]=TP;
tp[1]=TP1;
tp[2]=TP2;
tp[3]=TP3;
tp[4]=TP4;
tp[5]=TP5;
tp[6]=TP6;
tp[7]=TP7;
tp[8]=TP8;
tp[9]=TP9;
tp[10]=TP10;
step[0]=Step1;
step[1]=Step1;
step[2]=Step2;
step[3]=Step3;
step[4]=Step4;
step[5]=Step5;
step[6]=Step6;
step[7]=Step7;
step[8]=Step8;
step[9]=Step9;
step[10]=Step10;
lot[0]=Lot;
lot[1]=Lot1;
lot[2]=Lot2;
lot[3]=Lot3;
lot[4]=Lot4;
lot[5]=Lot5;
lot[6]=Lot6;
lot[7]=Lot7;
lot[8]=Lot8;
lot[9]=Lot9;
lot[10]=Lot10;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) { }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealResult()
{
int result=0;
if(OrdersHistoryTotal()==0)
{
result=0;
}
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealType()
{
int type=0;
if(OrdersHistoryTotal()==0)
{
type=0;
}
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
type=1;//buy
}
if(OrderType()==OP_SELL)
{
type=2;//sell
}
}
}
return(type);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelBuyLimitOrder()
{
bool del;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
{
if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderType()==OP_BUYLIMIT) del=OrderDelete(OrderTicket());
}
}
}
return;
}
//+------------------------------------------------------------------+
void DelSellLimitOrder()
{
bool del;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
{
if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderType()==OP_SELLLIMIT) del=OrderDelete(OrderTicket());
}
}
}
return;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
int res=0;
double pr=0;
if(k>10) k=1;
//когда нет позиций
if(CountTrades()<1)
{
res=OrderSend(Symbol(),OP_BUY,Lot,Ask,Slip,Ask-SL*Point,Ask+TP*Point,"",Magic,0,Blue);
res=OrderSend(Symbol(),OP_SELL,Lot,Bid,Slip,Bid+SL*Point,Bid-TP*Point,"",Magic,0,Red);
k++;
pr=Ask-step[k]*Point;
res=OrderSend(Symbol(),OP_BUYLIMIT,lot[k],pr,0,pr-SL*Point,Ask+tp[k]*Point,"",Magic,0,Blue);
pr=Bid+step[k]*Point;
res=OrderSend(Symbol(),OP_SELLLIMIT,lot[k],pr,0,pr+SL*Point,Bid-tp[k]*Point,"",Magic,0,Red);
return;
}
//когда есть позы и sell закрылся по ТП
if(CountTrades()>0 && LastDealResult()==1 && LastDealType()==2)
{
k++;
DelSellLimitOrder();
res=OrderSend(Symbol(),OP_SELL,Lot,Bid,Slip,Bid+SL*Point,Bid-TP*Point,"",Magic,0,Red);
pr=Bid+step[k]*Point;
res=OrderSend(Symbol(),OP_SELLLIMIT,lot[k],pr,0,pr+SL*Point,pr-tp[k]*Point,"",Magic,0,Red);
return;
}
//когда есть позы и buy закрылся по ТП
if(CountTrades()>0 && LastDealResult()==1 && LastDealType()==1)
{
k++;
DelBuyLimitOrder();
res=OrderSend(Symbol(),OP_BUY,Lot,Ask,Slip,Ask-SL*Point,Ask+TP*Point,"",Magic,0,Blue);
pr=Ask-step[k]*Point;
res=OrderSend(Symbol(),OP_BUYLIMIT,lot[k],pr,0,pr-SL*Point,pr+tp[k]*Point,"",Magic,0,Blue);
return;
}
Comment("\n K: ",k,
"\n TP: ",tp[k],
"\n Lot: ",lot[k],
"\n Step: ",step[k]);
}
//+------------------------------------------------------------------+
extern int StopLoss = 1900;//Стоплосс всех ордеров
extern int TakeProfit = 350; //Тейкпрофит всех ордеров
extern int Slip = 0; //Проскальзывание ордера
extern int TradingDay = 5; //День недели (1-понедельник,...5-Пятница)
extern int TradingWeak = 1; //Неделя в месяце (1-я или 2-я)
extern int StopLimit = 1; //Ставим стоповые(0) или лимитные(1) ордера
extern int StartHour = 9; //Час начала торговли(терминальное время)
extern int StartMin = 30; //Минуты начала торговли(терминальное время)
extern int Distance = 250; //Расстояние от цены для установки стопового ордера
extern int Step = 250; //Шаг установки стоповых ордеров
extern int Count = 10; //Количество устанавливаемых ордеров стоповых или лимитных
extern int Expiration = 300; //Время истечения ордера в минутах
extern double Lots = 0.1; //Лот
extern int Magic = 123; //Магик
//+------------------------------------------------------------------+
//| Martin.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, AM2"
#property link "http://www.forexsystems.biz"
#property description "Martin expert advisor"
extern int Magic = 20150916; //магик
extern int StopLoss = 1200; //лось
extern int TakeProfit = 1400; //язь
extern int Slip = 30; //реквот
extern int BuySell = 0; //0-бай. 1-селл
extern int StopTake = 0; //0-мартин после стопа. 1-мартин после тейка
extern double Lots = 0.1; //лот
extern double MaxLot = 5; //макс. лот
extern double KLot = 2; //умножение лота
//+------------------------------------------------------------------+
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()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
int res;
double pr=0,sl=0,tp=0;
//---- buy
if(BuySell==0)
{
pr=NormalizeDouble(Ask,Digits);
if(StopLoss>0) sl=NormalizeDouble(Ask-StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(Ask+TakeProfit*Point,Digits);
res=OrderSend(Symbol(),OP_BUY,Lot(),pr,Slip,sl,tp,"",Magic,0,Blue);
return;
}
//---- sell
if(BuySell==1)
{
pr=NormalizeDouble(Bid,Digits);
if(StopLoss>0) sl=NormalizeDouble(Bid+StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(Bid-TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_SELL,Lot(),pr,Slip,sl,tp,"",Magic,0,Red);
return;
}
}
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double Lot()
{
double lot=0;
if(OrdersHistoryTotal()==0)
{
lot=Lots;
}
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(StopTake==0)
{
if(OrderProfit()>0)
{
lot=Lots;
}
if(OrderProfit()<=0)
{
lot=OrderLots()*KLot;
}
}
if(StopTake==1)
{
if(OrderProfit()>0)
{
lot=OrderLots()*KLot;
}
if(OrderProfit()<=0)
{
lot=Lots;
}
}
}
}
if(lot>MaxLot || lot==0)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1) OpenPos();
}
//+------------------------------------------------------------------+
AM2