ROBOTRADING - Форум по автоматизированной и ручной торговле на финансовых рынках.

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.



e-Stomper_EURGBP_m15

Сообщений 1 страница 2 из 2

1

Код:
//+------------------------------------------------------------------+
//|                                                      Stomper.mq4 |
//|                              Copyright © 2008, BJF Trading Group |
//|                                          http://iticsoftware.com |
//+------------------------------------------------------------------+
#define OP_CLOSEBY   96
#define OP_MODIFY    97
#define OP_CLOSE     98
#define OP_NONE      99
#define OH1          0
#define CH1          1
#define OH2          2
#define CH2          3

 
extern string OrderOptions=    "--------   Orders options  --------";
extern double Lots = 0.1;
extern int    LotsPercent = 20;
int    MaxDrawDown = 30;
extern bool   UseAutosettings = true;
extern int    TakeProfit = 24;
extern bool   TryTakeProfit = true;
extern int    StopLoss = 34;
extern bool   CheckFreezLevel = true;
int    TrailingStop = 50;
extern int    MinProfitValue = 8;
extern string TradeOptions=    "--------   Trade  options  --------";
extern int    ChannelBars = 4;
extern int    SellCorrection = 0;
extern int    BuyCorrection = 0;
extern bool   CheckTimeBar = false;
extern bool   EqualBars = true;

string TransmiteOptions="--------Transmite options--------";
bool   TradeTransferIn=false;
bool   TradeTransferOut=false;
bool   CheckDeleteFile=false;
int    TimeOutDeleteFile=10;
bool   CheckSetOrder=true;
int    TimeOutSetOrder=10;
bool   DeleteFileAfterChecking=false;
int    NumberRepeatCloseOrder = 0;

extern string TimeOptions=     "--------   Time   options  --------";
extern bool   EachDayHourSettings=false;
extern int    TradeTimeChoise = 1;
extern int    TradeDayOfWeek=0;
extern int    OpenHour1=0;
extern int    CloseHour1=8;
extern int    OpenHour2=20;
extern int    CloseHour2=24;

string OtherOptions=    "--------   Other  options  --------";
int    PersonalMagicNumber=642;
bool   ShowComment=true;
bool   ShowSettings=true;
int    TimeOutComment=3;
bool   ShowPrint=true;
bool   ShowTime=true;
bool   ShowNameID=false;
bool   ShowMagicNumber=false;


int    BarSlippage=2;
int    BBPeriod=20;
int    BBShift=0;
double BBDeviations=2.5;
int    BBChannelValue = 50;
bool   ReversTrades = false;
bool   LackTrades = false;
bool   OneTradesToDirection = true;
bool   HideIndicators = false;
//


int    Slippage;
int    MagicNumber=8888881;
string NameID="Stomper", InitString;
double LotsForTrade;
double HighestBarsValue, LowestBarsValue;
color  ReversOrderColor = Black;
color  BuyOrderColor = Blue;
color  SellOrderColor = Red;
int    LastOrderBar, LastOrderTicket, CurrentOrderTicket, CurrentOrderProfitPoint, CurrentOrderTrailingStop;
bool   TradeLimit;
int    opposite_id = 1;
double LastOrderTime=0;
double CurrentOrderProfit;
double BuyOrderPrice;
bool   GoSell=false, GoBuy=false;
double MaxProfit=0, MaxLoss=0;
double UPmaxProfit=0, UPmaxLoss=0;
double UPminProfit=50, UPminLoss=50;
double DOWNmaxProfit=0,DOWNmaxLoss=0;
double DOWNminProfit=50, DOWNminLoss=50;
int    ReadOperationCounter, SaveOperationCounter;
int    CurrentDirection=OP_NONE, LastDirection=OP_NONE, CurrentMode=1,FileCounterMaxValue=10, CounterRepeatClose;
int    RB_Counter=0, RB_TimeBar=0, RB_Operation=1, RB_Ticket=2, RB_Price=3, RB_StopLoss=4, RB_TakeProfit=5; 
int    CB_Counter=0, CB_TimeBar=0, CB_Operation=1, CB_RecTicket=2, CB_OurTicket=3, CB_OpenPrice=4, CB_ClosePrice=5, CB_StopLoss=6, CB_TakeProfit=7; 
bool   fTime=true, StopTradesByMargin, LastisOrderSell, LastisOrderBuy, TryRepeatCloseOrder;
int    LastOpenHour1, LastCloseHour1, LastOpenHour2, LastCloseHour2;
bool   RepeatCloseOrder, FirstComment=false;
string ErrorArray[4207];
int    TradeTimeBuffer[5][4];
double ReceiveBuffer[1][6];
double CommandBuffer[1][8];
string CommentBuffer[20][2];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
{
   Comment("");
   InitString="";
   Slippage=MarketInfo(Symbol(),MODE_SPREAD);
   InitErrorArray();
   if (HideIndicators) HideTestIndicators(true);
   LastOrderTime=Time[0];
   MagicNumber=PersonalMagicNumber;
   ClearBuffer("ReceiveBuffer",RB_Counter);
   ClearBuffer("CommandBuffer",CB_Counter);
   ClearBuffer("CommentBuffer",0);
   InitString="Manual settings for "+AccountCompany()+" M"+Period()+"\n";
   if (UseAutosettings)
      {
      if (SetAutoSettings())
         {
         InitString="Automatic settings for "+AccountCompany()+" M"+Period()+"\n";
         }
      }
   LastOpenHour1=OpenHour1; LastCloseHour1=CloseHour1; LastOpenHour2=OpenHour2; LastCloseHour2=CloseHour2;
   StartRulls();
   
   
   if (Lots!=0)
      {
      InitString = InitString + "Lots = " + DoubleToStr(Lots,2) + "\n";
      }
   else
      {
      InitString = InitString + "LotsPercent = " + LotsPercent + " %" + "\n";
      }
   InitString = InitString + "TakeProfit = " + TakeProfit + "\n";
   InitString = InitString + "StopLoss = " + StopLoss + "\n";
   InitString = InitString + "ChannelBars = " + ChannelBars + "\n";
   InitString = InitString + "CheckTimeBar = " + CheckTimeBar + "\n";
   InitString = InitString + "EqualBars = " + EqualBars + "\n";
   InitString = InitString + "EachDayHourSettings = " + EachDayHourSettings + "\n";
   InitString = InitString + "Trade time " + OpenHour1 + ".00  " + CloseHour1 + ".00 and " + OpenHour2 + ".00 " + CloseHour2 + ".00" + "\n";


   if (TradeTransferOut)
      {
      SaveFileOrder(0, OP_NONE, 0, 0, 0, 0, 0);
      }
   else
      {
      Comments("Initial");
      }
return(0);}
// конец.
//+------------------------------------------------------------------+
int deinit()
{
   ClearBuffer("ReceiveBuffer",RB_Counter);
   ClearBuffer("CommandBuffer",CB_Counter);
   ClearBuffer("CommentBuffer",0);
return(0);}
// конец.
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
//
   if (!StartRulls()) return(0);
   if (TradeTransferIn)
      {
      if (ReadFileOrder()) CheckReceiveBuffer();
      CheckCommandBuffer();
      return(0);
      }
//
   PrepareIndicators();
//   if (StopByMaxDrawDown()) return(0);
   
   
//   Comments("Start()");
 

 
   if (isOrderSell() && !TimeCurrentBar())
      {
      if (isGroDtoBuy() || isMinProfittoClose() || TryToCloseAgain())
         {
         if (CurrentOrderProfitPoint<0 && TryTakeProfit) return(0);
         CloseSellOrder();
         return(0);
         }
      return(0);
      }



   if (isOrderBuy() && !TimeCurrentBar())
      {
      if (isGroDtoSell() || isMinProfittoClose() || TryToCloseAgain())
         {
         if (CurrentOrderProfitPoint<0 && TryTakeProfit) return(0);
         CloseBuyOrder();
         return(0);
         }
      return(0);
      }




   if (isGroDtoSell() && !TimeCurrentBar() && (isTimetoTrade(OpenHour1, CloseHour1) || isTimetoTrade(OpenHour2, CloseHour2)))
      {
         {
         SendSellOrder(StopLoss,TakeProfit);
         return(0);
         }
      }
      
   if (isGroDtoBuy() && !TimeCurrentBar() && (isTimetoTrade(OpenHour1, CloseHour1) || isTimetoTrade(OpenHour2, CloseHour2)))
      {
         {
         SendBuyOrder(StopLoss,TakeProfit);
         return(0);
         }
      }
      
      
      
      
return(0);}
// конец.

/*
bool StopByMaxDrawDown(){
   bool result=false;
   double CurrentMaxDrawDown;
   if (MaxDrawDown==0 || (OpenHour1==0 && CloseHour1==12 && OpenHour2==12 && CloseHour2==24)) return(result);
   if (!isTimetoTrade(OpenHour1, CloseHour1) && !isTimetoTrade(OpenHour2, CloseHour2))
      {
      Comments("StopByMaxDrawDown(): Trade allow");
      StopTradesByMargin=false;
      GlobalVariableSet("MaxAccountValue",AccountBalance());
      result=false;
      return(result);
      }
   if (StopTradesByMargin)
      {
      result=true;
      return(result);
      }
   if (GlobalVariableGet("MaxAccountValue")-AccountBalance()<0) GlobalVariableSet("MaxAccountValue",AccountBalance());
   CurrentMaxDrawDown=GlobalVariableGet("MaxAccountValue")-GlobalVariableGet("MaxAccountValue")*MaxDrawDown/100;/*
/*   Comment(
            "CurrentMaxDrawDown= ",CurrentMaxDrawDown,"\n",
            "MaxAccountValue= ",GlobalVariableGet("MaxAccountValue"),"\n",
            "AccountBalance()= ",AccountBalance(),"\n",
            "AccountEquity()= ",AccountEquity(),"\n"
            );*//*
   if (CurrentMaxDrawDown-AccountEquity()>0)
      {
      while (isOrderBuy()) CloseBuyOrder();
      while (isOrderSell()) CloseSellOrder();
      Comments("StopByMaxDrawDown(): Trade is permitted");
      StopTradesByMargin=true;
      result=true;
      return(result);
      }
return(result);}
*/
/*

void ResultTrades()
{
   if (OrderType()==OP_BUY)
      {
      if (UPmaxProfit<MaxProfit) UPmaxProfit=MaxProfit;
      if (UPmaxLoss<MaxLoss) UPmaxLoss=MaxLoss;
      }
   if (OrderType()==OP_SELL)
      {
      if (DOWNmaxProfit<MaxProfit) DOWNmaxProfit=MaxProfit;
      if (DOWNmaxLoss<MaxLoss) DOWNmaxLoss=MaxLoss;
      }
   MaxProfit=0;
   MaxLoss=0;
}

void CalculateTrades()
{
   if (OrderType()==OP_BUY)
      {
      if ((Bid-OrderOpenPrice())>MaxProfit) MaxProfit=Bid-OrderOpenPrice();
      if ((OrderOpenPrice()-Bid)>MaxLoss) MaxLoss=OrderOpenPrice()-Bid;
      }
   if (OrderType()==OP_SELL)
      {
      if ((OrderOpenPrice()-Ask)>MaxProfit) MaxProfit=OrderOpenPrice()-Ask;
      if ((Ask-OrderOpenPrice())>MaxLoss) MaxLoss=Ask-OrderOpenPrice();
      }
}
*/

   
bool TimeCurrentBar(){
   bool result=false;
   if (CheckTimeBar && Time[0]==LastOrderTime) result=true;
return(result);}

bool isOrderSell(){
   bool result=false;
   int cnt=0, ticket, total;
   total=OrdersTotal();
   for (cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
         {
         if (!TradeTransferOut && OrderMagicNumber()!=MagicNumber) continue;
         result=true;
         CurrentOrderProfit = OrderProfit();
         CurrentOrderProfitPoint = (OrderOpenPrice()-Ask)/Point;
         break;
         }
      }
   if (LastisOrderSell && !result)
      {
      if (OrderStopLoss()!=0 || OrderTakeProfit()!=0) LastOrderTime=Time[0];
      }
   LastisOrderSell=result;
return(result);}



bool isOrderBuy(){
   bool result=false;
   int cnt=0, ticket, total;
   total=OrdersTotal();
   for (cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
         {
         if (!TradeTransferOut && OrderMagicNumber()!=MagicNumber) continue;
         result=true;
         CurrentOrderProfit = OrderProfit();
         CurrentOrderProfitPoint = (Bid-OrderOpenPrice())/Point;
         break;
         }
      }
   if (LastisOrderBuy && !result)
      {
      if (OrderStopLoss()!=0 || OrderTakeProfit()!=0) LastOrderTime=Time[0];
      }
   LastisOrderBuy=result;
return(result);}
/*
bool OrderRevers(){
   bool result=false;
   int cnt=0, ticket, total;
   total=OrdersTotal();
   for (cnt=0;cnt<total;cnt++)
   {
      ticket = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      ticket = OrderTicket();
      if (OrderSymbol()==Symbol() &&  OrderMagicNumber()==MagicNumber && OrderType()<=OP_SELL)
         {
         if (OrderCloseBy(OrderTicket(),ticket,ReversOrderColor))
            {
//            Comments("Order reversed : "+OrderOpenPrice());
            opposite_id=opposite_id+1;
            result=true;
            LastOrderTime=Time[0];
            if (TradeTransferOut) SaveFileOrder(Time[0], OP_CLOSEBY, ticket, OrderLots(), Bid, 0, 0);
            }
         else
            {
            Comments("Error revers order: "+PrintError(GetLastError()));
            }
         }
   }
return(result);}
*/
bool CloseBuyOrder(){
   bool result=false;
   int cnt=0, ticket, total;
   total=OrdersTotal();
   for (cnt=0;cnt<total;cnt++)
      {
      ticket = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
         {
         if (isFreezLevel()) continue;
         if (!TradeTransferOut &&  OrderMagicNumber()==MagicNumber)
            {
            if (OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,BuyOrderColor))
               {
//               Comments("Buy order closed : "+OrderClosePrice());
               result=true;
               LastOrderTime=Time[0];
               LastDirection=OP_BUY;
               RepeatCloseOrder=false;
               }
            else
               {
               Comments("Error close Buy order: "+PrintError(GetLastError()));
               RepeatCloseOrder=true;
               }
            }
         else
            {
            if (SaveFileOrder(Time[0], OP_CLOSE, OrderTicket(), OrderLots(), Bid, 0, 0))
               {
//               Comments("Close Buy order transmited");
               result=true;
               LastOrderTime=Time[0];
               LastDirection=OP_BUY;
               RepeatCloseOrder=false;
               }
            else
               {
               Comments("Error transmite Close Buy order");
               RepeatCloseOrder=true;
               }
            }
         }
      }
return(result);}

bool CloseSellOrder(){
   bool result=false;
   int cnt=0, ticket, total;
   total=OrdersTotal();
   for (cnt=0;cnt<total;cnt++)
      {
      ticket = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
         {
         if (isFreezLevel()) continue;
         if (!TradeTransferOut &&  OrderMagicNumber()==MagicNumber)
            {
            if (OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,SellOrderColor))
               {
//               Comments("Sell order closed : "+OrderClosePrice());
               result=true;
               LastOrderTime=Time[0];
               LastDirection=OP_SELL;
               RepeatCloseOrder=false;
               }
            else
               {
               Comments("Error close Sell order: "+PrintError(GetLastError()));
               RepeatCloseOrder=true;
               }
            }
         else
            {
            if (SaveFileOrder(Time[0], OP_CLOSE, OrderTicket(), OrderLots(), Ask, 0, 0))
               {
//               Comments("Close Sell order transmited");
               result=true;
               LastOrderTime=Time[0];
               LastDirection=OP_SELL;
               RepeatCloseOrder=false;
               }
            else
               {
               Comments("Error transmite Close Sell order");
               RepeatCloseOrder=true;
               }
            }
         }
      }
return(result);}



bool TryToCloseAgain(){
   bool result=false;
   if (!RepeatCloseOrder)
      {
      CounterRepeatClose=NumberRepeatCloseOrder;
      }
   else
      {
      CounterRepeatClose=CounterRepeatClose-1;
      if (CounterRepeatClose>0)
         {
         result=true;
         }
      else
         {
         RepeatCloseOrder=false;
   //      Comments("TryToCloseAgain(): Error after repeat Close order");
         }
      }
return(result);}



bool isFreezLevel()
{
   bool result=false;
   double Price, FreezLevelValue, CurrentSlippage;
   if (CheckFreezLevel)
      {
      if (OrderStopLoss()!=0 || OrderTakeProfit()!=0)
         {
         if (OrderType()==OP_BUY) Price=Bid;
         if (OrderType()==OP_SELL) Price=Ask;
         FreezLevelValue=MarketInfo(Symbol(),MODE_FREEZELEVEL)*Point;
         if (  OrderStopLoss()!=0 && FreezLevelValue>(MathAbs(Price-OrderStopLoss()  ))) result=true;
         if (OrderTakeProfit()!=0 && FreezLevelValue>(MathAbs(Price-OrderTakeProfit()))) result=true;
         }
      }
return(result);}

bool SendBuyOrder(double SBO_StopLoss, double SBO_TakeProfit)
{
int ticket=0;
   RepeatCloseOrder=false;
   if (SBO_StopLoss!=0)
      {
      if (SBO_StopLoss < MarketInfo(Symbol(),MODE_STOPLEVEL)) SBO_StopLoss = MarketInfo(Symbol(),MODE_STOPLEVEL);
      SBO_StopLoss = NormalizeDouble(Bid - SBO_StopLoss*Point,MarketInfo(Symbol(),MODE_DIGITS));
      }
   if (SBO_TakeProfit!=0)
      {
      if (SBO_TakeProfit < MarketInfo(Symbol(),MODE_STOPLEVEL)) SBO_TakeProfit = MarketInfo(Symbol(),MODE_STOPLEVEL);
      SBO_TakeProfit = NormalizeDouble(Ask + SBO_TakeProfit*Point,MarketInfo(Symbol(),MODE_DIGITS));
      }
   if (!TradeTransferOut)
      {
      ticket=OrderSend(Symbol(),OP_BUY,LotsForTrade,Ask,Slippage,SBO_StopLoss,SBO_TakeProfit, NameID,MagicNumber,0,BuyOrderColor);
      if(ticket>0)
         {
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
            {
//            Comments("Buy order opened : "+OrderOpenPrice());
            LastOrderTime=Time[0];
            LastOrderBar=Bars;
            CurrentOrderTicket=ticket;
            CurrentOrderTrailingStop=0;
            }
         }
      else 
         {
         Comments("Error open Buy order : "+PrintError(GetLastError()));
         return(false);
         }
      }
   else
      {
      if (SaveFileOrder(Time[0], OP_BUY, ticket, LotsForTrade, Ask, SBO_StopLoss, SBO_TakeProfit))
         {
//         Comments("Buy order open transmited ");
         LastOrderTime=Time[0];
         LastOrderBar=Bars;
         CurrentOrderTrailingStop=0;
         }
      else 
         {
         Comments("Error transmite open Buy order");
         return(false);
         }
      }
return(true);}

bool SendSellOrder(double SSO_StopLoss, double SSO_TakeProfit)
{
int ticket=0;
   RepeatCloseOrder=false;
   if (SSO_StopLoss!=0)
      {
      if (SSO_StopLoss < MarketInfo(Symbol(),MODE_STOPLEVEL)) SSO_StopLoss = MarketInfo(Symbol(),MODE_STOPLEVEL);
      SSO_StopLoss = NormalizeDouble(Ask + SSO_StopLoss*Point,MarketInfo(Symbol(),MODE_DIGITS));
      }
   if (SSO_TakeProfit!=0)
      {
      if (SSO_TakeProfit < MarketInfo(Symbol(),MODE_STOPLEVEL)) SSO_TakeProfit = MarketInfo(Symbol(),MODE_STOPLEVEL);
      SSO_TakeProfit = NormalizeDouble(Bid - SSO_TakeProfit*Point,MarketInfo(Symbol(),MODE_DIGITS));
      }
   if (!TradeTransferOut)
      {
      ticket=OrderSend(Symbol(),OP_SELL,LotsForTrade,Bid,Slippage,SSO_StopLoss,SSO_TakeProfit, NameID,MagicNumber,0,SellOrderColor);
      if(ticket>0)
         {
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
            {
//            Comments("Sell order opened : "+OrderOpenPrice());
            LastOrderTime=Time[0];
            LastOrderBar=Bars;
            CurrentOrderTicket=ticket;
            CurrentOrderTrailingStop=0;
            }
         }
      else 
         {
         Comments("Error open Sell order : "+PrintError(GetLastError()));
         return(false);
         }
      }
   else
      {
      if (SaveFileOrder(Time[0], OP_SELL, ticket, LotsForTrade, Bid, SSO_StopLoss, SSO_TakeProfit))
         {
//         Comments("Sell order open transmited: ");
         LastOrderTime=Time[0];
         LastOrderBar=Bars;
         CurrentOrderTrailingStop=0;
         }
      else 
         {
         Comments("Error transmite open Sell order");
         return(false);
         }
      }
return(true);}










bool StartRulls()
{
   double LotsStep, LotsMin, LotsMax;
   int LotsDigit;
   if (EachDayHourSettings && DayOfWeek()>0)
      {
      OpenHour1 =TradeTimeBuffer[DayOfWeek()-1][OH1];
      CloseHour1=TradeTimeBuffer[DayOfWeek()-1][CH1];
      OpenHour2 =TradeTimeBuffer[DayOfWeek()-1][OH2];
      CloseHour2=TradeTimeBuffer[DayOfWeek()-1][CH2];
      }
   if (!FirstComment)
      {
      FirstComment=true;
      }
   else
      {
      if (LastOpenHour1!=OpenHour1 || LastCloseHour1!=CloseHour1 || LastOpenHour2!=OpenHour2 || LastCloseHour2!=CloseHour2)
         {
         LastOpenHour1=OpenHour1; LastCloseHour1=CloseHour1; LastOpenHour2=OpenHour2; LastCloseHour2=CloseHour2;
         Comments("Another trade time EA");
         }
      }
   
   if (IsOptimization())
      {
      if (OpenHour1>12) return(false);
      if (CloseHour1>12) return(false);
      if (OpenHour2<12) return(false);
      if (CloseHour2<12) return(false);
      if (OpenHour1>CloseHour1 || OpenHour2>CloseHour2) return(false);
      }
   if(Bars<100)
     {
      Comments("StartRulls() Bars less than 100");
      return(false);  
     }
   if (IsTesting() || IsOptimization())
      {
      TradeTransferIn=false;
      TradeTransferOut=false;
      }
   if (TradeTransferIn && TradeTransferOut)
      {
     // Comment ("TradeTransferIn и TradeTransferOut не могут работать одновременно!!!");
      return(false);
      }
   LotsStep = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP),2);
   LotsMin=NormalizeDouble(MarketInfo(Symbol(),MODE_MINLOT),2);
   LotsMax=NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT),2);
   if (LotsStep==0.01) LotsDigit=2; else LotsDigit=1;
   // расчет размера лота
   if (Lots==0) LotsForTrade=NormalizeDouble(AccountFreeMargin()*LotsPercent/100000,LotsDigit);
   else LotsForTrade=Lots;
   if (LotsForTrade>LotsMax) LotsForTrade=LotsMax;
   if (LotsForTrade<LotsMin) LotsForTrade=LotsMin;
return(true);}





/*
bool isBBtoBuy(){
   bool result=false;
   if ((iBBHigh(0)-iBBLow(0))/Point<=BBChannelValue && Bid<iBBMidle(0))
       result=true;
return(result);}

bool isBBtoSell(){
   bool result=false;
   if ((iBBHigh(0)-iBBLow(0))/Point<=BBChannelValue && Bid>iBBMidle(0))
       result=true;
return(result);}
*/


bool isMinProfittoClose(){
   bool result=false;
   if (CurrentOrderProfitPoint>0 && CurrentOrderProfitPoint>=MinProfitValue && MinProfitValue!=0)
      {
      result=true;
      }
return(result);}

/*
bool isTrailingStop(){
   bool result=false;
   int OrderTrailingStop;
   if (CurrentOrderProfitPoint>MinProfitValue)
      {
      OrderTrailingStop=MathCeil(CurrentOrderProfitPoint*TrailingStop/100);
      if (OrderTrailingStop<1) OrderTrailingStop=1;
      if (CurrentOrderTrailingStop<OrderTrailingStop) CurrentOrderTrailingStop=OrderTrailingStop;
      }
   if (CurrentOrderTrailingStop!=0 && CurrentOrderProfitPoint<=CurrentOrderTrailingStop) result=true;
return(result);}
*/




/*
bool isTradeLimit(){
   bool result=false;
   if (CurrentOrderTicket!=LastOrderTicket)
      {
      CurrentOrderTicket=LastOrderTicket;
      TradeLimit=false;
      }
   if (TradeLimit) return(result);
   if (OrderProfit()>0) return(result);
   TradeLimit=true;
return(result);}
*/



bool isGroDtoBuy(){
   bool result=false;
   if (!ReversTrades)
      {
      if (Bid < (LowestBarsValue-Point*BuyCorrection) || (EqualBars && Bid <= (LowestBarsValue-Point*BuyCorrection))) result=true;
      }
   else
      {
      if (Bid > HighestBarsValue || (EqualBars && Bid >= HighestBarsValue)) result=true;
      }
return(result);}

bool isGroDtoSell(){
   bool result=false;
   if (!ReversTrades)
      {
      if (Bid > (HighestBarsValue+Point*SellCorrection) || (EqualBars && Bid >= (HighestBarsValue+Point*SellCorrection))) result=true;
      }
   else
      {
      if (Bid < LowestBarsValue || (EqualBars && Bid <= LowestBarsValue)) result=true;
      }
return(result);}




bool isTimetoTrade(int OpenHour, int CloseHour)
{
   bool result = false;
   int CurrentHour=Hour();
   if (OpenHour > 23 || OpenHour < 0 ) OpenHour = 0;
   if (CloseHour > 23 || CloseHour < 0 ) CloseHour = 0;
   if (OpenHour<CloseHour && (Hour()>=OpenHour && Hour()<CloseHour)) result=true;
   if (OpenHour>CloseHour && (Hour()>=OpenHour || Hour()<CloseHour)) result=true;
   if (DayOfWeek()!=TradeDayOfWeek && TradeDayOfWeek!=0) result = false;
return(result);}


//-------------------------------------------------------------------------- 
bool SaveFileOrder( int FileOrderTimeBar,int FileOrderOperation, int FileOrderTicket, double FileOrderLots, double FileOrderPrice, double FileOrderStopLoss, double FileOrderTakeProfit)
{
   int handle;
   bool result = false;
   string FileName = Symbol() + ".csv" ;
   handle=FileOpen(FileName,FILE_CSV|FILE_WRITE,';');
   if(handle<1)
      {
    //  Comments("SaveFileOrder(): Файл "+FileName+" не создан, ошибка :" + PrintError(GetLastError()));
      return(result);
      }
   FileWrite(handle,
//       FileOrderTimeBar,
         FileOrderOperation,
         FileOrderLots,
         FileOrderTicket,
         FileOrderPrice,
         DoubleToStr(FileOrderStopLoss,MarketInfo(Symbol(),MODE_DIGITS)),
         DoubleToStr(FileOrderTakeProfit,MarketInfo(Symbol(),MODE_DIGITS)));
   FileClose(handle);
//   Comments("SaveFileOrder(): Файл записан : "+FileName);
   result=true;

   if (FileOrderOperation==OP_BUY)   Comments("BUY     "+FileOrderOperation+" ; "+LotsForTrade+" ; "+FileOrderTicket+" ; "+FileOrderPrice+" ; "+FileOrderStopLoss+" ; "+FileOrderTakeProfit);
   if (FileOrderOperation==OP_SELL)  Comments("SELL    "+FileOrderOperation+" ; "+LotsForTrade+" ; "+FileOrderTicket+" ; "+FileOrderPrice+" ; "+FileOrderStopLoss+" ; "+FileOrderTakeProfit);
   if (FileOrderOperation==OP_CLOSE) Comments("CLOSE   "+FileOrderOperation+" ; "+LotsForTrade+" ; "+FileOrderTicket+" ; "+FileOrderPrice+" ; "+FileOrderStopLoss+" ; "+FileOrderTakeProfit);
   if (FileOrderOperation==OP_NONE)  Comments("NONE    "+FileOrderOperation+" ; "+LotsForTrade+" ; "+FileOrderTicket+" ; "+FileOrderPrice+" ; "+FileOrderStopLoss+" ; "+FileOrderTakeProfit);

   SaveOperationCounter =SaveOperationCounter + 1;
   if (SaveOperationCounter>FileCounterMaxValue) SaveOperationCounter=0;


//Проверка наличия файла в директории
   datetime TimeSaveFile=TimeLocal();
   if (CheckDeleteFile)
      {
//      Comments("SaveFileOrder(): Ожидание удаления файла");
      result=false;
      while (TimeLocal()-TimeSaveFile < TimeOutDeleteFile)
         {
         if (!isFile())
            {
            result=true;
            break;
            }
         Sleep(25);
         }
      if (!result)
         {
         if (DeleteFileAfterChecking)
            {
            if (FileErase(FileName))
               {
               Comments("SaveFileOrder(): Истек таймаут передачи файла, файл передачи очищен");
               }
            else
               {
               Comments("SaveFileOrder(): Истек таймаут передачи файла, файл передачи не удалось очистить");
               }
            }
         else
            {
            Comments("SaveFileOrder(): Истек таймаут передачи файла");
            }
         }
      }
//Проверка установки/закрытия ордеров
   TimeSaveFile=TimeLocal();
   if (CheckSetOrder)
      {
      result=false;
//      Comments("SaveFileOrder(): Ожидание установки/снятия ордера");
      while (TimeLocal()-TimeSaveFile < TimeOutSetOrder)
         {
         if (FileOrderOperation==OP_SELL && isOrderSell())
            {
            result=true;
            break;
            }
         if (FileOrderOperation==OP_BUY && isOrderBuy())
            {
            result=true;
            break;
            }
         if (FileOrderOperation==OP_CLOSE && !isOrderSell() && !isOrderBuy())
            {
            result=true;
            break;
            }
         if (FileOrderOperation==OP_NONE)
            {
            result=true;
            break;
            }
         Sleep(25);
         }
      if (!result)
         {
         if (DeleteFileAfterChecking)
            {
            if (FileErase(FileName))
               {
               Comments("SaveFileOrder(): Истек таймаут установки ордера, файл передачи очищен");
               }
            else
               {
               Comments("SaveFileOrder(): Истек таймаут установки ордера, файл передачи не удалось очистить");
               }
            }
         else
            {
            Comments("SaveFileOrder(): Истек таймаут установки ордера");
            }
         }
      }
return(result);}









//-------------------------------------------------------------------------- 
bool isFile()
{
   int handle;
   string FileName;
   bool result=false;
   FileName =  Symbol() + ".csv";
   handle=FileOpen(FileName,FILE_CSV|FILE_READ|FILE_WRITE);
   if (handle>0 && FileSize(handle)>0)
      {
      FileClose(handle);
      result=true;
      }
return(result);}

//-------------------------------------------------------------------------- 
bool FileErase(string FileName)
{
   int handle;
   bool result=false;
   handle=FileOpen(FileName,FILE_CSV|FILE_WRITE);
   if (handle>0)
      {
//      Comments("FileErase(): handle>0");
      FileClose(handle);
      result=true;
      }
return(result);}




//-------------------------------------------------------------------------- 
bool Comments(string CommentString){
   bool result=false;
   int i,j;
   if (ShowPrint)
      {
      string str="";
      if (ShowTime) str=str+TimeToStr(TimeCurrent(),TIME_SECONDS)+" : ";
      if (ShowNameID) str=str+NameID;
      if (ShowMagicNumber) str=str+"("+MagicNumber+")";
      if (ShowNameID || ShowMagicNumber) str=str+": ";
      Print(str+CommentString);
      }
   if (ShowSettings)
      {
      if (ShowComment) Comment(InitString+str+CommentString);
      }
   else
      {
      if (ShowComment) Comment(str+CommentString);
      }
//   if (ShowComment) ShowCommentList(false);
return(result);}

/*
//-------------------------------------------------------------------------- 
bool ShowCommentList(bool CheckForOld){
   bool result=false;
   int i,j;
   string str="";
   
   CommentBuffer[19][0]="Hello";
   CommentBuffer[19][1]="Hello";
      {
      for (i=0;i<=19;i++)
         {
         if (CommentBuffer[i][1]!="1")
            {
            str=str + i+": "+CommentBuffer[i][0]+"\n";
            }
         else
            {
            Comment (str);
            break;
            }
         }
      }
return(result);}
*/


//-------------------------------------------------------------------------- 
bool ReadFileOrder()
{
   int handle, counter;
   string str;
   string FileName;
   bool result=false;
   if (fTime)
      {
      for(counter=0;counter<FileCounterMaxValue+1;counter++)
         {
         FileName =  Symbol()+ (PersonalMagicNumber + Period()) + "_" + counter + ".csv";
         handle=FileOpen(FileName,FILE_CSV|FILE_READ);
         if (!handle<0)
            {
            ReadOperationCounter = counter;
            fTime=false;
            FileClose(handle);
            break;
            }
         }
      }
   if (fTime) return(result);
   FileName =  Symbol()+ (PersonalMagicNumber + Period()) + "_" + ReadOperationCounter + ".csv";
   handle=FileOpen(FileName,FILE_CSV|FILE_READ);
   if (handle>0)
      {  
         str=FileReadString(handle);
         ReceiveBuffer[RB_Counter][RB_TimeBar] = StrToInteger(str);
         str=FileReadString(handle);
         ReceiveBuffer[RB_Counter][RB_Operation] = StrToInteger(str);
         str=FileReadString(handle);
         ReceiveBuffer[RB_Counter][RB_Ticket] = StrToInteger(str);
         str=FileReadString(handle);
         ReceiveBuffer[RB_Counter][RB_Price] = StrToDouble(str);
         str=FileReadString(handle);
         ReceiveBuffer[RB_Counter][RB_StopLoss] = StrToDouble(str);
         str=FileReadString(handle);
         ReceiveBuffer[RB_Counter][RB_TakeProfit] = StrToDouble(str);
         FileClose(handle);
         FileDelete(FileName);
         
         ReadOperationCounter =ReadOperationCounter + 1;
         if (ReadOperationCounter>FileCounterMaxValue) ReadOperationCounter=0;
         Comments("ReadFileOrder(): Последний загруженный файл "+ FileName);
         result=true;
      }
return(true);}

bool CheckReceiveBuffer(){
   bool result=false;
   if (ReceiveBuffer[RB_Counter][RB_Operation]!=OP_NONE)
      {
      if (ReceiveBuffer[RB_Counter][RB_Operation]==OP_CLOSE)
         {
         if (CommandBuffer[CB_Counter][CB_OurTicket]!=0 && ReceiveBuffer[RB_Counter][RB_Ticket]==CommandBuffer[CB_Counter][CB_RecTicket])
            {
            CommandBuffer[CB_Counter][CB_Operation]=OP_CLOSE;
            CommandBuffer[CB_Counter][CB_ClosePrice]=ReceiveBuffer[RB_Counter][RB_Price];
            result = true;
            }
         }
      if ((ReceiveBuffer[RB_Counter][RB_Operation]==OP_BUY || ReceiveBuffer[RB_Counter][RB_Operation]==OP_SELL) &&
            CommandBuffer[CB_Counter][CB_Operation]==OP_NONE)
         {
         CommandBuffer[CB_Counter][CB_TimeBar]   = ReceiveBuffer[RB_Counter][RB_TimeBar];
         CommandBuffer[CB_Counter][CB_Operation] = ReceiveBuffer[RB_Counter][RB_Operation];
         CommandBuffer[CB_Counter][CB_RecTicket] = ReceiveBuffer[RB_Counter][RB_Ticket];
         CommandBuffer[CB_Counter][CB_OpenPrice] = ReceiveBuffer[RB_Counter][RB_Price];
         CommandBuffer[CB_Counter][CB_StopLoss]  = ReceiveBuffer[RB_Counter][RB_StopLoss];
         CommandBuffer[CB_Counter][CB_TakeProfit]= ReceiveBuffer[RB_Counter][RB_TakeProfit];
         result = true;
         }
      }
   ClearBuffer("ReceiveBuffer",RB_Counter);
return(result);}



bool CheckCommandBuffer(){
   bool result=false;
   if (CommandBuffer[CB_Counter][CB_Operation]!=OP_NONE)
      {
      if (CommandBuffer[CB_Counter][CB_TimeBar]+BarSlippage*(Period()*60)<=Time[0])
         {
         if (CommandBuffer[CB_Counter][CB_Operation]==OP_BUY &&
             CommandBuffer[CB_Counter][CB_OpenPrice]>=Ask)
             {
             if (SendBuyOrder(CommandBuffer[CB_Counter][CB_StopLoss], CommandBuffer[CB_Counter][CB_TakeProfit])) 
               {
                result=true;
               }
             }
         if (CommandBuffer[CB_Counter][CB_Operation]==OP_SELL &&
             CommandBuffer[CB_Counter][CB_OpenPrice]<=Bid)
             {
             if (SendSellOrder(CommandBuffer[CB_Counter][CB_StopLoss], CommandBuffer[CB_Counter][CB_TakeProfit])) 
               {
                result=true;
               }
             }
         }
      if (CommandBuffer[CB_Counter][CB_TimeBar]+BarSlippage*(Period()*60)<=Time[0])
         {
         }
      }
return(result);}


bool ClearBuffer(string CurrentBuffer, int Row){
   int result=false;
   if (CurrentBuffer=="ReceiveBuffer")
      {
      ReceiveBuffer[RB_Counter][RB_TimeBar] = 0;
      ReceiveBuffer[RB_Counter][RB_Operation] = OP_NONE;
      ReceiveBuffer[RB_Counter][RB_Ticket] = 0;
      ReceiveBuffer[RB_Counter][RB_Price] = 0;
      ReceiveBuffer[RB_Counter][RB_StopLoss] = 0;
      ReceiveBuffer[RB_Counter][RB_TakeProfit] = 0;
      }
   if (CurrentBuffer=="CommandBuffer")
      {
      ReceiveBuffer[CB_Counter][CB_TimeBar] = 0;
      ReceiveBuffer[CB_Counter][CB_Operation] = OP_NONE;
      ReceiveBuffer[CB_Counter][CB_RecTicket] = 0;
      ReceiveBuffer[CB_Counter][CB_OurTicket] = 0;
      ReceiveBuffer[CB_Counter][CB_OpenPrice] = 0;
      ReceiveBuffer[CB_Counter][CB_ClosePrice] = 0;
      ReceiveBuffer[CB_Counter][CB_StopLoss] = 0;
      ReceiveBuffer[CB_Counter][CB_TakeProfit] = 0;
      }
   if (CurrentBuffer=="CommentBuffer")
      {
      for (int i=0;i<20;i++)
         {
         CommentBuffer[i][0]="";
         CommentBuffer[i][1]="";
         }
      }
return(result);}



//-------------------------------------------------------------------------- 

/*  
bool CloseOrdersBuyMargin()
{  int counter;
   double MinProfit=0;
   bool result=false;
   if ((AccountFreeMarginCheck(Symbol(),OP_BUY, 2*Lots)<=0 || AccountFreeMarginCheck(Symbol(),OP_SELL, 2*Lots)<=0)
         && (AccountBalance()>AccountEquity()) )
   {
      for(counter=0;counter<OrdersTotal();counter++)
      {
         OrderSelect(counter, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
         {
            if(OrderProfit()<=MinProfit) {MinProfit=OrderProfit();}
         }
      }
      for(counter=0;counter<OrdersTotal();counter++)
      {
         OrderSelect(counter, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
         {
            if(  (MinProfit-OrderProfit())==0
               && ( ((MathAbs(OrderOpenPrice()-Bid)-TrailingStop*Point)>0 && OrderType()==OP_BUY) 
                 || ((MathAbs(Ask-OrderOpenPrice())-TrailingStop*Point)>0 && OrderType()==OP_SELL) ) )
            {
               OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,White);
               if (OrderType()==OP_BUY) {Comments("Buy Order close by margin, profit= "+ OrderProfit());}
               if (OrderType()==OP_SELL) {Comments("Sell Order close by margin, profit= "+ OrderProfit());}
               result=true;
               break;
            }
         }
      }
    }
return(result);}
*/

//
string PrintError(int ErrorCode)
{
return(ErrorArray[ErrorCode]);}

void InitErrorArray()
{
   ErrorArray[0] = "No errors";
   ErrorArray[1] = "No errors, but no resulting";
   ErrorArray[2] = "General fault";
   ErrorArray[3] = "Fault parameters"; 
   ErrorArray[4] = "Trade busy"; 
   ErrorArray[5] = "Old version of terminal"; 
   ErrorArray[6] = "Not connect"; 
   ErrorArray[7] = "Rules not good for you"; 
   ErrorArray[8] = "Very many orders"; 
   ErrorArray [9] = "Invalid operation disrupt the server"; 
    ErrorArray [64] = "blocked account"; 
    ErrorArray [65] = "Invalid account number"; 
    ErrorArray [128] = "Expired expectations of the transaction"; 
    ErrorArray [129] = "Invalid price"; 
    ErrorArray [130] = "Wrong foot"; 
    ErrorArray [131] = "Invalid volume"; 
    ErrorArray [132] = "The market is closed"; 
    ErrorArray [133] = "Trade is prohibited"; 
    ErrorArray [134] = "Not enough money for the transaction"; 
    ErrorArray [135] = "Price has changed"; 
    ErrorArray [136] = "No price"; 
    ErrorArray [137] = "Broker busy"; 
    ErrorArray [138] = "New prices"; 
    ErrorArray [139] = "Order has been blocked and processed"; 
    ErrorArray [140] = "Allow only buy"; 
    ErrorArray [141] = "Too many bugs"; 
    ErrorArray [145] = "Modification is prohibited, as the warrant is too close to the market"; 
    ErrorArray [146] = "subsystem busy trade"; 
    ErrorArray [147] = "Using the date of expiry of the warrant is prohibited broker"; 
    ErrorArray [148] = "The number of open orders and deferred reached the limit set by the broker"; 
    ErrorArray [4000] = "No errors"; 
    ErrorArray [4001] = "Invalid Index function"; 
    ErrorArray [4002] = "Index array - out of range"; 
    ErrorArray [4003] = "No memory to stack functions"; 
    ErrorArray [4004] = "stack overflow after recursive call"; 
    ErrorArray [4005] = "At no memory of the stack to pass options"; 
    ErrorArray [4006] = "No memory for a string parameter"; 
    ErrorArray [4007] = "No memory for a temporary line"; 
    ErrorArray [4008] = "Neinitsializirovannaya line"; 
    ErrorArray [4009] = "Neinitsializirovannaya line in the array"; 
    ErrorArray [4010] = "No memory for an array string"; 
    ErrorArray [4011] = "Too long line"; 
    ErrorArray [4012] = "Balance of dividing by zero"; 
    ErrorArray [4013] = "The division by zero"; 
    ErrorArray [4014] = "Unknown command"; 
    ErrorArray [4015] = "Invalid conversion"; 
    ErrorArray [4016] = "Neinitsializirovanny array"; 
    ErrorArray [4017] = "Challenge DLL not allowed "; 
    ErrorArray [4018] = "Can not load library"; 
    ErrorArray [4019] = "Can not call"; 
    ErrorArray [4020] = "Challenge external library functions are not allowed "; 
    ErrorArray [4021] = "Not enough memory to the line, recovery of the function"; 
    ErrorArray [4022] = "system busy"; 
    ErrorArray [4050] = "Wrong number of parameters function"; 
    ErrorArray [4051] = "Invalid value functions"; 
    ErrorArray [4052] = "Internal error string functions"; 
    ErrorArray [4053] = "Error array"; 
    ErrorArray [4054] = "Misuse of solid-taymserii"; 
    ErrorArray [4055] = "user error indicator"; 
    ErrorArray [4056] = "Arrays incompatible"; 
    ErrorArray [4057] = "Error processing globalnyeh variables"; 
    ErrorArray [4058] = "global variable is not detected"; 
    ErrorArray [4059] = "function is not allowed in test mode"; 
    ErrorArray [4060] = "function is not allowed"; 
    ErrorArray [4061] = "Error sending"; 
    ErrorArray [4062] = "expected parameter type string"; 
    ErrorArray [4063] = "expected parameter type integer"; 
    ErrorArray [4064] = "expected parameter type double"; 
    ErrorArray [4065] = "As expected array parameter"; 
    ErrorArray [4066] = "The requested historical data in a state of renewal"; 
    ErrorArray [4067] = "Error executing trading operations"; 
    ErrorArray [4099] = "End file"; 
    ErrorArray [4100] = "error when working with the file"; 
    ErrorArray [4101] = "Invalid file name"; 
    ErrorArray [4102] = "Too many open files"; 
    ErrorArray [4103] = "Can not open file"; 
    ErrorArray [4104] = "Incompatible regime access to the file"; 
    ErrorArray [4105] = "No warrant is not selected"; 
    ErrorArray [4106] = "Unknown symbol"; 
    ErrorArray [4107] = "Invalid setting prices for commercial functions"; 
    ErrorArray [4108] = "Wrong number tiketa"; 
    ErrorArray [4109] = "Trade is not allowed. You need to include the option Allow an adviser to trade in the properties of expert"; 
    ErrorArray [4110] = "Long positions are not allowed. You should check the properties of expert"; 
    ErrorArray [4111] = "Short positions are not allowed. You should check the properties of expert"; 
    ErrorArray [4200] = "Object already exists"; 
    ErrorArray [4201] = "Requested an unknown object property"; 
    ErrorArray [4202] = "The object does not exist"; 
    ErrorArray [4203] = "Unknown type of object"; 
    ErrorArray [4204] = "No, the object name "; 
    ErrorArray [4205] = "Error coordinates object"; 
    ErrorArray [4206] = "said subwindow Not Found"; 
    ErrorArray [4207] = "error when working with the object";
}


//подготовка индикаторов
void PrepareIndicators()
   {
/*   HighestBarsValue      =High[iHighest(NULL, 0, MODE_HIGH, ChannelBars, 1)]+Point;
   LowestBarsValue       =Low [iLowest (NULL, 0, MODE_LOW , ChannelBars, 1)]+Point;
   if (IsTesting() || IsOptimization() || AccountCompany()!="Private Consulting Corp.")*/
      {
      HighestBarsValue   =High[iHighest(NULL, 0, MODE_HIGH, ChannelBars, 1)];
      LowestBarsValue    =Low [iLowest (NULL, 0, MODE_LOW , ChannelBars, 1)];
      } 
   }



/*
//индикатор Bollinger Bands
double iBBLow(int CurrentBar){
   double result;
   result = iCustom(NULL,0,"Bollinger Bands",BBPeriod,BBShift,BBDeviations,2,CurrentBar);
return(result);}

double iBBHigh(int CurrentBar){
   double result;
   result = iCustom(NULL,0,"Bollinger Bands",BBPeriod,BBShift,BBDeviations,1,CurrentBar);
return(result);}

double iBBMidle(int CurrentBar){
   double result;
   result = iCustom(NULL,0,"Bollinger Bands",BBPeriod,BBShift,BBDeviations,0,CurrentBar);
return(result);}
*/


bool SetAutoSettings(){
   bool result=false;
// Автоустановки для Fibo Group
   if (AccountCompany()=="FIBO Group, Ltd.")
      {
      if (Symbol()=="EURGBP" && Period()==PERIOD_M5)
         {
         ChannelBars=24; CheckTimeBar=false; EqualBars=true;
         if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=23; CloseHour2=0;}
         if (TradeTimeChoise==0)
         result=true;
         }
      if (Symbol()=="EURGBP" && Period()==PERIOD_M15)
         {
         ChannelBars=10; CheckTimeBar=false; EqualBars=true;
         if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=22; CloseHour2=0;}
            {
            //запонение буфера торгового времени (фиксированные настройки)
            TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=22 ; TradeTimeBuffer[0][CH2]=24; 
            TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=1 ; TradeTimeBuffer[1][OH2]=22 ; TradeTimeBuffer[1][CH2]=24; 
            TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=1 ; TradeTimeBuffer[2][OH2]=22 ; TradeTimeBuffer[2][CH2]=24; 
            TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=1 ; TradeTimeBuffer[3][OH2]=22 ; TradeTimeBuffer[3][CH2]=24; 
            TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=1 ; TradeTimeBuffer[4][OH2]=22 ; TradeTimeBuffer[4][CH2]=24;
            }
         if (TradeTimeChoise==1)
            {
            //запонение буфера торгового времени (оптимальные настройки)
            TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=20 ; TradeTimeBuffer[0][CH2]=24; 
            TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=2 ; TradeTimeBuffer[1][OH2]=18 ; TradeTimeBuffer[1][CH2]=24; 
            TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=0 ; TradeTimeBuffer[2][OH2]=21 ; TradeTimeBuffer[2][CH2]=24; 
            TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=6 ; TradeTimeBuffer[3][OH2]=20 ; TradeTimeBuffer[3][CH2]=24; 
            TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=3 ; TradeTimeBuffer[4][OH2]=22 ; TradeTimeBuffer[4][CH2]=24;
            }
         result=true;
         }
      }
   if (AccountCompany()=="ODL Securities")
      {
      if (Symbol()=="EURGBP" && Period()==PERIOD_M5)
         {
         ChannelBars=24; CheckTimeBar=false; EqualBars=true;
         if (EachDayHourSettings) {OpenHour1=0; CloseHour1=5; OpenHour2=22; CloseHour2=0;}
         result=true;
         }
      if (Symbol()=="EURGBP" && Period()==PERIOD_M15)
         {
         ChannelBars=9; CheckTimeBar=false; EqualBars=true;
         if (EachDayHourSettings) {OpenHour1=0; CloseHour1=5; OpenHour2=22; CloseHour2=0;}
         result=true;
         }
      if (Symbol()=="EURCHF" && Period()==PERIOD_M15)
         {
         ChannelBars=15; CheckTimeBar=false; EqualBars=true;
         if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=22; CloseHour2=0;}
         result=true;
         }
      }
   if (AccountCompany()=="Alpari Ltd.")
      {
      if (Symbol()=="EURGBP" && Period()==PERIOD_M15)
         {
         ChannelBars=18; CheckTimeBar=false; EqualBars=true;
//         TakeProfit = 20; StopLoss = 30;
         if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=22; CloseHour2=0;}
         if (TradeTimeChoise==0)
            {
            //запонение буфера торгового времени (фиксированные настройки)
            TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=22 ; TradeTimeBuffer[0][CH2]=24; 
            TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=1 ; TradeTimeBuffer[1][OH2]=22 ; TradeTimeBuffer[1][CH2]=24; 
            TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=1 ; TradeTimeBuffer[2][OH2]=22 ; TradeTimeBuffer[2][CH2]=24; 
            TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=1 ; TradeTimeBuffer[3][OH2]=22 ; TradeTimeBuffer[3][CH2]=24; 
            TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=1 ; TradeTimeBuffer[4][OH2]=22 ; TradeTimeBuffer[4][CH2]=24;
            }
         if (TradeTimeChoise==1)
            {
            //запонение буфера торгового времени (оптимальные настройки)
            TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=20 ; TradeTimeBuffer[0][CH2]=24; 
            TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=2 ; TradeTimeBuffer[1][OH2]=18 ; TradeTimeBuffer[1][CH2]=24; 
            TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=0 ; TradeTimeBuffer[2][OH2]=21 ; TradeTimeBuffer[2][CH2]=24; 
            TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=6 ; TradeTimeBuffer[3][OH2]=20 ; TradeTimeBuffer[3][CH2]=24; 
            TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=3 ; TradeTimeBuffer[4][OH2]=22 ; TradeTimeBuffer[4][CH2]=24;
            }
         result=true;
         }
      }
   if (AccountCompany()=="Private Consulting Corp.")
      {
      if (Symbol()=="EURCHF" && Period()==PERIOD_M1)
         {
         ChannelBars=1; CheckTimeBar=false; EqualBars=false;
         if (EachDayHourSettings) {OpenHour1=0; CloseHour1=1; OpenHour2=23; CloseHour2=0;}
         if (TradeTimeChoise==0)
            {
            //запонение буфера торгового времени (фиксированные настройки)
            TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=23 ; TradeTimeBuffer[0][CH2]=24; 
            TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=1 ; TradeTimeBuffer[1][OH2]=23 ; TradeTimeBuffer[1][CH2]=24; 
            TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=1 ; TradeTimeBuffer[2][OH2]=23 ; TradeTimeBuffer[2][CH2]=24; 
            TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=1 ; TradeTimeBuffer[3][OH2]=23 ; TradeTimeBuffer[3][CH2]=24; 
            TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=1 ; TradeTimeBuffer[4][OH2]=23 ; TradeTimeBuffer[4][CH2]=24;
            }
         if (TradeTimeChoise==1)
            {
            //запонение буфера торгового времени (оптимальные настройки)
            TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=0 ; TradeTimeBuffer[0][OH2]=21 ; TradeTimeBuffer[0][CH2]=24; 
            TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=1 ; TradeTimeBuffer[1][OH2]=23 ; TradeTimeBuffer[1][CH2]=24; 
            TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=0 ; TradeTimeBuffer[2][OH2]=23 ; TradeTimeBuffer[2][CH2]=24; 
            TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=0 ; TradeTimeBuffer[3][OH2]=22 ; TradeTimeBuffer[3][CH2]=24; 
            TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=6 ; TradeTimeBuffer[4][OH2]=24 ; TradeTimeBuffer[4][CH2]=24;
            }
         if (TradeTimeChoise>1)
            {
            //запонение буфера торгового времени (максимальная прибыль)
            TradeTimeBuffer[0][OH1]=0 ; TradeTimeBuffer[0][CH1]=1 ; TradeTimeBuffer[0][OH2]=21 ; TradeTimeBuffer[0][CH2]=24; 
            TradeTimeBuffer[1][OH1]=0 ; TradeTimeBuffer[1][CH1]=7 ; TradeTimeBuffer[1][OH2]=23 ; TradeTimeBuffer[1][CH2]=24; 
            TradeTimeBuffer[2][OH1]=0 ; TradeTimeBuffer[2][CH1]=0 ; TradeTimeBuffer[2][OH2]=23 ; TradeTimeBuffer[2][CH2]=24; 
            TradeTimeBuffer[3][OH1]=0 ; TradeTimeBuffer[3][CH1]=7 ; TradeTimeBuffer[3][OH2]=21 ; TradeTimeBuffer[3][CH2]=24; 
            TradeTimeBuffer[4][OH1]=0 ; TradeTimeBuffer[4][CH1]=8 ; TradeTimeBuffer[4][OH2]=24 ; TradeTimeBuffer[4][CH2]=24;
            }
         result=true;
         }
      }
return(result);}

0

2

test

0