Errors, bugs, questions - page 3076

 
Vladimir Karputov #:

First question: Did you write this code yourself and give these variable names?

Yes.

 
Yury Lemeshev #:

Yes.

Very strange names - looks like decompiled. Please show more of your other code - code you wrote yourself.

 
Vladimir Karputov #:

Very strange names - looks like decompiled. Please show more of your other code - code you wrote yourself.

int intLevelOrderProfit()
   {
   int iLOP,iL;
   ProfitCycle=GlobalVariableGet("["+MAGICs+"] Profit Cycle");
   iL=GlobalVariableGet("["+MAGICs+"] Level Orders")-1;
   ArrayResize(LOP,GlobalVariableGet("["+MAGICs+"] Level Orders")-1);
   int LOPc;LOPc=0;
   for(i=0; i<GlobalVariablesTotal(); i++)
      {
      if(StringFind(GlobalVariableName(i),"["+MAGICs+"] Level Order #")!=-1)
         {
         iLOP=GlobalVariableGet(GlobalVariableName(i));
         if(iLOP<GlobalVariableGet("["+MAGICs+"] Level Orders"))
            {
            /*MT5*/if(PositionSelectByTicket(StringSubstr(GlobalVariableName(i),(2+StringFind(GlobalVariableName(i)," #",0))))==true)
            ///*MT4*/if(OrderSelect(StringSubstr(GlobalVariableName(i),(2+StringFind(GlobalVariableName(i)," #",0))),SELECT_BY_TICKET,MODE_TRADES)==true)
               {
               LOPc++;
               ArrayFill(LOP,(iLOP-1)*5+0,1,MAGICs);
               /*MT5*/ArrayFill(LOP,(iLOP-1)*5+1,1,LOP[iLOP-1][1]+PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP));
               ///*MT4*/ArrayFill(LOP,(iLOP-1)*5+1,1,LOP[iLOP-1][1]+OrderProfit()+OrderSwap()+OrderCommission());
               if(LOPc==1){ArrayFill(LOP,((iLOP-1)*5)+3,1,StringSubstr(GlobalVariableName(i),(2+StringFind(GlobalVariableName(i)," #",0))));}
               if(LOPc==2){ArrayFill(LOP,((iLOP-1)*5)+4,1,StringSubstr(GlobalVariableName(i),(2+StringFind(GlobalVariableName(i)," #",0))));}
               if(LOPc==2){LOPc=0;}
               }
            }
         }
      }
   if(ArraySize(LOP)>0)
      {
      int iLOPP;
      iLOPP=Profit;
      if(CloseLevelOrders==ECLO2){iLOPP=Profit*(GlobalVariableGet("["+MAGICs+"] Level Orders"));}
      for(i=0; i<ArraySize(LOP)/5; i++)
         {
         if(NormalizeDouble(LOP[i][0],0)==MAGICs)
            {
            if((-LOP[i][1])<(-iLOPP*2) && (-LOP[i][1])<(-LOP[i][2]*2))
               {ArrayFill(LOP,(i*5)+2,1,(LOP[i][1])/2);}
            if(LOP[i][1]>iLOPP && LOP[i][1]<=LOP[i][2])
               {
               if(LOP[i][3]>0)
                  {
                  ticket=LOP[i][3];Print("-673- Closing by profit "+(LOP[i][2])+" ticket "+ticket);intClosePosition();CloseMode="CloseOneMagic";intDeleteGlobalVariables();GlobalVariableSet("["+MAGICs+"] Profit Cycle",LOP[i][2]/2+ProfitCycle);
                  }
               if(LOP[i][4]>0)
                  {
                  ticket=LOP[i][4];Print("-677- Closing by profit "+(LOP[i][2])+" ticket "+ticket);intClosePosition();CloseMode="CloseOneMagic";intDeleteGlobalVariables();GlobalVariableSet("["+MAGICs+"] Profit Cycle",LOP[i][2]/2+ProfitCycle);
                  }
               GlobalVariableSet("["+MAGICs+"] INDEX",GlobalVariableGet("["+MAGICs+"] INDEX")/DeMultiplicationVoltage); //Edition 26082021
               ArrayFill(LOP,(i*5)+2,1,0);
               }
            }
         ArrayFill(LOP,(i*5)+0,1,0);
         ArrayFill(LOP,(i*5)+1,1,0);
         ArrayFill(LOP,(i*5)+3,1,0);
         ArrayFill(LOP,(i*5)+4,1,0);
         }
      }
   return(0);
   }
 
Vladimir Karputov #:

Very strange names - looks like decompiled. Please show more of your other code - the code you wrote yourself.

I divide everything in my Expert Advisor into functions, iFunctionExample(), and the variables iFE1,iFE2,iFE3 for int, and dFE1, dFE2, dFE3 for double. This makes it easier for me to understand where everything comes from.

 
Yury Lemeshev #:

In my Expert Advisor, I divide everything by functions, iFunctionExample(), and inside these functions, there are variables iFE1,iFE2,iFE3 for int, and dFE1, dFE2, dFE3 for double. It is easier for me to understand what comes out of it this way.

Ok. Thank you for this clarification and for starting to get the code right.

 
Yury Lemeshev #:

I am working with two or more orders at the same time. Grid. I check the price below or above the conditional entry point. Conditional entry points originally were in the array, now they are in the global ones.

And it turns out that the digits are swapped, but God forbid the swap. If only the comparison was performed correctly. But substitution glitches too.

I've seen that SymbolInfoBid(name,SYMBOL_BID) may return 0 or EMPTY_VALUE, so it's worth checking if it's valid.

But a double comparison if (A>B && B-A<0) reads quite funny: "Is it more than B ? and even so ?

don't be afraid to use log - print your variables to see what's really going on

PS/ of course variable names are a pain...how do you read and write such code :-) and most importantly remember

 
Maxim Kuznetsov #:

SymbolInfoBid(name,SYMBOL_BID) may return 0 or EMPTY_VALUE, it is worth checking if it is correct

But a double comparison if (A>B && B-A<0) reads quite funny: "Is it bigger than B ? and even so ?

don't be afraid to use log - print your variables to see what's really going on

PS/ of course variable names are a joke...how do you read and write such code :-) and most importantly remember

I will write an EA where this error should be obvious, or I won't catch it. I will write about it later.

B-A<0 additional check to ensure that the function is not hit, but other characters take data that bypass this check.

 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict
#property script_show_inputs

input int                        Magic                      =100;
input double                     Volume                     =0.01;
input bool                       EURUSD                     =true;
input bool                       EURGBP                     =true;
input bool                       GBPUSD                     =true;
input double                     Grid                       =0.5;
extern int                       Slippage                   =5;   

