Variable , Primitive question

Michael-M

Trader
May 8, 2020
9
0
17
33
I am sorry but I have a primitive question. it’s about variable, I was trying to code my own EA and trying things out some of my custom function return with -1 others with zero but when took one of these functions that should return zero when there is no result and assign it to a variable that is initiated with -1 I noticed that the result change although according to my understanding that the new value of the function should be assigned to the variable instead of -1 but it seems that is not what happened and the result the function result change rather than if the variable is initialized by zero

as if the function is not been read because the variable that this function is been assigned to is initialized with -1

anyone can explain to me why?

thank you
 
Last edited:

Michael-M

Trader
May 8, 2020
9
0
17
33
The EA is more than 1000 lines but here a part of EA that I have a problem with, the bold line is the issue that I am facing, its custom function that I have and its act as if it is not being read in the EA because the variable that I have assigned this function to is initialized with -1 although when I change that variable to zero, it works fine,

Moreover when I test the function separately out of the EA and assign it to variable that is initialized with -1 , it works as expected and the new value of the function take place of the value of initialization (-1).

But still when I try out the function within the EA and just change the initialization value of the variable that the function is assigned to, to be zero it also works fine

the issue happens only when the initialization value of the variable is -1 and trying it within the EA

I was wondering if someone had the same issue and has explanation to it,

MQL4:
double SellPendingLevelOnNewTrend()
  {
   int j,z ;
   int TheDemandTDPointSameLevelOfSupply_BO ;
[B]   int LevelOfDemandBO=-1,LevelOfSupplyBO =-1;[/B]
   int Location_FirstTDPoint_OnLevelDemand ;
   int Location_NxtTDPoint_OnLevelDemand ;
   int Location_FirstTDPoint_OnLevelSupply ;
   int Location_NxtTDPoint_OnLevelSupply ;
   double value ;
   double PSL_ValueBasedOnSupply_BO ;
   double PSL_ValueBasedOnDemand_BO ;
   for(int i=1; i<300; i++)
     {
      Location_FirstTDPoint_OnLevelDemand = Get_DemandTD_Location_As_Level(i);
      Location_NxtTDPoint_OnLevelDemand = Get_NX_DemandTD_Location_As_Level(i);
      for(j=Location_FirstTDPoint_OnLevelDemand+1 ; j < Location_NxtTDPoint_OnLevelDemand ; j++)
        {
         if(Is_DemandTD_Point(j) == true && Level_TDPoint_Demand(j)>Level_TDPoint_Demand(Location_FirstTDPoint_OnLevelDemand))
           {
            LevelOfDemandBO = Level_TDPoint_Demand(j);
            PSL_ValueBasedOnDemand_BO = iLow(NULL,0, Location_FirstTDPoint_OnLevelDemand);
            // Print("Level of Demand BO","  ",LevelOfDemandBO,"  ","Candle Number","  ", j);
            break;
 
           }
        }
      if(LevelOfDemandBO > 0)
        {
         break;
        }
     }
//------------------------------------------------------------------------------------------------
   for(int i=1; i<300; i++)
     {
      Location_FirstTDPoint_OnLevelSupply = Get_SupplyTD_Location_As_Level(i);
      Location_NxtTDPoint_OnLevelSupply = Get_NX_SupplyTD_Location_As_Level(i);
      for(z=Location_FirstTDPoint_OnLevelSupply+1 ; z < Location_NxtTDPoint_OnLevelSupply ; z++)
        {
         if(Is_SupplyTD_Point(z) == true && Level_TDPoint_Supply(z)>Level_TDPoint_Supply(Location_FirstTDPoint_OnLevelSupply))
           {
            LevelOfSupplyBO = Level_TDPoint_Supply(z);
            TheDemandTDPointSameLevelOfSupply_BO = Get_DemandTD_Location_As_Level(LevelOfSupplyBO);
            PSL_ValueBasedOnSupply_BO = iLow(NULL,0,TheDemandTDPointSameLevelOfSupply_BO);
            // Print("Level of Supply BO","  ",LevelOfSupplyBO,"  ","Candle Number","  ", z,"  ", "Demand Candle as Supply Level BO" = TheDemandTDPointSameLevelOfSupply_BO );
            break;
           }
        }
      if(LevelOfSupplyBO > 0)
        {
         break;
        }
     }
 
   if(LevelOfSupplyBO < LevelOfDemandBO && LevelOfSupplyBO != 0)
     {
      Print("Level of Demand BO","  ",LevelOfDemandBO,"  ","Candle Number","  ", j, "The candle of PSL loc.","  ",Location_FirstTDPoint_OnLevelDemand,"  ","its value:","  ",PSL_ValueBasedOnDemand_BO);
      Print("Level of Supply BO","  ",LevelOfSupplyBO,"  ","Candle Number","  ", z, " The candle of PSL loc.","  ",TheDemandTDPointSameLevelOfSupply_BO,"  ","its value:","  ",PSL_ValueBasedOnSupply_BO);
      return (PSL_ValueBasedOnSupply_BO);
     }
   if(LevelOfDemandBO < LevelOfSupplyBO && LevelOfDemandBO != 0)
     {
      Print("Level of Demand BO","  ",LevelOfDemandBO,"  ","Candle Number","  ", j, "The candle of PSL loc.","  ",Location_FirstTDPoint_OnLevelDemand,"  ","its value:","  ",PSL_ValueBasedOnDemand_BO);
      Print("Level of Supply BO","  ",LevelOfSupplyBO,"  ","Candle Number","  ", z, " The candle of PSL loc.","  ",TheDemandTDPointSameLevelOfSupply_BO,"  ","its value:","  ",PSL_ValueBasedOnSupply_BO);
      return (PSL_ValueBasedOnDemand_BO);
     }
   if(LevelOfDemandBO == 0)
     {
      Print("Level of Demand BO","  ",LevelOfDemandBO,"  ","Candle Number","  ", j, "The candle of PSL loc.","  ",Location_FirstTDPoint_OnLevelDemand,"  ","its value:","  ",PSL_ValueBasedOnDemand_BO);
      Print("Level of Supply BO","  ",LevelOfSupplyBO,"  ","Candle Number","  ", z, " The candle of PSL loc.","  ",TheDemandTDPointSameLevelOfSupply_BO,"  ","its value:","  ",PSL_ValueBasedOnSupply_BO);
      return (PSL_ValueBasedOnSupply_BO);
     }
   if(LevelOfSupplyBO == 0)
     {
      Print("Level of Demand BO","  ",LevelOfDemandBO,"  ","Candle Number","  ", j, "The candle of PSL loc.","  ",Location_FirstTDPoint_OnLevelDemand,"  ","its value:","  ",PSL_ValueBasedOnDemand_BO);
      Print("Level of Supply BO","  ",LevelOfSupplyBO,"  ","Candle Number","  ", z, " The candle of PSL loc.","  ",TheDemandTDPointSameLevelOfSupply_BO,"  ","its value:","  ",PSL_ValueBasedOnSupply_BO);
      return (PSL_ValueBasedOnDemand_BO);
     }
 
 
   return (0);
  }
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
It is not entirely clear what result you call “works fine” and what result is a “failure” here.
Also, the code is untestable due to the custom functions used inside it. Could you please attach the EA file here? Or in a conversation with me if you do not want to make it public?