extern int Expiration = 50; // время истечения ордера
extern int Back = 7; // за сколько свечей назад считаем минимальную свечку
//+------------------------------------------------------------------+
//| MinDay.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 1; // лот
extern int StopLoss = 500; // лось
extern int TakeProfit = 500; // язь
extern int BULevel = 300; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int Expiration = 50; // время истечения ордера
extern int Slip = 30; // реквот
extern int Delete = 1; // 1-удалять ордер. 0-нет
extern int Delta = 100; // размер свечи
extern int Back = 7; // за сколько свечей назад считаем минимальную свечку
extern int Magic = 123; // магик
extern string IndName="NR7";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BU()
{
bool m;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(OrderOpenPrice()<=Bid-BULevel*Point && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Green);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=Ask+BULevel*Point && OrderOpenPrice()<OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Green);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
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()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void PutOrder()
{
int r=0;
double sl=0,tp=0,pr=0;
//--- get Ind
double NR=iCustom(NULL,0,IndName,Back,0,1);
double Max = iHigh(NULL,PERIOD_D1,1);
double Min = iLow(NULL,PERIOD_D1,1);
if(Max-Min<=Delta*Point)
{
//--- sell
if(NR>0 && Bid>Min && CountOrders(5)<1)
{
if(StopLoss>0) sl=NormalizeDouble(Min+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Min-TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_SELLSTOP,Lots,NormalizeDouble(Min,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,Red);
return;
}
//--- buy
if(NR>0 && Bid<Max && CountOrders(4)<1)
{
if(StopLoss>0) sl=NormalizeDouble(Max-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Max+TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_BUYSTOP,Lots,NormalizeDouble(Max,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,Blue);
return;
}
}
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()==4 || OrderType()==5) del=OrderDelete(OrderTicket());
}
}
}
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()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Mode()
{
bool m;
double Max = iHigh(NULL,PERIOD_D1,1);
double Min = iLow(NULL,PERIOD_D1,1);
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(OrderStopLoss()!=Min && OrderStopLoss()<Min)
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),Min,OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderStopLoss()!=Max)
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),Max,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double NR=iCustom(NULL,0,IndName,Back,0,1);
double Max = iHigh(NULL,PERIOD_D1,1);
double Min = iLow(NULL,PERIOD_D1,1);
if(BULevel>0) BU();
if(StopLoss==0) Mode();
if(CountTrades()<1) PutOrder();
if(CountTrades()>0 && Delete==1) DelOrder();
Comment("\n NR: ",NR,
"\n Max: ",Max,
"\n Min: ",Min);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| MinDay.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 1; // лот
extern int StopLoss = 500; // лось
extern int TakeProfit = 500; // язь
extern int BULevel = 300; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int Expiration = 50; // истечение
extern int Slip = 30; // реквот
extern int Delete = 1; // 1-удалять ордер. 0-нет
extern int Delta = 100; // размер свечи
extern int Back = 7; // назад
extern int Magic = 123; // магик
extern string IndName="NR7";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BU()
{
bool m;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(OrderOpenPrice()<=Bid-BULevel*Point && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Green);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=Ask+BULevel*Point && OrderOpenPrice()<OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Green);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
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()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void PutOrder()
{
int r=0;
double sl=0,tp=0,pr=0;
//--- get Ind
double NR=iCustom(NULL,0,IndName,Back,0,1);
double Max = iHigh(NULL,PERIOD_D1,1);
double Min = iLow(NULL,PERIOD_D1,1);
if(Max-Min<=Delta*Point)
{
//--- sell
if(NR>0 && Bid>Min && CountOrders(5)<1)
{
if(StopLoss>0) sl=NormalizeDouble(Min+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Min-TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_SELLSTOP,Lots,NormalizeDouble(Min,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,Red);
return;
}
//--- buy
if(NR>0 && Bid<Max && CountOrders(4)<1)
{
if(StopLoss>0) sl=NormalizeDouble(Max-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Max+TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_BUYSTOP,Lots,NormalizeDouble(Max,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,Blue);
return;
}
}
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()==4 || OrderType()==5) del=OrderDelete(OrderTicket());
}
}
}
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()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double NR=iCustom(NULL,0,IndName,Back,0,1);
if(BULevel>0) BU();
if(CountTrades()<1) PutOrder();
if(CountTrades()>0 && Delete==1) DelOrder();
Comment("\n NR: ",NR);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| MinDay.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 1; // лот
extern int StopLoss = 500; // лось
extern int TakeProfit = 500; // язь
extern int Expiration = 50; // истечение
extern int Slip = 30; // реквот
extern int Back = 7; // назад
extern int Magic = 123; // магик
extern string IndName="NR7";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
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()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void PutOrder()
{
int r=0;
double sl=0,tp=0,pr=0;
//--- get Ind
double NR=iCustom(NULL,0,IndName,Back,0,1);
double Max = iHigh(NULL,PERIOD_D1,1);
double Min = iLow(NULL,PERIOD_D1,1);
//--- sell
if(NR>0 && Bid>Min && CountOrders(5)<1)
{
if(StopLoss>0) sl=NormalizeDouble(Min+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Min-TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_SELLSTOP,Lots,NormalizeDouble(Min,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,Red);
return;
}
//--- buy
if(NR>0 && Bid<Max && CountOrders(4)<1)
{
if(StopLoss>0) sl=NormalizeDouble(Max-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Max+TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_BUYSTOP,Lots,NormalizeDouble(Max,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,Blue);
return;
}
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()==4 || OrderType()==5) del=OrderDelete(OrderTicket());
}
}
}
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()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double NR=iCustom(NULL,0,IndName,Back,0,1);
if(CountTrades()<1) PutOrder();
if(CountTrades()>0) DelOrder();
Comment("\n NR: ",NR);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| NR7.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Green
//+------------------------------------------------------------------+
extern int Back=7;
//+------------------------------------------------------------------+
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,217);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
return(0);
}
//+------------------------------------------------------------------+
int start()
{
int i,j,pos;
for(i=Bars-IndicatorCounted()-1;i>=1;i--)
{
//if ((High[i]<High[i+1])&&(Low[i]>Low[i+1])){
pos=i;
for(j=i+1;j<i+Back;j++)
if((High[j]-Low[j])<(High[i]-Low[i]))
pos=j;
if(pos==i)
ExtMapBuffer1[i]=High[i]+(High[i]-Low[i])/3;
// }
}
return(0);
}
//+------------------------------------------------------------------+
P.S Как удалить задание?
Это понятно, просто я сам оптимизировать пока не умею вот и спрашиваю, с какими настройками у Вас получился такой график? Дайте скрин настроек пожалуйста, при которых получилась такая кривая баланса
Кривая на Вашем графике после оптимизации получилась с теми же настройками, что стоят по умолчанию в текущей версии советника, если не секрет?
Можно узнать, сейчас в базе та версия, с которой у Вас такая кривая получилась?
В приведенной вами цитате я объяснил почему скрин был другой. Скрин я заменил на соответствующий. Дополнительно прилагаю еще скриншоты.
extern int Shift = 1; // сдвиг
//+------------------------------------------------------------------+
//| Bandit.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, AM2"
#property link "http://www.forexsystems.biz"
#property description "Simple expert advisor"
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 500; // лось
extern int TakeProfit = 500; // язь
extern int TrailingStop = 300; // трал
extern int Slip = 30; // реквот
extern int Shift = 1; // сдвиг
extern int Magic = 123; // магик
extern string IndName1 = "++PANAH13-7";
extern string IndName2 = "++CLOSING";
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
int r=0;
double sl=0,tp=0;
//--- get Ind
double UP=iCustom(NULL,0,IndName1,0,1);
double DN=iCustom(NULL,0,IndName1,1,1);
double CloseUP=iCustom(NULL,0,IndName2,1,Shift);
double CloseDN=iCustom(NULL,0,IndName2,0,Shift);
//--- sell conditions
if(DN<100 && CloseUP<100)
{
if(StopLoss>0) sl=NormalizeDouble(Bid+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Bid-TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slip,sl,tp,"",Magic,0,Red);
return;
}
//--- buy conditions
if(UP<100 && CloseDN<100)
{
if(StopLoss>0) sl=NormalizeDouble(Ask-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Ask+TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slip,sl,tp,"",Magic,0,Blue);
return;
}
//---
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void ClosePos()
{
//--- get Ind
double CloseUP=iCustom(NULL,0,IndName2,1,1);
double CloseDN=iCustom(NULL,0,IndName2,0,1);
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic || OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(CloseDN<100)
{
bool c=OrderClose(OrderTicket(),OrderLots(),Bid,Slip,White);
}
break;
}
if(OrderType()==OP_SELL)
{
if(CloseUP<100)
{
c=OrderClose(OrderTicket(),OrderLots(),Ask,Slip,White);
}
break;
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>TrailingStop*Point)
{
if(OrderStopLoss()<Bid-TrailingStop*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
if(OrderType()==OP_SELL)
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
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()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
double UP=iCustom(NULL,0,IndName1,0,1);
double DN=iCustom(NULL,0,IndName1,1,1);
double CloseUP=iCustom(NULL,0,IndName2,1,2);
double CloseDN=iCustom(NULL,0,IndName2,0,2);
if(t!=Time[0])
{
if(CountTrades()<1) OpenPos();
else ClosePos();
t=Time[0];
}
if(TrailingStop>0) Trailing();
Comment("\n UP: ",UP,
"\n DN: ",DN,
"\n CloseUP: ",CloseUP,
"\n CloseDN: ",CloseDN);
//---
}
//+------------------------------------------------------------------+
Андрей и посмотри пожалуйста этот скрин… После желтого креста и потом появления белой стрелки, может открыться только одна сделка… скрин чуть выше…
//+------------------------------------------------------------------+
//| Bandit.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, AM2"
#property link "http://www.forexsystems.biz"
#property description "Simple expert advisor"
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 500; // лось
extern int TakeProfit = 500; // язь
extern int TrailingStop = 300; // трал
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
extern string IndName1 = "++PANAH13-7";
extern string IndName2 = "++CLOSING";
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
int r=0;
double sl=0,tp=0;
//--- get Ind
double UP=iCustom(NULL,0,IndName1,0,1);
double DN=iCustom(NULL,0,IndName1,1,1);
double CloseUP=iCustom(NULL,0,IndName2,1,1);
double CloseDN=iCustom(NULL,0,IndName2,0,1);
//--- sell conditions
if(DN<100 && CloseUP<100)
{
if(StopLoss>0) sl=NormalizeDouble(Bid+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Bid-TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slip,sl,tp,"",Magic,0,Red);
return;
}
//--- buy conditions
if(UP<100 && CloseDN<100)
{
if(StopLoss>0) sl=NormalizeDouble(Ask-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(Ask+TakeProfit*Point,Digits);
r=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slip,sl,tp,"",Magic,0,Blue);
return;
}
//---
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void ClosePos()
{
//--- get Ind
double CloseUP=iCustom(NULL,0,IndName2,1,1);
double CloseDN=iCustom(NULL,0,IndName2,0,1);
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic || OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(CloseDN<100)
{
bool c=OrderClose(OrderTicket(),OrderLots(),Bid,Slip,White);
}
break;
}
if(OrderType()==OP_SELL)
{
if(CloseUP<100)
{
c=OrderClose(OrderTicket(),OrderLots(),Ask,Slip,White);
}
break;
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>TrailingStop*Point)
{
if(OrderStopLoss()<Bid-TrailingStop*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
if(OrderType()==OP_SELL)
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
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()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
double UP=iCustom(NULL,0,IndName1,0,1);
double DN=iCustom(NULL,0,IndName1,1,1);
double CloseUP=iCustom(NULL,0,IndName2,1,1);
double CloseDN=iCustom(NULL,0,IndName2,0,1);
if(t!=Time[0])
{
if(CountTrades()<1) OpenPos();
else ClosePos();
t=Time[0];
}
if(TrailingStop>0) Trailing();
Comment("\n UP: ",UP,
"\n DN: ",DN,
"\n CloseUP: ",CloseUP,
"\n CloseDN: ",CloseDN);
//---
}
//+------------------------------------------------------------------+
Появилась белая стрелка ++PANAH13-7… снизу вверх-сигнал на buy на следующую свечу… появился желтый крестик ++CLOSING сделка должна закрыться…
AM2