Если закрылась серия ордеров по общему тралу на продажу, следующий ордер открывается на покупку.
if((b && CountTrades()<1) || (CountTrades()<1 && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin) && BuySell==1) || (CountTrades()<=MaxTrades && otype==0 && (FindLastBuyPrice()-Ask)/Point>=Step))
{
PutOrder(0,Ask);
ModifyOrders();
}
А то этот только баит
if(IsTesting())
{
if(CountTrades()<1) PutOrder(0,Ask);
//if(CountTrades()<1) PutOrder(1,Bid);
}
Жаль что нет кнопки выражения благодарности киви кошелек.
Я против. Это в тестере так красиво выглядит, а на реале все будет очень плохо.
было бы очень неплохо
//+------------------------------------------------------------------+
//| Real.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
//--- Inputs
extern double Lots = 0.1; // лот
extern double Risk = 5; // риск
extern double StopLoss = 500; // лось
extern double TakeProfit = 500; // язь
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Slip = 30; // реквот
extern int CloseSig = 0; // 1-закрытие по сигналу
extern int Magic = 123; // магик
extern string IndName="Real Trend";
extern int SignalPeriod= 15;
extern int ArrowPeriod = 2;
//+------------------------------------------------------------------+
//| 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,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenPos()
{
double buy=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,2,Shift);
double sell=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,3,Shift);
//--- sell
if(sell>0)
{
PutOrder(1,Bid);
}
//--- buy conditions
if(buy>0)
{
PutOrder(0,Ask);
}
//---
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void ClosePos()
{
double buy=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,2,Shift);
double sell=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,3,Shift);
if(sell>0)
{
CloseAll(0);
}
if(buy>0)
{
CloseAll(1);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
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()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
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;
double lotstep=MarketInfo(Symbol(),MODE_LOTSTEP);
double MinLot=MarketInfo(Symbol(),MODE_MINLOT);
double MaxLot=MarketInfo(Symbol(),MODE_MAXLOT);
if(Lots==0) lot=AccountBalance()/100000*Risk;
lot=NormalizeDouble(lot/lotstep,0)*lotstep;
if(lot<MinLot) lot=MinLot;
if(lot>MaxLot) lot=MaxLot;
return(lot);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1) OpenPos();
if(CloseSig>0) ClosePos();
}
//+------------------------------------------------------------------+
AM2