Советник не работает на другой машине

 

Переношу советник на другой компьютер, и он перестаёт работать.

Переношу и исходник и исполнительный файл. Перекомпилирую, ошибок нет.

Пытаюсь прогнать в тестере, советник не видит открытые позиции.

Что не так? Спасибо.

 
Ledockoll:

Переношу советник на другой компьютер, и он перестаёт работать.

Переношу и исходник и исполнительный файл. Перекомпилирую, ошибок нет.

Пытаюсь прогнать в тестере, советник не видит открытые позиции.

Что не так? Спасибо.

В тестере используете какую валюту? 

 
Vladimir Karputov #:

В тестере используете какую валюту? 

USD

 
Ledockoll #:

USD

Символ выставляете в тестере тоже с валютой USD? Плечо не забыли поставить 1:100? Журнал вообще читаете - смотрите ошибки?

 
Vladimir Karputov #:

Символ выставляете в тестере тоже с валютой USD? Плечо не забыли поставить 1:100? Журнал вообще читаете 

Символ EURUSD, плечо 1:100, в журнале только об открытии позиций, пока не кончатся средства. Все позиции открываются на первом же сигнале, сов не видит, что позиции уже есть, также не обрабатывает их. Не закрывает и не модифицирует. 

Использую: position.SelectByIndex(i)

 
Ledockoll #:

Символ EURUSD, плечо 1:100, в журнале только об открытии позиций, пока не кончатся средства. Все позиции открываются на первом же сигнале, сов не видит, что позиции уже есть, также не обрабатывает их. Не закрывает и не модифицирует. 

Использую: position.SelectByIndex(i)

Давайте свой код и настройки и параметры тестера.

 
Vladimir Karputov #:

Давайте свой код и настройки и параметры

Какой то конкретный фрагмент нужен, или весь код выложить? Он длинный. Или исходник?

 
Ledockoll #:

Какой то конкретный фрагмент нужен, или весь код выложить? Он длинный. Или исходник?

Сами то как думаете? :) 

 
Vladimir Karputov #:

Сами то как думаете

Могу лишь предположить, что нужно выложить весь код...

 
Ledockoll #:

Могу лишь предположить, что нужно выложить весь код...

MQL5 Код и настройки и параметры тестера.

 
#property strict    "COBRA"
#property version   "1.0"

#include <Trade\AccountInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\OrderInfo.mqh>

input int    MAGIC        = 111;
input int    Size         = 70;
input int    StopLoss     = 150;
input int    Add          = 2;
input int    MaxSpread    = 50;
input double Risk         = 0.1;
input string TimeStart    = "0:00"; // start pause time
input string TimeEnd      = "0:00"; // end of pause
input int    depth        = 2;
CAccountInfo   account;                    // account info wrapper
CSymbolInfo    m_symbol;                   // symbol info object
CTrade         ExtTrade;
CPositionInfo  position;
COrderInfo     order;                      // pending orders object
datetime StartPause,EndPause;
double buff_stoch_main[];           // stoch_currentastic for indicator main buffer
double buff_stoch_signal[];         // stoch_currentastic for indicator signal buffer
int    handle_stoch=0;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   handle_stoch=iStochastic(_Symbol, _Period, 5, 3, 3, MODE_SMA, STO_CLOSECLOSE);
   if(handle_stoch==INVALID_HANDLE)
     {
      printf("Error creating Stochastic indicator");
      return(INIT_FAILED);
     }
   ArraySetAsSeries(buff_stoch_main,true);
   ArraySetAsSeries(buff_stoch_signal,true);
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int PositionsTotalBySymbol(string symbol)
  {
   int total=0;
   if((ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE)==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
      //--- пройдем по всем позициям
      for(int i=PositionsTotal()-1; i>=0; i--)
         if(position.SelectByIndex(i))
            if(MAGIC==PositionGetInteger(POSITION_MAGIC) && PositionGetString(POSITION_SYMBOL)==_Symbol)
              {
               if(_Symbol==symbol)
                  total++;
              }
   return(total);
  }
//+------------------------------------------------------------------+
//| Контроль позиций                                                 |
//+------------------------------------------------------------------+
int PositionsTotalByType(long const position_type)
  {
   int total=0;
   if((ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE)==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
      //--- пройдем по всем позициям
      for(int i=PositionsTotal()-1; i>=0; i--)
         if(position.SelectByIndex(i))
            if(MAGIC==PositionGetInteger(POSITION_MAGIC) && PositionGetString(POSITION_SYMBOL)==_Symbol)
              {
               if(position.PositionType()==position_type)
                  total++;
              }
//---
   return(total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Volume(string symbol)
  {
   double lot=0.0;
   double procent=0.0;
   double balans=AccountInfoDouble(ACCOUNT_BALANCE);
   double tc = SymbolInfoDouble(symbol,SYMBOL_TRADE_CONTRACT_SIZE);
   double tv = SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_VALUE_LOSS);
   double point=SymbolInfoDouble(symbol,SYMBOL_POINT);
   double LotStep=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
   procent=(balans/100.0)*Risk;
   switch((ENUM_SYMBOL_CALC_MODE)SymbolInfoInteger(symbol,SYMBOL_TRADE_CALC_MODE))
     {
      case SYMBOL_CALC_MODE_FOREX:
         if(StopLoss!=0 && tv!=0)
            lot=procent/(StopLoss*tv);
         break;
      case SYMBOL_CALC_MODE_EXCH_STOCKS:
         if(StopLoss!=0 && point!=0 && tc!=0)
            lot=procent/(StopLoss*point*tc);
         break;
     }
   return(NormalizeVolume(symbol,lot));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double NormalizeVolume(string symbol, double lot)
  {
   double MinLot=SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);
   double MaxLot=SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
   double volume_step=SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
   int volume_digits=(int)(MathLog(1.0/volume_step)/MathLog(10.0));
   if(lot<MinLot)
      lot=MinLot;
   if(lot>MaxLot)
      lot=MaxLot;
   return(NormalizeDouble(lot, volume_digits));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double PriceLastPos(string symbol="", int type=-1)
  {
   long oot=0;
   double   oop=-1;
   int      i, total=PositionsTotal();
   if(symbol=="0")
      symbol=_Symbol;
   for(i=0; i<total; i++)
     {
      if(position.SelectByIndex(i))
        {
         if(PositionGetString(POSITION_SYMBOL)==symbol)
           {
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY || PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
              {
               if(type<0 || PositionGetInteger(POSITION_TYPE)==type)
                 {
                  if(PositionGetInteger(POSITION_MAGIC)==MAGIC)
                    {
                     if(oot<OpenTimePosition())
                       {
                        oot=OpenTimePosition();
                        oop=PositionGetDouble(POSITION_PRICE_OPEN);
                       }
                    }
                 }
              }
           }
        }
     }
   return(oop);
  }
//+------------------------------------------------------------------+
//| Open Order Time                                                  |
//+------------------------------------------------------------------+
long OpenTimePosition(long const position_type=-1)
  {
   long oot=-1;
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(position.SelectByIndex(i))
         if(PositionGetInteger(POSITION_MAGIC)==MAGIC && PositionGetString(POSITION_SYMBOL)==_Symbol)
            if(position_type<=0 || PositionGetInteger(POSITION_TYPE)==position_type)
              {
               if(oot<PositionGetInteger(POSITION_TIME_MSC))
                  oot=PositionGetInteger(POSITION_TIME_MSC);
              }
   return(oot);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
long TypeLastOpenPos(string symbol)
  {
   long oot=0;
   long type=-1;
   if(symbol=="0")
      symbol=_Symbol;
   for(int i=PositionsTotal()-1; i>=0; i--)
     {
      if(position.SelectByIndex(i))
        {
         if((PositionGetString(POSITION_SYMBOL)==symbol) && (PositionGetInteger(POSITION_MAGIC)==MAGIC))
           {
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY || PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
              {
               if(oot<OpenTimePosition())
                 {
                  oot=OpenTimePosition();
                  type=PositionGetInteger(POSITION_TYPE);
                 }
              }
           }
        }
     }
   return(type);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double Bid=SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double Ask=SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   long   TB=iTime(_Symbol,_Period,0)*1000;
   double POB=iOpen(_Symbol,_Period,0);
   double P=SymbolInfoDouble(_Symbol,SYMBOL_POINT);
   long Spread=SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);
   double max_volume=SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_LIMIT);
//--- sell conditions
   if((POB-Ask)/P>=Size && OpenTimePosition(POSITION_TYPE_SELL)<TB)
     {
      //--- check for free money
      double free_margin_check = account.FreeMarginCheck(_Symbol, ORDER_TYPE_SELL, Volume(_Symbol), Bid);
      double margin_check      = account.MarginCheck(_Symbol, ORDER_TYPE_SELL, Volume(_Symbol), Bid);
      if(free_margin_check<margin_check)
        {
         //--- сообщим об ошибке и вернем false
         Print("Not enough money for ", EnumToString(POSITION_TYPE_SELL), " ", Volume(_Symbol), " ", _Symbol);
         return;
        }
      else
        {
         //--- open position
         if(ExtTrade.PositionOpen(_Symbol,(ENUM_ORDER_TYPE)POSITION_TYPE_SELL, Volume(_Symbol), Bid,0,0, NULL))
            printf("The order is placed.Parameters : Spread=%f", Spread, 0, 0);
         else
           {
            printf("Error installation SELL order by %s : '%s'", _Symbol, ExtTrade.ResultComment());
            printf("Placement parameters : price=%f", Bid, 0, 0);
            return;
           }
        }
     }
//--- buy conditions
   if((Bid-POB)/P>=Size && OpenTimePosition(POSITION_TYPE_BUY)<TB)
     {
      double free_margin_check = account.FreeMarginCheck(_Symbol, ORDER_TYPE_BUY, Volume(_Symbol), Ask);
      double margin_check      = account.MarginCheck(_Symbol, ORDER_TYPE_BUY, Volume(_Symbol), Ask);
      if(free_margin_check<margin_check)
        {
         //--- сообщим об ошибке и вернем false
         Print("Not enough money for ", EnumToString(POSITION_TYPE_BUY), " ", Volume(_Symbol), " ", _Symbol);
         return;
        }
      else
        {
         //--- open position
         if(ExtTrade.PositionOpen(_Symbol,(ENUM_ORDER_TYPE)POSITION_TYPE_BUY, Volume(_Symbol), Ask, 0,0,NULL))
            printf("The order is placed.Parameters : Spread=%f", Spread, 0, 0);
         else
           {
            printf("Error installation BUY order by %s : '%s'", _Symbol, ExtTrade.ResultComment());
            printf("Placement parameters : price=%f", Ask, 0, 0);
            return;
           }
        }
     }
   return;
  }
//+------------------------------------------------------------------+
//| Check for position SL                                            |
//+------------------------------------------------------------------+
void SL(void)
  {
   double Bid=SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double Ask=SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double sl=-1;
   int    total=PositionsTotal();
     {
      for(int i=total-1; i>=0; i--)
         if(position.SelectByIndex(i))
            if(MAGIC==PositionGetInteger(POSITION_MAGIC) && PositionGetString(POSITION_SYMBOL)==_Symbol)
              {
               if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
                 {
                  sl=NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN)-_Point*StopLoss, _Digits);
                  //--- check
                  if(Bid-sl>SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL)*_Point && Bid>sl)
                     if(PositionGetDouble(POSITION_SL)==0 && PositionGetDouble(POSITION_PRICE_OPEN)-sl>SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL)*_Point)
                       {
                        //--- modify position
                        if(ExtTrade.PositionModify(PositionGetInteger(POSITION_TICKET), sl, 0))
                           printf("Long position by %s to be modified,SL=%f", Symbol(), sl);
                        else
                          {
                           printf("Error modifying position by %s : '%s'", Symbol(), ExtTrade.ResultComment());
                           printf("Modify parameters : SL=%f", sl, 0);
                          }
                        //--- modified and must exit from expert
                       }
                 }
               if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
                 {
                  sl=NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN)+_Point*StopLoss, _Digits);
                  //--- check
                  if(sl-Ask>SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL)*_Point && Ask<sl)
                     if(PositionGetDouble(POSITION_SL)==0 && sl-PositionGetDouble(POSITION_PRICE_OPEN)>SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL)*_Point)
                       {
                        //--- modify position
                        if(ExtTrade.PositionModify(PositionGetInteger(POSITION_TICKET), sl, 0))
                           printf("Short position by %s to be modified,SL=%f", Symbol(), sl);
                        else
                          {
                           printf("Error modifying position by %s : '%s'", Symbol(), ExtTrade.ResultComment());
                           printf("Modify parameters : SL=%f", sl, 0);
                          }
                        //--- modified and must exit from expert
                       }
                 }
              }
     }
   return;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CloseFance()
  {
   int    total=PositionsTotal();
   long   T=SymbolInfoInteger(_Symbol,SYMBOL_TIME_MSC);
   double P=SymbolInfoDouble(_Symbol,SYMBOL_POINT);
   long Spread=SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);
   double Bid=SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double Ask=SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double  stoch_current;
   double  stoch_previous;
   double  signal_stoch;
   double  signal_stoch_prev;
   stoch_current     =buff_stoch_main[0];
   stoch_previous    =buff_stoch_main[1];
   signal_stoch      =buff_stoch_signal[0];
   signal_stoch_prev =buff_stoch_signal[1];
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(position.SelectByIndex(i))
         if(MAGIC==PositionGetInteger(POSITION_MAGIC) && PositionGetString(POSITION_SYMBOL)==_Symbol)
           {
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
              {
               ulong  ticket=PositionGetInteger(POSITION_TICKET);
                 {
                  if(Bid>PositionGetDouble(POSITION_PRICE_OPEN))
                     if(stoch_current<signal_stoch && stoch_previous>signal_stoch_prev && stoch_current>80 &&
                        (Bid-PositionGetDouble(POSITION_PRICE_OPEN))/P>Spread)
                       {
                        if(ExtTrade.PositionClose(ticket))
                           printf("Long position by %s to be closed", Symbol());
                        else
                           Print("Error closing position by %s :", GetLastError());
                        //--- processed and cannot be modified
                       }
                 }
              }
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
              {
               ulong  ticket=PositionGetInteger(POSITION_TICKET);
                 {
                  if(Ask<PositionGetDouble(POSITION_PRICE_OPEN))
                     if(stoch_current>signal_stoch && stoch_previous<signal_stoch_prev && stoch_current<20 &&
                        (PositionGetDouble(POSITION_PRICE_OPEN)-Ask)/P>Spread)
                       {
                        if(ExtTrade.PositionClose(ticket))
                           printf("Long position by %s to be closed", Symbol());
                        else
                           Print("Error closing position by %s :", GetLastError());
                        //--- processed and cannot be modified
                       }
                 }
              }
           }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   CopyBuffer(handle_stoch,0,0,2,buff_stoch_main);
   CopyBuffer(handle_stoch,1,0,2,buff_stoch_signal);
     {
      if(PositionsTotalBySymbol(_Symbol)>0)
        {
         SL();
         CloseFance();
        }
     }
   StartPause = StringToTime(TimeStart);
   EndPause   = StringToTime(TimeEnd);
   if((StartPause < EndPause && (TimeCurrent() > StartPause &&  TimeCurrent() < EndPause))
      || (StartPause > EndPause && (TimeCurrent() > StartPause ||  TimeCurrent() < EndPause)))
     {
      Comment("Pause in the work of the adviser");
      return;
     }
   CheckForOpen();
  }
//+------------------------------------------------------------------+
Причина обращения: