www.opentraders.ru/downloads/1133/

А можно, ещё добавить в него функцию, чтобы противоположный ордер закрывался и открывалась новая пара не только тогда, когда сработает тейк профит, как сейчас, а и при срабатывании стоп лосс тоже?
//+------------------------------------------------------------------+
//| OpenOrders.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 int StopLoss = 500; // лось
extern int TakeProfit = 500; // язь
extern int Delta = 300; // расстояние от цены
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Last()
{
int result=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Last()==1 || Last()==2) DelOrder();
if(CountOrders(0)<1 && CountOrders(1)<1)
{
if(CountOrders(4)<1)PutOrder(4,Bid+Delta*Point);
if(CountOrders(5)<1)PutOrder(5,Bid-Delta*Point);
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| STS.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 Slip = 30; // реквот
extern int Shift = 1; // сдвиг
extern int Magic = 123; // магик
extern string IndName = "#STS_alert_mail_2008";
extern int MAMetod = 3;
extern int MAPeriod = 11;
bool b=true,s=true;
//+------------------------------------------------------------------+
//| 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 FBlue=iCustom(NULL,0,IndName,MAMetod,MAPeriod,4,Shift);
double FRed=iCustom(NULL,0,IndName,MAMetod,MAPeriod,5,Shift);
//--- sell conditions
if(FRed<1000 && s)
{
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);
if(LastDealResult()==1)
{
b=true;
s=false;
}
}
//--- buy conditions
if(FBlue<1000 && b)
{
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);
if(LastDealResult()==1)
{
b=false;
s=true;
}
}
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealResult()
{
int result=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 FBlue=iCustom(NULL,0,IndName,MAMetod,MAPeriod,4,Shift);
double FRed=iCustom(NULL,0,IndName,MAMetod,MAPeriod,5,Shift);
if(CountTrades()<1) OpenPos();
Comment("\n Blue: ",FBlue,
"\n Red: ",FRed);
//---
}
//+------------------------------------------------------------------+
Добрый день, Андрей.Спасибо за проделанную работу, но советник у меня не работает. Это легко проверить, установив на демо вилку на текущую цену из коротких стоп ордеров (близкие лоси и язи ) В журнале из 11 возможностей лишь один раз написал «open»
пропал коофицент умножения лота
лишние ордера по прежнему ложатся
еще нашел неисправность, если ставим закрывать по валюте депозита, то он закрывает только рабочие ордера, а лимитники так и продолжают висеть.
Не то…Чтобы получить советник за 1000$ нужно и поработать на тыщу баксов
//+------------------------------------------------------------------+
//| Lexus.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 = 1; // лот
extern int StopLoss = 70; // лось
extern int TakeProfit = 30; // язь
extern int TrailingStop = 20; // трал
extern int Delta = 30; // расстояние от цены
extern int Slip = 3; // реквот
extern int Magic = 123; // магик
extern string s="------------- Настройки BBands -------------";
extern int Length = 20; // период BB
extern double Deviation = 1; // отклонение ВВ
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
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(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((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Mode()
{
bool m;
double oop=0,sl=0,tp=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==4)
{
if(OrderOpenPrice()-Ask>Delta*Point)
{
oop=NormalizeDouble(Ask+Delta*Point,Digits);
if(StopLoss>0) sl=NormalizeDouble(oop-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(oop+TakeProfit*Point,Digits);
if(OrderOpenPrice()!=oop) m=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
}
}
if(OrderType()==5)
{
if(Ask-Delta*Point>OrderOpenPrice())
{
oop=NormalizeDouble(Ask-Delta*Point,Digits);
if(StopLoss>0) sl=NormalizeDouble(oop+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(oop-TakeProfit*Point,Digits);
if(OrderOpenPrice()!=oop) m=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Tomato);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double up=iBands(NULL,0,Length,Deviation,0,0,1,0);
double dn=iBands(NULL,0,Length,Deviation,0,0,2,0);
Mode();
if(CountTrades()<1 && (Bid>up || Bid<dn))
{
if(CountOrders(4)<1) PutOrder(4,Bid+Delta*Point);
if(CountOrders(5)<1) PutOrder(5,Bid-Delta*Point);
}
if(TrailingStop>0) Trailing();
Comment("\n ");
}
//+------------------------------------------------------------------+
• jbrix_factor — 1.0; может принимать значения от 1.0 до 2.0. (например, 1.2, 1.5… и так далее).
AM2