My Code Compiled correctly but I have a problem with it

 

 I was trying to code my own EA and created some custom function,  the issue that I am facing is as if the custom function that I have is not being read in the EA if the variable that I have assigned this function to is initialized with -1 although when I change that variable to zero, it works fine, 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

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,

anyone can explain to me why?


double SellPendingLevelOnNewTrend()
  {
   int j,z ;
   int TheDemandTDPointSameLevelOfSupply_BO ;
   
int LevelOfDemandBO=-1,LevelOfSupplyBO =-1;
   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);
  }
Reason: