Прогнал по истории по всем тикам, нет ошибок. В таком случае приводите скрин ошибки и когда она возникает, так же и с МА. Раздельные уровни добавил:
www.opentraders.ru/downloads/1365/
1) фильтр по машкам работает наоборот — нужно если быстрая над медленной, то ордер может быть только бай, и наоборот, для селл (просто поменять машки в настройках местами проблему не решает), фильтр по машкам — трендовый фильтр
А есть возможность чтобы стрелки оставались на графике?
ObjectDelete(0,name);
//ObjectDelete(0,name);
//+------------------------------------------------------------------+
//| DeltaMA.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
#property indicator_chart_window
input int MAPeriod = 20;
input int MAMethod = 3;
input int Shift = 10;
input int Delta = 35;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutArrow(string name,int code,double p,datetime time,color clr)
{
//--- создадим стрелку
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_ARROW,0,time,p);
//--- установим код стрелки
ObjectSetInteger(0,name,OBJPROP_ARROWCODE,code);
//--- установим способ привязки
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_CENTER);
//--- установим цвет стрелки
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- установим размер стрелки
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
double ma11=iMA(NULL,0,MAPeriod,0,MAMethod,3,1);
double ma12=iMA(NULL,0,MAPeriod,0,MAMethod,3,1+Shift);
double ma21=iMA(NULL,0,MAPeriod,0,MAMethod,2,1);
double ma22=iMA(NULL,0,MAPeriod,0,MAMethod,2,1+Shift);
Comment("\n ma11: ",NormalizeDouble(ma11,Digits),
"\n ma12: ",NormalizeDouble(ma12,Digits),
"\n ma21: ",NormalizeDouble(ma11,Digits),
"\n ma22: ",NormalizeDouble(ma22,Digits),
"\n ma12-ma11: ",NormalizeDouble(MathAbs(ma12-ma11)/Point,0),
"\n ma22-ma21: ",NormalizeDouble(MathAbs(ma22-ma21)/Point,0),
"\n dma: ",NormalizeDouble(MathAbs(ma22-ma21)/Point-MathAbs(ma12-ma11)/Point,0));
double dma=NormalizeDouble(MathAbs(ma22-ma21)/Point-MathAbs(ma12-ma11)/Point,0);
if(dma>0 && MathAbs(dma)>Delta) PutArrow("Arrow",233,low[1],time[1],Red);
if(dma<0 && MathAbs(dma)>Delta) PutArrow("Arrow",234,high[1],time[1],Blue);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Pattern.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, AM2"
#property link "http://www.forexsystems.biz"
extern int StopLoss = 300; // лось
extern int TakeProfit = 600; // язь
extern int Slip = 50; // реквот
extern int MAPeriod = 9; // период МА
extern int MAMethod = 0; // метод МА
extern bool Trend = true; // фильтр МА
extern int Magic = 123; // магик
extern double Lots = 0.1; // торговый объем
datetime t=0;
//+------------------------------------------------------------------+
//| Установка ордера |
//+------------------------------------------------------------------+
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,Lots,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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool Star()
{
if(Close[4]>Open[4] && Open[4]-Low[4]<Close[4]-Open[4] && (High[4]-Close[4])/(Close[4]-Open[4])>2 && High[4]>High[3] && High[4]>High[2] && High[4]>High[1] && High[4]>High[5] && High[4]>High[6] && High[4]>High[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool Hanged()
{
if(Close[4]>Open[4] && Open[4]-Close[4]<Open[4]-Low[4] && (Open[4]-Low[4])/(Close[4]-Open[4])>2 && High[4]>High[3] && High[4]>High[2] && High[4]>High[1] && High[4]>High[5] && High[4]>High[6] && High[4]>High[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool Hammer()
{
if(Close[4]<Open[4] && High[4]-Open[4]<Open[4]-Close[4] && (Close[4]-Low[4])/(Open[4]-Close[4])>2 && Low[4]<Low[3] && Low[4]<Low[2] && Low[4]<Low[1] && Low[4]<Low[5] && Low[4]<Low[6] && Low[4]<Low[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
bool InvertHammer()
{
if(Close[4]<Open[4] && High[4]-Open[4]>Open[4]-Close[4] && (High[4]-Open[4])/(Open[4]-Close[4])>2 && Low[4]<Low[3] && Low[4]<Low[2] && Low[4]<Low[1] && Low[4]<Low[5] && Low[4]<Low[6] && Low[4]<Low[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool MorningStar()
{
if(Close[4]>Open[4] && Close[3]>Open[3] && Close[5]<Open[4] && (Open[5]-Close[5])/(Close[4]-Open[4])>3 && (Close[3]-Open[3])/(Close[4]-Open[4])>3 && Low[4]<Low[3] && Low[4]<Low[2] && Low[4]<Low[1] && Low[4]<Low[5] && Low[4]<Low[6] && Low[4]<Low[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool EverningStar()
{
if(Close[4]<Open[4] && Close[3]<Open[3] && Close[5]>Open[4] && (Close[5]-Open[5])/(Open[4]-Close[4])>3 && (Open[3]-Close[3])/(Close[4]-Open[4])>3 && High[4]>High[3] && High[4]>High[2] && High[4]>High[1] && High[4]>High[5] && High[4]>High[6] && High[4]>High[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void OnTick()
{
double ma=iMA(NULL,0,MAPeriod,0,MAMethod,0,0);
bool buy = (Hammer() || InvertHammer() || MorningStar()) && Bid>ma;
bool sell = (Star() || Hanged() || EverningStar()) && Bid<ma;
if(!Trend)
{
buy = (Hammer() || InvertHammer() || MorningStar());
sell = (Star() || Hanged() || EverningStar());
}
if(CountTrades()<1 && t!=Time[0])
{
//---- buy
if(buy)
{
PutOrder(0,Ask);
}
//---- sell
if(sell)
{
PutOrder(1,Bid);
}
t=Time[0];
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| RenkoLimit.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 = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 555; // лось
extern int TakeProfit = 555; // язь
extern int Delta = 0; // расстояние от открытия свечи
extern int Slip = 3; // реквот
extern int Closing = 1; // 1-закрытие на новой свече 2-закрытие половины лота
extern int Magic = 123; // магик
datetime t=0;
int CloseCount=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),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(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
}
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll()
{
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()==OP_BUY)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePol()
{
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()==OP_BUY)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots()/2,NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots()/2,NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
}
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenOrd()
{
DelOrder();
if(Close[1]>Open[1])
{
PutOrder(2,Open[1]-Delta*Point);
}
if(Close[1]<Open[1])
{
PutOrder(3,Open[1]+Delta*Point);
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CloseCount>0 && CountTrades()>0 && t!=Time[0])
{
CloseAll();
CloseCount=0;
t=Time[0];
}
if(CountTrades()<1 && t!=Time[0])
{
OpenOrd();
t=Time[0];
}
if(CountTrades()>0 && t!=Time[0])
{
if(Closing==1) CloseAll();
if(Closing==2)
{
ClosePol();
CloseCount++;
}
t=Time[0];
}
Comment("\n CloseCount: ",CloseCount);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Platinum.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 = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 555; // лось
extern int TakeProfit = 555; // язь
extern int LossPoint = 250; // расстояние от экстремума
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int CloseSig = 1; // 1-закрытие по сигналу
extern int Magic = 123; // магик
extern string IndName = "PLATINUM";
extern int Risk = 3;
extern double ArrowsGap = 1;
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); else sl=NormalizeDouble(High[1]+LossPoint*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); else sl=NormalizeDouble(Low[1]-LossPoint*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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double buy = iCustom(NULL,0,IndName,Risk,ArrowsGap,1,Shift);
double sell = iCustom(NULL,0,IndName,Risk,ArrowsGap,0,Shift);
//---
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)
{
if(sell<1000)
{
CloseAll();
}
}
if(OrderType()==OP_SELL)
{
if(buy<1000)
{
CloseAll();
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll()
{
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()==OP_BUY)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenPos()
{
double buy = iCustom(NULL,0,IndName,Risk,ArrowsGap,1,Shift);
double sell = iCustom(NULL,0,IndName,Risk,ArrowsGap,0,Shift);
if(buy<1000)
{
PutOrder(0,Ask);
}
if(sell<1000)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double buy = iCustom(NULL,0,IndName,Risk,ArrowsGap,1,Shift);
double sell = iCustom(NULL,0,IndName,Risk,ArrowsGap,0,Shift);
if(t!=Time[0])
{
if(CountTrades()<1) OpenPos();
if(CloseSig>0) ClosePos();
t=Time[0];
}
Comment("\n Buy: ",buy,"\n Sell: ",sell);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Pattern.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, AM2"
#property link "http://www.forexsystems.biz"
extern int StopLoss = 300; // лось
extern int TakeProfit = 600; // язь
extern int Slip = 50; // реквот
extern int MAPeriod = 9; // период МА
extern int MAMethod = 0; // метод МА
extern int Magic = 123; // магик
extern double Lots = 0.1; // торговый объем
datetime t=0;
//+------------------------------------------------------------------+
//| Установка ордера |
//+------------------------------------------------------------------+
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,Lots,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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool Star()
{
if(Close[4]>Open[4] && Open[4]-Low[4]<Close[4]-Open[4] && (High[4]-Close[4])/(Close[4]-Open[4])>2 && High[4]>High[3] && High[4]>High[2] && High[4]>High[1] && High[4]>High[5] && High[4]>High[6] && High[4]>High[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool Hanged()
{
if(Close[4]>Open[4] && Open[4]-Close[4]<Open[4]-Low[4] && (Open[4]-Low[4])/(Close[4]-Open[4])>2 && High[4]>High[3] && High[4]>High[2] && High[4]>High[1] && High[4]>High[5] && High[4]>High[6] && High[4]>High[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool Hammer()
{
if(Close[4]<Open[4] && High[4]-Open[4]<Open[4]-Close[4] && (Close[4]-Low[4])/(Open[4]-Close[4])>2 && Low[4]<Low[3] && Low[4]<Low[2] && Low[4]<Low[1] && Low[4]<Low[5] && Low[4]<Low[6] && Low[4]<Low[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
bool InvertHammer()
{
if(Close[4]<Open[4] && High[4]-Open[4]>Open[4]-Close[4] && (High[4]-Open[4])/(Open[4]-Close[4])>2 && Low[4]<Low[3] && Low[4]<Low[2] && Low[4]<Low[1] && Low[4]<Low[5] && Low[4]<Low[6] && Low[4]<Low[7]) return(true);
else return(false);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void OnTick()
{
double ma=iMA(NULL,0,MAPeriod,0,MAMethod,0,0);
if(CountTrades()<1 && t!=Time[0])
{
//---- buy
if((Hammer() || InvertHammer()) && Bid>ma)
{
PutOrder(0,Ask);
}
//---- sell
if((Hammer() || Hanged()) && Bid<ma)
{
PutOrder(1,Bid);
}
t=Time[0];
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| RenkoLimit.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 = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 555; // лось
extern int TakeProfit = 555; // язь
extern int Delta = 0; // расстояние от открытия свечи
extern int Slip = 3; // реквот
extern int Closing = 1; // 1-закрытие на новой свече 2-закрытие половины лота
extern int Magic = 123; // магик
datetime t=0;
int CloseCount=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),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(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
}
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll()
{
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()==OP_BUY)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePol()
{
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()==OP_BUY)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots()/2,NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots()/2,NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
}
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenOrd()
{
DelOrder();
if(Close[1]>Open[1])
{
PutOrder(2,Open[1]-Delta*Point);
}
if(Close[1]<Open[1])
{
PutOrder(3,Open[1]+Delta*Point);
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1 && t!=Time[0])
{
OpenOrd();
t=Time[0];
}
if(CountTrades()>0 && t!=Time[0])
{
if(Closing==1) CloseAll();
if(Closing==2)
{
ClosePol();
CloseCount++;
}
t=Time[0];
}
if(CloseCount==1 && CountTrades()>0 && t!=Time[0])
{
CloseAll();
CloseCount=0;
t=Time[0];
}
Comment("\n CloseCount: ",CloseCount);
}
//+------------------------------------------------------------------+
у меня 1384
AM2