int i,type,ticket,MagiX;
double price;
string symbol,iOrderComment;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
   {
   return(INIT_SUCCEEDED);  
   }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
   {
   }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int iGridCreate()
   {
   double dGC1;
   dGC1=SymbolInfoDouble(symbol,SYMBOL_BID);
   for(i=0; i<25; i++)
      {GlobalVariableSet(symbol+" BUY "+(1001+i),NormalizeDouble(dGC1=dGC1-(dGC1/100*Grid),SymbolInfoInteger(symbol,SYMBOL_DIGITS)));}
   dGC1=SymbolInfoDouble(symbol,SYMBOL_BID);
   for(i=0; i<25; i++)
      {GlobalVariableSet(symbol+" SELL "+(1001+i),NormalizeDouble(dGC1=dGC1+(dGC1/100*Grid),SymbolInfoInteger(symbol,SYMBOL_DIGITS)));}
   return(0);
   }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int iMagic()
   {
   MagiX=Magic;
   return(0);
   }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int iGridOpen()
   {
   double dGO1;
   string sGO1;
   for(i=0; i<GlobalVariablesTotal(); i++)
      {
      sGO1=GlobalVariableName(i);
      symbol=StringSubstr(sGO1,0,StringFind(sGO1," ",0));
      dGO1=SymbolInfoDouble(symbol,SYMBOL_BID);
      if(StringFind(sGO1,"BUY",0)!=-1)
         {
         if(dGO1<GlobalVariableGet(sGO1))
            {
            type=0;
            iOrderComment=dGO1+"<"+GlobalVariableGet(sGO1);
            intOpenPosition();
            GlobalVariableDel(sGO1);
            }
         }
      if(StringFind(sGO1,"SELL",0)!=-1)
         {
         if(dGO1>GlobalVariableGet(sGO1))
            {
            type=1;
            iOrderComment=dGO1+">"+GlobalVariableGet(sGO1);
            intOpenPosition();
            GlobalVariableDel(sGO1);
            }
         }
      }
   return(0);
   }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int intOpenPosition()
   {
   MqlTradeRequest TradeRequest={}; MqlTradeResult TradeResult={};
   ZeroMemory(TradeRequest);ZeroMemory(TradeResult);
   TradeRequest.action=TRADE_ACTION_DEAL;
   TradeRequest.symbol=symbol;
   TradeRequest.volume=Volume;
   TradeRequest.type=type;
   if(type==0){price=SymbolInfoDouble(symbol,SYMBOL_ASK);}
   if(type==1){price=SymbolInfoDouble(symbol,SYMBOL_BID);}
   TradeRequest.price=price;
   TradeRequest.deviation=Slippage;
   TradeRequest.magic=MagiX;
   TradeRequest.comment=iOrderComment;
   if(!OrderSend(TradeRequest,TradeResult)){Print("110");intOpenPosition();}
   else{ticket=TradeResult.deal;}
   return(0);
   }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
   {
   iMagic();
   iGridOpen();
   if(EURUSD==true)
      {
      symbol="EURUSD";
      SymbolSelect(symbol,true);
      if(GlobalVariablesTotal()==0){iGridCreate();}
      for(i=0; i<GlobalVariablesTotal(); i++)
         {
         if(StringFind(GlobalVariableName(i),symbol,0)!=-1){break;}
         }
      if(i==GlobalVariablesTotal()){iGridCreate();}
      }
   if(EURGBP==true)
      {
      symbol="EURGBP";
      SymbolSelect(symbol,true);
      if(GlobalVariablesTotal()==0){iGridCreate();}
      for(i=0; i<GlobalVariablesTotal(); i++)
         {
         if(StringFind(GlobalVariableName(i),symbol,0)!=-1){break;}
         }
      if(i==GlobalVariablesTotal()){iGridCreate();}
      }
   if(GBPUSD==true)
      {
      symbol="GBPUSD";
      SymbolSelect(symbol,true);
      if(GlobalVariablesTotal()==0){iGridCreate();}
      for(i=0; i<GlobalVariablesTotal(); i++)
         {
         if(StringFind(GlobalVariableName(i),symbol,0)!=-1){break;}
         }
      if(i==GlobalVariablesTotal()){iGridCreate();}
      }
   }
 

Tickets 6,7,8 have not received their data. If I am writing something wrong, I would be grateful if you could tell me what is wrong. However I tried many changes and the error persists.

I see the problem in the MT5 tester in visualization mode.

Files:
bhshrzc2g7.png  27 kb
 

Trying to solve the problem.

Noticed the following:

The tester stops writing logs, of any kind. And at this point there is a crash, the metamatics collapse.

2020.08.17 06:12:21 EURGBP 0.90496

2020.08.17 06:12:21 EURGBP BUY 0.90496

2020.08.17 06:47:12 GBPUSD 1.3098

2020.08.17 06:47:12 GBPUSD BUY 1.3098

Just at 6:34:15 there is an opening of trades that should not be opening.

Please check my code on the tester. It seems to me that the tester is not working correctly after the latest updates.


Files:
du8ozf0qs9.png  67 kb
Reason: