My expert does not work at windows 10

Ahmed Abd El Aziz
234

Hello,


I created an expert depending on custom indicator. it is work perfectly at windows 7 but dose not work at window 10


Can anyone tells me the reason and how to fix this problem?


input int MagicNumber=10001;
input double Lots =0.1;
input double StopLoss=0;
input double TakeProfit=0;
input int TrailingStop=0;
bool CloseOpposite;
const string IndicatorName="(My_Heckin_ashi)";
const int Handle_Buy=0;
const int Handle_Sell=1;
int Handle;
double BufferBuy[3];
double BufferSell[3];

//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+

 ENUM_MA_METHOD MethodMigrate(int method)
  {
   switch(method)
     {
      case 0: return(MODE_SMA);
      case 1: return(MODE_EMA);
      case 2: return(MODE_SMMA);
      case 3: return(MODE_LWMA);
      default: return(MODE_SMA);
     }
  }
  
ENUM_STO_PRICE StoFieldMigrate(int field)
  {
   switch(field)
     {
      case 0: return(STO_LOWHIGH);
      case 1: return(STO_CLOSECLOSE);
      default: return(STO_LOWHIGH);
     }
  }
ENUM_APPLIED_PRICE PriceMigrate(int price)
  {
   switch(price)
     {
      case 1: return(PRICE_CLOSE);
      case 2: return(PRICE_OPEN);
      case 3: return(PRICE_HIGH);
      case 4: return(PRICE_LOW);
      case 5: return(PRICE_MEDIAN);
      case 6: return(PRICE_TYPICAL);
      case 7: return(PRICE_WEIGHTED);
      default: return(PRICE_CLOSE);
     }
  }

ENUM_TIMEFRAMES TFMigrate(int tf)
  {
   switch(tf)
     {
      case 0: return(PERIOD_CURRENT);
      case 1: return(PERIOD_M1);
      case 5: return(PERIOD_M5);
      case 15: return(PERIOD_M15);
      case 30: return(PERIOD_M30);
      case 60: return(PERIOD_H1);
      case 240: return(PERIOD_H4);
      case 1440: return(PERIOD_D1);
      case 10080: return(PERIOD_W1);
      case 43200: return(PERIOD_MN1);
      
      case 2: return(PERIOD_M2);
      case 3: return(PERIOD_M3);
      case 4: return(PERIOD_M4);      
      case 6: return(PERIOD_M6);
      case 10: return(PERIOD_M10);
      case 12: return(PERIOD_M12);
      case 16385: return(PERIOD_H1);
      case 16386: return(PERIOD_H2);
      case 16387: return(PERIOD_H3);
      case 16388: return(PERIOD_H4);
      case 16390: return(PERIOD_H6);
      case 16392: return(PERIOD_H8);
      case 16396: return(PERIOD_H12);
      case 16408: return(PERIOD_D1);
      case 32769: return(PERIOD_W1);
      case 49153: return(PERIOD_MN1);      
      default: return(PERIOD_CURRENT);
     }
  }
  
#define MODE_MAIN 0  
#define MODE_SIGNAL 1
#define MODE_PLUSDI 1
#define MODE_MINUSDI 2
#define MODE_OPEN 0
#define MODE_LOW 1
#define MODE_HIGH 2
#define MODE_CLOSE 3
#define MODE_VOLUME 4 
#define MODE_REAL_VOLUME 5


#define OP_BUY 0           //Buy 
#define OP_SELL 1          //Sell 
#define OP_BUYLIMIT 2      //Pending order of BUY LIMIT type 
#define OP_SELLLIMIT 3     //Pending order of SELL LIMIT type 
#define OP_BUYSTOP 4       //Pending order of BUY STOP type 
#define OP_SELLSTOP 5      //Pending order of SELL STOP type 
//---
#define MODE_TRADES 0
#define MODE_HISTORY 1
#define SELECT_BY_POS 0
#define SELECT_BY_TICKET 1
//---
#define DOUBLE_VALUE 0
#define FLOAT_VALUE 1
#define LONG_VALUE INT_VALUE
//---
#define CHART_BAR 0
#define CHART_CANDLE 1
//---
#define MODE_ASCEND 0
#define MODE_DESCEND 1
//---

#define MODE_TIME 5
#define MODE_BID 9
#define MODE_ASK 10
#define MODE_POINT 11
#define MODE_DIGITS 12
#define MODE_SPREAD 13
#define MODE_STOPLEVEL 14
#define MODE_LOTSIZE 15
#define MODE_TICKVALUE 16
#define MODE_TICKSIZE 17
#define MODE_SWAPLONG 18
#define MODE_SWAPSHORT 19
#define MODE_STARTING 20
#define MODE_EXPIRATION 21
#define MODE_TRADEALLOWED 22
#define MODE_MINLOT 23
#define MODE_LOTSTEP 24
#define MODE_MAXLOT 25
#define MODE_SWAPTYPE 26
#define MODE_PROFITCALCMODE 27
#define MODE_MARGINCALCMODE 28
#define MODE_MARGININIT 29
#define MODE_MARGINMAINTENANCE 30
#define MODE_MARGINHEDGED 31
#define MODE_MARGINREQUIRED 32
#define MODE_FREEZELEVEL 33
//---
#define EMPTY -1
#include <Trade\Trade.mqh>
CTrade  *Trade;
int OnInit() {


//      Create a pointer to a ctrade object
Trade=new CTrade();
Trade.SetExpertMagicNumber(MagicNumber);
Handle=iCustom(Symbol(),Period(),IndicatorName);
if(Handle==INVALID_HANDLE)
     {
      PrintFormat("Failed",GetLastError());
      return(INIT_FAILED);
     }
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason) {
IndicatorRelease(Handle);
}
void OnTick()
{
{
  
 }


int cnt_B = CopyBuffer(Handle,Handle_Buy,0,3,BufferBuy);
int cnt_S = CopyBuffer(Handle,Handle_Sell,0,3,BufferSell);
       
double Previous_Candle_Buy = BufferBuy[1];
double Current_Candle_Buy = BufferBuy[0];
   
double Previous_Candle_Sell = BufferSell[1];
double Current_Candle_Sell = BufferSell[0];
   

double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);

double MyPoint=_Point;
if(_Digits==2 || _Digits==5) MyPoint=_Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
if(TotalOrdersCount()==0 ) 
{
if(Previous_Candle_Buy == iLow(_Symbol, PERIOD_CURRENT,1)
&& ((((iOpen(_Symbol, PERIOD_CURRENT,0))-(StopLoss*MyPoint))<iLow(_Symbol, PERIOD_CURRENT,0))||(StopLoss==0))
&& ((((iOpen(_Symbol, PERIOD_CURRENT,0))+(TakeProfit*MyPoint))>iHigh(_Symbol, PERIOD_CURRENT,0))||(TakeProfit==0))
)
{
        if(StopLoss>0) TheStopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-StopLoss*MyPoint;
        if(TakeProfit>0) TheTakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+TakeProfit*MyPoint;
        Trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,SymbolInfoDouble(_Symbol,SYMBOL_ASK),TheStopLoss,TheTakeProfit);
        return;
}
if(Previous_Candle_Sell == iHigh(_Symbol, PERIOD_CURRENT,1)
&& ((((iOpen(_Symbol, PERIOD_CURRENT,0))+(StopLoss*MyPoint))>iHigh(_Symbol, PERIOD_CURRENT,0))||(StopLoss==0))
&& ((((iOpen(_Symbol, PERIOD_CURRENT,0))-(TakeProfit*MyPoint))<iLow(_Symbol, PERIOD_CURRENT,0))||(TakeProfit==0))
)      
{
        if(StopLoss>0) TheStopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+StopLoss*MyPoint;
        if(TakeProfit>0) TheTakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-TakeProfit*MyPoint;
        Trade.PositionOpen(_Symbol,ORDER_TYPE_SELL,Lots,SymbolInfoDouble(_Symbol,SYMBOL_BID),TheStopLoss,TheTakeProfit);
        return;
}
 }
   int posTotal=PositionsTotal();
   for(int posIndex=posTotal-1;posIndex>=0;posIndex--)
     {
      ulong ticket=PositionGetTicket(posIndex);
      if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC)==MagicNumber) 
      {
     if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
        {
              if(iADXMQL4(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,1)<iADXMQL4(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,1)
              )    //here is your close buy rule
         {
         Trade.PositionClose(ticket);
         break;
         }
       
         if(TrailingStop>0)  
              {                 
               if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN)>MyPoint*TrailingStop)
                 {
                  if(PositionGetDouble(POSITION_SL)<SymbolInfoDouble(_Symbol,SYMBOL_BID)-MyPoint*TrailingStop)
                    {
                    Trade.PositionModify(ticket,SymbolInfoDouble(_Symbol,SYMBOL_BID)-MyPoint*TrailingStop,PositionGetDouble(POSITION_TP));
                     return;
                    }
                 }
              }
        }
      
       if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
        {
              if(iADXMQL4(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,1)>iADXMQL4(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,1))    // here is your close sell rule
         {
         Trade.PositionClose(ticket);
         break;
         }
          if(TrailingStop>0)  
              {                 
               if(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(_Symbol,SYMBOL_ASK)>MyPoint*TrailingStop)
                 {
                  if(PositionGetDouble(POSITION_SL)>SymbolInfoDouble(_Symbol,SYMBOL_ASK)+MyPoint*TrailingStop)
                    {
                    Trade.PositionModify(ticket,SymbolInfoDouble(_Symbol,SYMBOL_ASK)+MyPoint*TrailingStop,PositionGetDouble(POSITION_TP));
                     return;
                    }
                 }
              }
        }
      }
     }  
    return;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double Highest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
{
   double highest=0;
   double High[];
   ArraySetAsSeries(High,true);
   int copied=CopyHigh(symbol,timeframe,start,count,High) ;
   int index=ArrayMaximum(High,0,count)+start;
   if(copied>0 && index<copied) highest=High[index];
   return(highest);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lowest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
{
   double lowest=0;
   double Low[];
   ArraySetAsSeries(Low,true);
   int copied=CopyLow(symbol,timeframe,start,count,Low);
   int index=ArrayMinimum(Low,0,count)+start;
   if(copied>0 && index<copied) lowest=Low[index];
   return(lowest);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


int TotalOrdersCount()
{
  int result=0;
  int posTotal=PositionsTotal();
   for(int posIndex=posTotal-1;posIndex>=0;posIndex--)
     {
      ulong ticket=PositionGetTicket(posIndex);
      if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC)==MagicNumber) result++;
     }  
  return (result);
}


int Hour()
{
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.hour);
}
int Minute()
{
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.min);
}

double CopyBufferMQL4(int handle,int index,int shift)
  {
   double buf[];
   switch(index)
     {
      case 0: if(CopyBuffer(handle,0,shift,1,buf)>0)
         return(buf[0]); break;
      case 1: if(CopyBuffer(handle,1,shift,1,buf)>0)
         return(buf[0]); break;
      case 2: if(CopyBuffer(handle,2,shift,1,buf)>0)
         return(buf[0]); break;
      case 3: if(CopyBuffer(handle,3,shift,1,buf)>0)
         return(buf[0]); break;
      case 4: if(CopyBuffer(handle,4,shift,1,buf)>0)
         return(buf[0]); break;
      default: break;
     }
   return(EMPTY_VALUE);
  }
  
  
double iACMQL4(string symbol,
               int tf,
               int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iAC(symbol,timeframe);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
  
  
  double iADMQL4(string symbol,
               int tf,
               int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=(int)iAD(symbol,timeframe,VOLUME_TICK);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }  
  
  double iAlligatorMQL4(string symbol,
                      int tf,
                      int jaw_period,
                      int jaw_shift,
                      int teeth_period,
                      int teeth_shift,
                      int lips_period,
                      int lips_shift,
                      int method,
                      int price,
                      int mode,
                      int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iAlligator(symbol,timeframe,jaw_period,jaw_shift,
                         teeth_period,teeth_shift,
                         lips_period,lips_shift,
                         ma_method,applied_price);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode-1,shift));
  }
  
double iADXMQL4(string symbol,
                int tf,
                int period,
                int price,
                int mode,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iADX(symbol,timeframe,period);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode,shift));
  }

double iAOMQL4(string symbol,
               int tf,
               int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iAO(symbol,timeframe);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
  double iATRMQL4(string symbol,
                int tf,
                int period,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iATR(symbol,timeframe,period);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
  
 double iBearsPowerMQL4(string symbol,
                       int tf,
                       int period,
                       int price,
                       int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iBearsPower(symbol,timeframe,period);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
  
 double iBullsPowerMQL4(string symbol,
                       int tf,
                       int period,
                       int price,
                       int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iBullsPower(symbol,timeframe,period);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
  
  double iBandsMQL4(string symbol,
                  int tf,
                  int period,
                  double deviation,
                  int bands_shift,
                  int method,
                  int mode,
                  int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   int handle=iBands(symbol,timeframe,period,
                     bands_shift,deviation,ma_method);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode,shift));
  }
  double iCCIMQL4(string symbol,
                int tf,
                int period,
                int price,
                int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iCCI(symbol,timeframe,period,price);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
  

double iDeMarkerMQL4(string symbol,
                     int tf,
                     int period,
                     int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   int handle=iDeMarker(symbol,timeframe,period);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,0,shift));
  }
  double EnvelopesMQL4(string symbol,
                     int tf,
                     int ma_period,
                     int method,
                     int ma_shift,
                     int price,
                     double deviation,
                     int mode,
                     int shift)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   ENUM_MA_METHOD ma_method=MethodMigrate(method);
   ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
   int handle=iEnvelopes(symbol,timeframe,
                         ma_period,ma_shift,ma_method,
                         applied_price,deviation);
   if(handle<0)
     {
      return(-1);
     }
   else
      return(CopyBufferMQL4(handle,mode-1,shift));
  }
  

Amine Abed
301
Amine Abed  

The code compiles fine,


What do you mean by it doesn't work ? Does it show some errors ? Does it do anything strange ?

R4tna C
415
R4tna C  
Ahmed Abd El Aziz:

Hello,


I created an expert depending on custom indicator. it is work perfectly at windows 7 but dose not work at window 10


Can anyone tells me the reason and how to fix this problem?


Have you tried it on another Win 10 PC ?

William Roeder
28322
William Roeder  
Ahmed Abd El Aziz: it is work perfectly at windows 7 but dose not work at window 10
  1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

    Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

  2. Windows 7 extended support period begins in January 2020 when Windows 7 support ended officially, and it ends in January 2023 for good.
              New MetaTrader 4 Platform build 1220 - MQL4 programming forum - Page 3 #26 (2020)

  3. Your code
       switch(index)
         {
          case 0: if(CopyBuffer(handle,0,shift,1,buf)>0)
             return(buf[0]); break;
          case 1: if(CopyBuffer(handle,1,shift,1,buf)>0)
             return(buf[0]); break;
          case 2: if(CopyBuffer(handle,2,shift,1,buf)>0)
             return(buf[0]); break;
          case 3: if(CopyBuffer(handle,3,shift,1,buf)>0)
             return(buf[0]); break;
          case 4: if(CopyBuffer(handle,4,shift,1,buf)>0)
             return(buf[0]); break;
          default: break;
         }
    Simplified
       if(CopyBuffer(handle,index,shift,1,buf)>0)
             return(buf[0]);
  4.    int handle=iAC(symbol,timeframe);
       ⋮
       int handle=(int)iAD(symbol,timeframe,VOLUME_TICK);
       ⋮
       int handle=iAlligator(symbol,timeframe,jaw_period,jaw_shift,
                             teeth_period,teeth_shift,
                             lips_period,lips_shift,
                             ma_method,applied_price);
       ⋮
       int handle=iADX(symbol,timeframe,period);
       ⋮
       int handle=iAO(symbol,timeframe);
       ⋮
       int handle=iATR(symbol,timeframe,period);
       ⋮
       int handle=iBearsPower(symbol,timeframe,period);
       ⋮
       int handle=iBullsPower(symbol,timeframe,period);
       ⋮
       int handle=iBands(symbol,timeframe,period,
                         bands_shift,deviation,ma_method);
       ⋮
       int handle=iCCI(symbol,timeframe,period,price);
       ⋮
       int handle=iDeMarker(symbol,timeframe,period);
       ⋮
       int handle=iEnvelopes(symbol,timeframe,
                             ma_period,ma_shift,ma_method,
                             applied_price,deviation);
       if(handle<0) return(-1);
       return(CopyBufferMQL4(handle,mode-1,shift));
      }
     

    Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

Ahmed Abd El Aziz
234
Ahmed Abd El Aziz  

After i press "OK" it is disappearing




Ahmet Metin Yilmaz
10337
Ahmed Abd El Aziz #:

After i press "OK" it is disappearing




Custom indicator name. If the name starts with the reverse slash '\', the EX5 indicator file is searched for relative to the MQL5\Indicators indicator root directory. Thus, when calling iCustom(Symbol(), Period(), "\FirstIndicator"...), the indicator is downloaded as MQL5\Indicators\FirstIndicator.ex5. If the path contains no file, the error 4802 (ERR_INDICATOR_CANNOT_CREATE) occurs.

const string IndicatorName="(My_Heckin_ashi)";

is that your indicator names?

what is written in your platform expert and journal tab? Nothing?