Problem with compilation using #Property strict, Need Help..

 

Hello everyone

After try using #property strict and all going succeed except this code :

// Exit After X Bars

         tempValue = getOrderExitAfterXBars(770);

         if(tempValue > 0) {

            if (sqGetOpenBarsForOrder(tempValue+10) >= tempValue) {

               Verbose("Exit After ", (string)tempValue, "bars - closing order with ticket: ", (string)OrderTicket(), ", Magic Number: ", (string)orderMagicNumber);

               sqClosePositionAtMarket(-1); 

}

         } 

it always show warning message : "possible loss of data due to type conversion" 

can anybody correct me which part the mistake?

 

Thank You 

 

This means you are mixing different types of data somewhere in the code. In which line do you get an error?

What's the type of the local variable "tempValue"?

What are return types of the functions

 
It should also tell you the exact line numbers and the cursor positions so you can get closer to the exact problem.
 
Marco vd Heijden:

It should also tell you the exact line numbers and the cursor positions so you can get closer to the exact problem.


// Exit After X Bars

         tempValue1 = getOrderExitAfterXBars(770);

         if(tempValue1 > 0) {

            if (sqGetOpenBarsForOrder(tempValue1+10) >= tempValue1) {

               Verbose("Exit After ", (string)tempValue1, "bars - closing order with ticket: ", (string)OrderTicket(), ", Magic Number: ", (string)orderMagicNumber);

               sqClosePositionAtMarket(-1); 

}

   } 

 

at this line and cursor Ive got an error 

 
Fajar Alam:


// Exit After X Bars

         tempValue1 = getOrderExitAfterXBars(770);

         if(tempValue1 > 0) {

            if (sqGetOpenBarsForOrder(tempValue1+10) >= tempValue1) {

               Verbose("Exit After ", (string)tempValue1, "bars - closing order with ticket: ", (string)OrderTicket(), ", Magic Number: ", (string)orderMagicNumber);

               sqClosePositionAtMarket(-1); 

}

   } 

 

at this line and cursor Ive got an error 

yeah ok so it tell you this because your going from long type to integer or from double to integer or any other combination because you are not showing the code that declares those variables so i just have to guess at this point but basically it is telling you hey you upconvert or downconvert from one type to another so dataloss can occur for example if you have a double 10.123 and use it as integer the data after the decimal point will be cut off or be lost then the double 10.123 becomes 10 because integers only handle whole number and its telling you look out for the dataloss.

so you have to look at how these variables are declared and where there is a mis match between types i can not make it up from this short piece of code.

 
Marco vd Heijden:

yeah ok so it tell you this because your going from long type to integer or from double to integer or any other combination because you are not showing the code that declares those variables so i just have to guess at this point but basically it is telling you hey you upconvert or downconvert from one type to another so dataloss can occur for example if you have a double 10.123 and use it as integer the data after the decimal point will be cut off or be lost then the double 10.123 becomes 10 because integers only handle whole number and its telling you look out for the dataloss.

so you have to look at how these variables are declared and where there is a mis match between types i can not make it up from this short piece of code.

Here my code , can you check please :

void manageOrder(int orderMagicNumber) {

   double tempValue1 = 0;

   


if(orderMagicNumber == 1) {

      if(OrderType() == OP_BUY || OrderType() == OP_SELL) {

         // handle only active orders



// Exit After X Bars

         tempValue1 = getOrderExitAfterXBars(1);

         if(tempValue1 > 0) {

            if (sqGetOpenBarsForOrder (tempValue1+10) >= tempValue1) {

               Verbose("Exit After ", (string)tempValue1, "bars - closing order with ticket: ", (string)OrderTicket(), ", Magic Number: ", (string)orderMagicNumber);

               sqClosePositionAtMarket(-1);

            }

         }

      }

   }


//+------------------------------------------------------------------+


int sqGetOpenBarsForOrder(int expBarsPeriod) {

   datetime opTime = OrderOpenTime();


   int numberOfBars = 0;

   for(int i=0; i<expBarsPeriod+10; i++) {

      if(opTime < Time[i]) {

         numberOfBars++;

      }

   }


   return(numberOfBars);

//+-----------------------------------------------------------------+

double getOrderExitAfterXBars(int orderMagicNumber) {

   double price = 0;


   if(orderMagicNumber == 1) {

      price = ExitAfterBars;

   }

   return(NormalizeDouble(price, Digits));

 
At Font color Red , I got an error 
Reason: