Андрей, при получении прибыли в размере 10 советник не закрыл убыточный, как было 3 buy так и остались
По скринам видно что не было прибыли в 10 баксов, поэтому и не закрыл.
Андрей, при получении прибыли в размере 10 советник не закрыл убыточный, как было 3 buy так и остались
//+------------------------------------------------------------------+
//| LossClose.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
input double Profit=10;
double LastEquity=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
if(type==1 || type==3 || type==5)
{
clr=Red;
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(NULL,type,0.1,NormalizeDouble(price,Digits),5,0,0,"",0,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseLastMinus()
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==0)
{
if(OrderProfit()<0) cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),5,White);
break;
}
if(OrderType()==1)
{
if(OrderProfit()<0) cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),5,White);
break;
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(IsTesting() && OrdersTotal()<1)
{
for(int i=1;i<=5;i++) PutOrder(2,Ask-200*Point*i);
for(int i=1;i<=3;i++) PutOrder(5,Ask-150*Point*i);
}
if(AccountEquity()-LastEquity>Profit)
{
CloseLastMinus();
LastEquity=AccountEquity();
}
Comment("\n Profit: ",AllProfit(),
"\n Account Equity: ",AccountEquity(),
"\n Last Equity: ",LastEquity);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Levels.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
input double Level1 = 1.0755;
input double Level2 = 1.0745;
input double Level3 = 1.0735;
extern double Lots = 0.1; // лот
extern int StopLoss = 200; // лось
extern int TakeProfit = 300; // язь
extern int Delta = 30; // дельта
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
bool l1=true,l2=true,l3=true;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Bid<Level1+Delta*Point && Bid>Level1-Delta*Point && l1)
{
PutOrder(4,Bid+Delta*Point);
PutOrder(5,Bid-Delta*Point);
l1=false;
}
if(Bid<Level2+Delta*Point && Bid>Level2-Delta*Point && l2)
{
PutOrder(4,Bid+Delta*Point);
PutOrder(5,Bid-Delta*Point);
l2=false;
}
if(Bid<Level3+Delta*Point && Bid>Level3-Delta*Point && l3)
{
PutOrder(4,Bid+Delta*Point);
PutOrder(5,Bid-Delta*Point);
l3=false;
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Zigi.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutTrend(string name,datetime time1,double price1,datetime time2,double price2)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price2);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,Blue);
//--- установим стиль отображения линии
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,2);
//--- включим (true) или отключим (false) режим продолжения отображения линии вправо
ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double ZZPrice(int ne=0)
{
double zz;
int i,k=iBars(NULL,0),ke=0;
for(i=1; i<k; i++)
{
zz=iCustom(NULL,0,"ZigZag",12,5,3,0,i);
if(zz!=0)
{
ke++;
if(ke>ne) return(zz);
}
}
Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int ZZBar(int ne=0)
{
double zz;
int i,k=iBars(NULL,0),ke=0;
for(i=0; i<k; i++)
{
zz=iCustom(NULL,0,"ZigZag",12,5,3,0,i);
if(zz!=0)
{
ke++;
if(ke>ne) return(i);
}
}
Print("GetExtremumZZBar(): Экстремум ЗигЗага номер ",ne," не найден");
return(-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[])
{
//---
PutTrend((string)time[0],time[ZZBar(0)],ZZPrice(0),time[ZZBar(1)],ZZPrice(1));
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
В советнике есть контроль по символу. В ТЗ не было указано что позы будут по разным символам.
AM2