Defined constant not evaluating properly in if statement ....

 

Hello,

I'm having a hard time understanding why a defined constant is not evaluating properly in an if().

In the debugger, I don't understand how it is possible I could be positioned on this line of code, given the following print statement and the displayed values:

      if(_Symbol=="USDCAD")
         {
      Print("trendBuyOrSell: ",trendBuyOrSell,"; HIST_SELL: ",HIST_SELL,"; HIST_BUY: ",HIST_BUY,"; TMACDPriorThickBuffer[0]: ",TMACDPriorThickBuffer[0]);
         }
      if(trendBuyOrSell==HIST_BUY && (TMACDPriorThickBuffer[0]<0 || TMACDPriorThickBuffer[0]==0))
         {
         // if trend is BUY, but prior period current bar is against trend OR is not building
         statuses[i].hasPulledBack=false;
         return;
         }
      if(trendBuyOrSell==HIST_SELL && (TMACDPriorThickBuffer[0]>0 || TMACDPriorThickBuffer[0]==0))
         {
         // if trend is SELL, but prior period current bar is against trend OR is not building
         }
         statuses[i].hasPulledBack=false;   // DEBUGGER IS HITTING THIS LINE OF CODE DESPITE THE ABOVE IF()
         return;

Print result is this, but....

trendBuyOrSell: 1; HIST_SELL: 2; HIST_BUY: 1; TMACDPriorThickBuffer[0]: 0.0039033351287835593

Look if() above the current line in the debugger.

Apparently this is a teachable moment ?


Thanks!!!



 

I even tried loading the constants into variables instead, and still got the same result:

int testBuy=HIST_BUY;
int testSell=HIST_SELL;

Here are the values displayed in the debugger:


I must really be having a brain malfunction.

But in my world, 1 != 2
 
Christian Berrigan:

Hello,

I'm having a hard time understanding why a defined constant is not evaluating properly in an if().

In the debugger, I don't understand how it is possible I could be positioned on this line of code, given the following print statement and the displayed values:

Print result is this, but....

trendBuyOrSell: 1; HIST_SELL: 2; HIST_BUY: 1; TMACDPriorThickBuffer[0]: 0.0039033351287835593

Look if() above the current line in the debugger.

Apparently this is a teachable moment ?


Thanks!!!



If I break apart the if() it works, but I don't understand why that is necessary.  I must have a fundamental misunderstanding about how if(exp1 && (exp2 || exp3)) logic works in an if().

If someone could explain it to me I would be very grateful!

         if(trendBuyOrSell==testSell)
         {
         if(TMACDPriorThickBuffer[0]>0 || TMACDPriorThickBuffer[0]==0)
            {
            // if trend is SELL, but prior period current bar is against trend OR is not building
            }
            statuses[i].hasPulledBack=false;
            return;
         }
 
      if(_Symbol=="USDCAD")
         {
      Print("trendBuyOrSell: ",trendBuyOrSell,"; HIST_SELL: ",HIST_SELL,"; HIST_BUY: ",HIST_BUY,"; TMACDPriorThickBuffer[0]: ",TMACDPriorThickBuffer[0]);
         }
      if(trendBuyOrSell==HIST_BUY && (TMACDPriorThickBuffer[0]<0 || TMACDPriorThickBuffer[0]==0))
         {
         // if trend is BUY, but prior period current bar is against trend OR is not building
         statuses[i].hasPulledBack=false;
         return;
         }
      if(trendBuyOrSell==HIST_SELL && (TMACDPriorThickBuffer[0]>0 || TMACDPriorThickBuffer[0]==0))
         {
         // if trend is SELL, but prior period current bar is against trend OR is not building
         statuses[i].hasPulledBack=false;   // DEBUGGER IS HITTING THIS LINE OF CODE DESPITE THE ABOVE IF()
         return;
         }
         

The last 2 lines were outside of the if brackets "{ }", so the second if was doing nothing, and those lines would always execute if the first if fails (they would do the same anyway too)

Reason: