

//+------------------------------------------------------------------+
//| PTC.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 string Start1 = "10:50"; //
extern string End1 = "13:00"; //
extern string Start2 = "16:30"; //
extern string End2 = "18:40"; //
extern double Lots = 0.1; // лот
extern int StopLoss = 150; // лось
extern int TakeProfit = 150; // язь
extern int MAPeriod = 163; // MA период
extern int Slip = 30; // реквот
extern int Magic1 = 111; // магик
extern int Magic2 = 222; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| 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 magic)
{
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,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades(int magic)
{
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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double ma=iMA(NULL,0,MAPeriod,0,0,0,1);
if(t!=Time[0])
{
if(CountTrades(Magic1)<2 && TimeCurrent()>StringToTime(Start1) && TimeCurrent()<StringToTime(End1))
{
if(Open[3]>Close[3] && Open[2]<Close[2] && Open[1]<Close[1] && Ask>ma && Open[3]>ma)
{
PutOrder(0,Ask,Magic1);
}
if(Open[3]<Close[3] && Open[2]>Close[2] && Open[1]>Close[1] && Bid<ma && Open[3]<ma)
{
PutOrder(1,Bid,Magic1);
}
}
if(CountTrades(Magic2)<2 && TimeCurrent()>StringToTime(Start2) && TimeCurrent()<StringToTime(End2))
{
if(Open[3]>Close[3] && Open[2]<Close[2] && Open[1]<Close[1] && Ask>ma && Open[3]>ma)
{
PutOrder(0,Ask,Magic2);
}
if(Open[3]<Close[3] && Open[2]>Close[2] && Open[1]>Close[1] && Bid<ma && Open[3]<ma)
{
PutOrder(1,Bid,Magic2);
}
}
}
}
//+-----------------------------------------------------
почему то не хочет)))
//+------------------------------------------------------------------+
//| Contrast.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 double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 111; // лось
extern int TakeProfit = 111; // язь
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
extern string Expiration = "5"; // истечение ордера
extern string IndName = "##Contrast";
datetime t=0;
//+------------------------------------------------------------------+
//| 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),0,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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenPos()
{
double red1 = iCustom(NULL,0,IndName,0,Shift);
double gold1 = iCustom(NULL,0,IndName,1,Shift);
double red2 = iCustom(NULL,0,IndName,0,Shift+1);
double gold2 = iCustom(NULL,0,IndName,1,Shift+1);
if((gold1<red1 && gold2>red2 && (LastDealResult()==1 || LastDealResult()==0)) || (LastDealResult()==2 && LastDealType()==1))
{
PutOrder(0,Ask);
}
if((gold1>red1 && gold2<red2 && (LastDealResult()==1 || LastDealResult()==0)) || (LastDealResult()==2 && LastDealType()==2))
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealResult()
{
int result=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
return(result);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealType()
{
int type=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderType()==OP_BUY)
{
type=1;//buy
}
if(OrderType()==OP_SELL)
{
type=2;//sell
}
}
return(type);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double red = iCustom(NULL,0,IndName,0,Shift);
double gold = iCustom(NULL,0,IndName,1,Shift);
if(CountTrades()<1 && t!=Time[0])
{
OpenPos();
t=Time[0];
}
Comment("\n red: ",red,
"\n gold: ",gold);
}
//+------------------------------------------------------------------+
Странно, что тут не ограничения кол-ва ордеров. Н ареле такое кол-во не прокатит, средств не хватит для поддержания просадки элементарно.
//+------------------------------------------------------------------+
//| PTC.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 string Start1 = "10:50"; //
extern string End1 = "13:00"; //
extern string Start2 = "16:30"; //
extern string End2 = "18:40"; //
extern double Lots = 0.1; // лот
extern int StopLoss = 150; // лось
extern int TakeProfit = 150; // язь
extern int MAPeriod = 163; // MA период
extern int Slip = 30; // реквот
extern int Magic1 = 111; // магик
extern int Magic2 = 222; // магик
//+------------------------------------------------------------------+
//| 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 magic)
{
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,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades(int magic)
{
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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double ma=iMA(NULL,0,MAPeriod,0,0,0,1);
if(CountTrades(Magic1)<1 && TimeCurrent()>StringToTime(Start1) && TimeCurrent()<StringToTime(End1))
{
if(Open[3]>Close[3] && Open[2]<Close[2] && Open[1]<Close[1] && Ask>ma)
{
PutOrder(0,Ask,Magic1);
}
if(Open[3]<Close[3] && Open[2]>Close[2] && Open[1]>Close[1] && Bid<ma)
{
PutOrder(1,Bid,Magic1);
}
}
if(CountTrades(Magic2)<1 && TimeCurrent()>StringToTime(Start2) && TimeCurrent()<StringToTime(End2))
{
if(Open[3]>Close[3] && Open[2]<Close[2] && Open[1]<Close[1] && Ask>ma)
{
PutOrder(0,Ask,Magic2);
}
if(Open[3]<Close[3] && Open[2]>Close[2] && Open[1]>Close[1] && Bid<ma)
{
PutOrder(1,Bid,Magic2);
}
}
}
//+------------------------------------------------------------------+
А можно как то добавить чтоб советник открывал стоповые ордера?
Могу сделать только небольшую часть.
AM2