uninit reason 0 error - page 2

 
Carlache24:
I Know that Script , I had same problem, what you have to do is increase the Slippage in the Include.mqh that your script should be calling and that's it!!

how to do this?

 
Luandre Ezra:
Hi, I'm trying to initialize my script but it is failed with an error message that it was uninitialized with a reason 0. I looked into the documentation and find the description doesn't tell me anything about the problem. Someone know how to fix this?
Did you figure out the problem in your script?
 
GOLDCASH_:
Did you figure out the problem in your script?

Answers already given in this topic.

 
Keith Watford:

Answers already given in this topic.

Maybe you can assist me. I am getting the same frustrating uninit reason 0. I’ve tried moving my slippage up ten pips, didn’t work. I read the manual and traced it back to the OnDeinit() function being called reason being:


before reinitialization due to the change of a symbol or chart period, to which the mql4 program is attached;


before reinitialization due to the change of input parameters;

before unloading the mql4 program.


However I can not seem to locate the mistake in either situation.  

It loaded successfully

It ran the global inputs successfully 

It initialized successfully 

It sent my price alert successfully 

It sent my entry price, stop loss, and take profit price successfully

then it called the  OnDeinit() function

Followed by a uninit reason 0

Follwed by a removal.

Attached it the script along with the function include file.

Thank You

#include <CustomH2H3L2L3Function.mqh>

int magicNB = 77777;
int bbPeriod = 20;
int band1Std = 1;
int band2Std = 4;
input double riskPerTrade = 0.02;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

void OnStart()
  {
//---
   double bbLower1 = iBands(NULL,0,bbPeriod,band1Std,0,PRICE_CLOSE,MODE_LOWER,0);
   double bbUpper1 = iBands(NULL,0,bbPeriod,band1Std,0,PRICE_CLOSE,MODE_UPPER,0);
   double bbMid = iBands(NULL,0,bbPeriod,band1Std,0,PRICE_CLOSE,0,0);
   
   double bbLower2 = iBands(NULL,0,bbPeriod,band2Std,0,PRICE_CLOSE,MODE_LOWER,0);
   double bbUpper2 = iBands(NULL,0,bbPeriod,band2Std,0,PRICE_CLOSE,MODE_UPPER,0);
   
   if(!CheckIfOpenOrdersByMagicNB(magicNB))
   {
   
   if(Ask < bbLower1)//buying
   {
      Alert("Price is bellow bbLower1, Sending buy order");
      double stopLossPrice = NormalizeDouble(bbLower2,Digits);
      double takeProfitPrice = NormalizeDouble(bbMid,Digits);
      Alert("Entry Price = " + Ask);
      Alert("Stop Loss Price = " + stopLossPrice);
      Alert("Take Profit Price = " + takeProfitPrice);
      
      double lotsize = OptimalLotSize(riskPerTrade,Ask,stopLossPrice);
      
      int orderID = OrderSend(NULL,OP_BUYLIMIT,lotsize,Ask,50,stopLossPrice,takeProfitPrice,NULL,magicNB);
      if(orderID < 0) Alert("order rejected. Order error: " + GetLastError());
   }
   else if(Bid > bbUpper1)//shorting
   {
      Alert("Price is above bbUpper1, Sending short order");
      double stopLossPrice = NormalizeDouble(bbUpper2,Digits);
      double takeProfitPrice = NormalizeDouble(bbMid,Digits);
      Alert("Entry Price = " + Bid);
      Alert("Stop Loss Price = " + stopLossPrice);
      Alert("Take Profit Price = " + takeProfitPrice);
      
      double lotsize = OptimalLotSize(riskPerTrade,Bid,stopLossPrice);
          
          int orderID = OrderSend(NULL,OP_SELLLIMIT,lotsize,Bid,50,stopLossPrice,takeProfitPrice,NULL,magicNB);
          if(orderID < 0) Alert("order rejected. Order error: " + GetLastError());
   }
  }
  
   
 }
  

//+------------------------------------------------------------------+
//|                                       CustomH2H3L2L3Function.mqh |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

double GetPipValue()
 {
      if(_Digits >=4)
   {
   return 0.0001;
   }
      else
   {
   return 0.01;
   }

 }

void DayOfWeekAlert()
  {
   Alert("");
   
   int dayOfWeek = DayOfWeek();
   
   switch (dayOfWeek)
   
  {
   case 1: Alert("We are Monday. Lets aim to enter new trades.");break;
   case 2: Alert("We are Tuesday. Lets aim to enter new trades and close existing trades.");break;
   case 3: Alert("We are Wednesday. Lets aim to enter new trades and close existing trades.");break;
   case 4: Alert("We are Thursday. Lets aim to enter new trades and close existing trades.");break;
   case 5: Alert("We are Friday. Close all existing trades.");break;
   case 6: Alert("Its the weekend. No trading.");break;
   case 0: Alert("Its the weekend. No trading.");break;
   default: Alert("Error. No such day in week.");
    
   }
  }
  
double GetStopLossPrice(bool bIsLongPosition, double entryPrice, int maxLossInPips)
  {
   double stopLossPrice;
   if (bIsLongPosition)
    {
      stopLossPrice = entryPrice - maxLossInPips * 0.0001;  
    }
   else
    {
      stopLossPrice = entryPrice + maxLossInPips * 0.0001;  
    }
    return stopLossPrice;
 }
 
 bool IsTradingAllowed()
{
   if(!IsTradeAllowed())
   {
      Alert("Expert Advisor is NOT Allowed to Trade. Check AutoTrading.");
            return false;
         }
         
         if(!IsTradeAllowed(Symbol(),TimeCurrent()))
         {
           Alert("Trading NOT Allowed for specific Symbol and Time.");
           return false;
         }
         
           return true; 
}

double OptimalLotSize(double maxRiskPrc, int maxLossInPips)
{

  double accEquity = AccountEquity();
  Alert("accEquity: " + accEquity);
  
  double lotSize = MarketInfo(NULL,MODE_LOTSIZE);
  ("lotSize: " + lotSize);
  
  double tickValue = MarketInfo(NULL,MODE_TICKVALUE);
  
  if(Digits <= 3)
  {
   tickValue = tickValue /100;
  }
  
  ("tickValue: " + tickValue);
  
  double maxLossDollar = accEquity * maxRiskPrc;
  ("maxLossDollar: " + maxLossDollar);
  
  double maxLossInQuoteCurr = maxLossDollar / tickValue;
  ("maxLossInQuoteCurr: " + maxLossInQuoteCurr);
  
  double optimalLotSize = NormalizeDouble(maxLossInQuoteCurr /(maxLossInPips * GetPipValue())/lotSize,2);
  
  return optimalLotSize;
 
}


double OptimalLotSize(double maxRiskPrc, double entryPrice, double stopLoss)
{
   int maxLossInPips = MathAbs(entryPrice - stopLoss)/GetPipValue();
   return OptimalLotSize(maxRiskPrc,maxLossInPips);
}


bool CheckIfOpenOrdersByMagicNB(int magicNB)
{
   int openOrders = OrdersTotal();
   
   for(int i = 0; i < openOrders; i++)
   {
      if(OrderSelect(i,SELECT_BY_POS)==true)
   {
      if(OrderMagicNumber() == magicNB) Alert("This expert advisor already sent an order");
   {
   return true;
   }
  }
 }
 return false;
 }
 

  

   

 



Input Variables - Variables - Language Basics - MQL4 Reference
Input Variables - Variables - Language Basics - MQL4 Reference
  • docs.mql4.com
Input Variables - Variables - Language Basics - MQL4 Reference
 
GOLDCASH_:

However I can not seem to locate the mistake in either situation.  

It loaded successfully

It ran the global inputs successfully 

It initialized successfully 

It sent my price alert successfully 

It sent my entry price, stop loss, and take profit price successfully

then it called the  OnDeinit() function

Followed by a uninit reason 0

Follwed by a removal.

This has already been explained!

It is a script, it is doing what it is supposed to do.

Why do you expect something different?

 
GOLDCASH_:

Do not double post!!!

I have deleted your other topic.

 
Keith Watford:

This has already been explained!

It is a script, it is doing what it is supposed to do.

Why do you expect something different?

thank you for the answer how hard was that lmao!?
Reason: