предварительная версия в базе: www.opentraders.ru/downloads/505/

//--- Inputs
extern int StopLoss = 200; // стоп лосс ордера
extern int TakeProfit = 200; // тейк профит ордера
extern int BUF = 0; // включение вывода в БУ(0-Выкл.,1-Вкл.)
extern int BULevel = 10; // Уровень безубытка
extern int BUProfit = 100; // Уровень профита
extern int MM = 0; // включение расчета объема позиции(0-Выкл.,постоянный лот;1-Вкл.)
extern double Lots = 0.1; // объем позиции
extern double Risk = 10; // риск в процентах от депо
extern int MAGIC = 2014; // магик
if(zz1>zz3 && zz1<zz2 && zz1<zz4 && zz5<=zz3 && b<1 && (LastDealResult()==0 || LastDealResult()==2))
zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);
//+------------------------------------------------------------------+
//| WW.mq4 |
//| Copyright © 2014, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, AM2"
#property link "http://www.forexsystems.biz"
#define MAGIC 20141115
extern int StopLoss = 450;
extern int TakeProfit = 800;
extern int ExtDepth = 10;
extern int ExtDeviation = 5;
extern int ExtBackstep = 3;
extern double Lots = 0.1;
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double zz1,zz2,zz3,zz4,zz5;
int res,b,s;
//---- get Extremum ZigZag Price
zz1=GetExtremumZZPrice(NULL,0,4,ExtDepth,ExtDeviation,ExtBackstep);
zz2=GetExtremumZZPrice(NULL,0,3,ExtDepth,ExtDeviation,ExtBackstep);
zz3=GetExtremumZZPrice(NULL,0,2,ExtDepth,ExtDeviation,ExtBackstep);
zz4=GetExtremumZZPrice(NULL,0,1,ExtDepth,ExtDeviation,ExtBackstep);
zz5=GetExtremumZZPrice(NULL,0,0,ExtDepth,ExtDeviation,ExtBackstep);
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
{
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
{
if(OrderType()==OP_BUY) b++;
if(OrderType()==OP_SELL) s++;
}
}
}
Comment("\n","ZZ1 = ",zz1,"\n",
"ZZ2 = ",zz2,"\n",
"ZZ3 = ",zz3,"\n",
"ZZ4 = ",zz4,"\n",
"ZZ5 = ",zz5,"\n");
//---- buy conditions
if(zz1>zz3 && zz1<zz2 && zz1<zz4 && zz5<=zz3 && b<1 && (LastDealResult()==0 || LastDealResult()==2))
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,fND(Ask-StopLoss*Point),fND(Ask+TakeProfit*Point),"",MAGIC,0,Blue);
if(res<0)
{
Print("Order Buy error: ",GetLastError());
}
else
Print("OK Order Buy");
return;
}
//---- sell conditions
if(zz1<zz3 && zz1>zz2 && zz1>zz4 && zz5>=zz3 && s<1 && (LastDealResult()==0 || LastDealResult()==1))
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,fND(Bid+StopLoss*Point),fND(Bid-TakeProfit*Point),"",MAGIC,0,Red);
if(res<0)
{
Print("Order Sell error: ",GetLastError());
}
else
Print("OK Order Sell");
return;
}
//----
}
//+------------------------------------------------------------------+
double fND(double d, int n=-1)
{
if (n<0) return(NormalizeDouble(d, Digits));
return(NormalizeDouble(d, n));
}
//+------------------------------------------------------------------+
bool NewBar()
{
static datetime lastbar = 0;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else
{
return(false);
}
}
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
double GetExtremumZZPrice(string sy="", int tf=0, int ne=0, int dp=12, int dv=5, int bs=3) {
if (sy=="" || sy=="0") sy=Symbol();
double zz;
int i, k=iBars(sy, tf), ke=0;
for (i=1; i<k; i++) {
zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);
if (zz!=0) {
ke++;
if (ke>ne) return(zz);
}
}
Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
return(0);
}
//+----------------------------------------------------------------------------+
int LastDealResult()
{
int result;
if(OrderSelect(OrdersHistoryTotal(), MODE_HISTORY)==true)
{
if(OrderType()==OP_BUY) result=1;
if(OrderType()==OP_SELL) result=2;
}
else
{
result=0;
}
return(result);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//--- go trading only for first tiks of new bar
if(NewBar()==true)
{
CheckForOpen();
}
//----
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Renko.mq4 |
//| Copyright © 2014, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, AM2"
#property link "http://www.forexsystems.biz"
#property description "indalekseifx Directional Line expert advisor"
//--- Inputs
extern double StopLoss = 2000; // стоп лосс ордера
extern double TakeProfit = 2000; // тейк профит ордера
extern double Lots = 0.1; // объем позиции
//----
extern int Amplitude = 2; // период средней indalekseifx Directional Line
extern int shift = 2; // смещение средней
//----
extern int FastPeriod = 12; // период быстрого макди
extern int SlowPeriod = 26; // период медленного макди
extern int SignalPeriod = 9; // период сигнального макди
//----
extern int MACDAC = 0; // включение макди(1-включен,0-отключен)
extern int MAGIC = 2014; // магик
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
int res,b,s;
//--- get Moving Average
double indalekseifxDeepSkyBlue=iCustom(Symbol(),0,"indalekseifx",Amplitude,1,1);
double indalekseifxTomato=iCustom(Symbol(),0,"indalekseifx",Amplitude,0,1);
double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
{
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
{
if(OrderType()==OP_BUY) b++;
if(OrderType()==OP_SELL) s++;
}
}
}
//--- sell conditions
if(MACDAC==1)
{
if(indalekseifxDeepSkyBlue>indalekseifxTomato && MACDGreen<MACDRed && s<1 && (LastDealResult()==0 || LastDealResult()==1))
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,fND(Bid+StopLoss*Point),fND(Bid-TakeProfit*Point),"",MAGIC,0,Tomato);
if(res<0)
{
Print("Order Sell error: ",GetLastError());
}
else
Print("OK Order Sell");
return;
}
//--- buy conditions
if(indalekseifxTomato>indalekseifxDeepSkyBlue && MACDGreen>MACDRed && b<1 && (LastDealResult()==0 || LastDealResult()==2))
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,fND(Ask-StopLoss*Point),fND(Ask+TakeProfit*Point),"",MAGIC,0,DeepSkyBlue);
if(res<0)
{
Print("Order Buy error: ",GetLastError());
}
else
Print("OK Order Buy");
return;
}
}
else
{
if(indalekseifxDeepSkyBlue>indalekseifxTomato && s<1 && (LastDealResult()==0 || LastDealResult()==1))
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Tomato);
if(res<0)
{
Print("Order Sell error: ",GetLastError());
}
else
Print("OK Order Sell");
return;
}
//--- buy conditions
if(indalekseifxTomato>indalekseifxDeepSkyBlue && b<1 && (LastDealResult()==0 || LastDealResult()==2))
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,fND(Ask-StopLoss*Point),fND(Ask+TakeProfit*Point),"",MAGIC,0,DeepSkyBlue);
if(res<0)
{
Print("Order Buy error: ",GetLastError());
}
else
Print("OK Order Buy");
return;
}
}
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
//--- get Moving Average
double indalekseifxDeepSkyBlue=iCustom(Symbol(),0,"indalekseifx",Amplitude,1,shift);
double indalekseifxTomato=iCustom(Symbol(),0,"indalekseifx",Amplitude,0,shift);
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
//--- check order type
if(OrderType()==OP_BUY)
{
if(indalekseifxDeepSkyBlue>indalekseifxTomato)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(indalekseifxTomato>indalekseifxDeepSkyBlue)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
//---
}
//+------------------------------------------------------------------+
bool NewBar()
{
static datetime lastbar = 0;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else
{
return(false);
}
}
//+------------------------------------------------------------------+
int LastDealResult()
{
int result;
if(OrderSelect(OrdersHistoryTotal(), MODE_HISTORY)==true)
{
if(OrderType()==OP_BUY) result=1;
if(OrderType()==OP_SELL) result=2;
}
else
{
result=0;
}
return(result);
}
//+------------------------------------------------------------------+
double fND(double d, int n=-1)
{
if (n<0) return(NormalizeDouble(d, Digits));
return(NormalizeDouble(d, n));
}
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for history and trading
if(Bars<100 || IsTradeAllowed()==false)
return;
//--- go trading only for first tiks of new bar
if(NewBar()==true)
{
Print("New Bar");
CheckForOpen();
CheckForClose();
}
Comment("\nResult of last deal: ", LastDealResult());
//---
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Renko.mq4 |
//| Copyright © 2014, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, AM2"
#property link "http://www.forexsystems.biz"
#property description "Slope Directional Line expert advisor"
//--- Inputs
extern double StopLoss = 500; // стоп лосс ордера
extern double TakeProfit = 500; // тейк профит ордера
extern double Lots = 0.1; // объем позиции
//----
extern int period = 90; // период средней Slope Directional Line
extern int method = 2; // метод средней(SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int price = 0; // цена по которой строится средняя
extern int shift = 3; // смещение средней
//----
extern int FastPeriod = 12; // период быстрого макди
extern int SlowPeriod = 26; // период медленного макди
extern int SignalPeriod = 9; // период сигнального макди
//----
extern int MACDAC = 1; // включение макди(1-включен,0-отключен)
extern int MAGIC = 333; // магик
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
int res,b,s;
bool sp=true,bp=true;
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
{
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
{
if(OrderType()==OP_BUY) b++;sp=false;
if(OrderType()==OP_SELL) s++;bp=false;
}
}
}
//--- sell conditions
if(MACDAC==1)
{
if(SlopeBlue>SlopeRed && MACDGreen<MACDRed && s<1 && (LastDealResult()==0 || LastDealResult()==1))
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);
return;
}
//--- buy conditions
if(SlopeRed>SlopeBlue && MACDGreen>MACDRed && b<1 && (LastDealResult()==0 ||LastDealResult()==2))
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);
return;
}
}
else
{
if(SlopeBlue>SlopeRed && s<1&& (LastDealResult()==0 || LastDealResult()==1))
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);
return;
}
//--- buy conditions
if(SlopeRed>SlopeBlue && b<1 && (LastDealResult()==0 ||LastDealResult()==2))
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);
return;
}
}
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,shift);
double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,shift);
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
//--- check order type
if(OrderType()==OP_BUY)
{
if(SlopeBlue>SlopeRed)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(SlopeRed>SlopeBlue)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
//---
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for history and trading
if(Bars<100 || IsTradeAllowed()==false)
return;
//--- calculate open orders by current symbol
CheckForOpen();
CheckForClose();
Comment("\nResult of last deal: ", LastDealResult());
//---
}
//+------------------------------------------------------------------+
int LastDealResult()
{
int result;
if(OrderSelect(OrdersHistoryTotal(), MODE_HISTORY)==true)
{
if(OrderType()==OP_BUY) result=1;
if(OrderType()==OP_SELL) result=2;
}
else
{
Print("No deals in history");
result=0;
}
return(result);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Renko.mq4 |
//| Copyright © 2014, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, AM2"
#property link "http://www.forexsystems.biz"
#property description "Slope Directional Line expert advisor"
//--- Inputs
extern double StopLoss = 500; // стоп лосс ордера
extern double TakeProfit = 500; // тейк профит ордера
extern double Lots = 0.1; // объем позиции
//----
extern int period = 90; // период средней Slope Directional Line
extern int method = 2; // метод средней(SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int price = 0; // цена по которой строится средняя
//----
extern int FastPeriod = 12; // период быстрого макди
extern int SlowPeriod = 26; // период медленного макди
extern int SignalPeriod = 9; // период сигнального макди
//----
extern int MACDAC = 1; // включение макди(1-включен,0-отключен)
extern int MAGIC = 2014;// магик
bool buy=true,sell=true;
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
int res;
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);
//--- sell conditions
if(MACDAC==1)
{
if(SlopeBlue>SlopeRed && MACDGreen<MACDRed && sell==true)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);
sell=false;
buy=true;
return;
}
//--- buy conditions
if(SlopeRed>SlopeBlue && MACDGreen>MACDRed && buy==true)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);
buy=false;
sell=true;
return;
}
}
else
{
if(SlopeBlue>SlopeRed && sell==true)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);
sell=false;
buy=true;
return;
}
//--- buy conditions
if(SlopeRed>SlopeBlue && buy==true)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);
buy=false;
sell=true;
return;
}
}
//---
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
//--- check order type
if(OrderType()==OP_BUY)
{
if(SlopeBlue>SlopeRed)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(SlopeRed>SlopeBlue)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
//---
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for history and trading
if(Bars<100 || IsTradeAllowed()==false)
return;
//--- calculate open orders by current symbol
if(OrdersTotal()<1) CheckForOpen();
else CheckForClose();
//---
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Renko.mq4 |
//| Copyright © 2014, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, AM2"
#property link "http://www.forexsystems.biz"
#property description "Slope Directional Line expert advisor"
#define MAGICMA 20141111
//--- Inputs
extern double StopLoss = 500; // стоп лосс ордера
extern double TakeProfit = 500; // тейк профит ордера
extern double Lots = 0.1; // объем позиции
//----
extern int period = 90; // период средней Slope Directional Line
extern int method = 2; // метод средней(SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int price = 0; // цена по которой строится средняя
//----
extern int FastPeriod = 12; // период быстрого макди
extern int SlowPeriod = 26; // период медленного макди
extern int SignalPeriod = 9; // период сигнального макди
//----
extern int MACDAC = 1; // включение макди(1-включен,0-отключен)
bool buy=true,sell=true;
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
int res;
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);
//--- sell conditions
if(MACDAC==1)
{
if(SlopeBlue>SlopeRed && MACDGreen<MACDRed && sell==true)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
sell=false;
buy=true;
return;
}
//--- buy conditions
if(SlopeRed>SlopeBlue && MACDGreen>MACDRed && buy==true)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);
buy=false;
sell=true;
return;
}
}
else
{
if(SlopeBlue>SlopeRed && sell==true)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
sell=false;
buy=true;
return;
}
//--- buy conditions
if(SlopeRed>SlopeBlue && buy==true)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);
buy=false;
sell=true;
return;
}
}
//---
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//--- check order type
if(OrderType()==OP_BUY)
{
if(SlopeBlue>SlopeRed)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(SlopeRed>SlopeBlue)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
//---
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for history and trading
if(Bars<100 || IsTradeAllowed()==false)
return;
//--- calculate open orders by current symbol
if(OrdersTotal()<1) CheckForOpen();
else CheckForClose();
//---
}
//+------------------------------------------------------------------+
AM2