Download MetaTrader 5

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

To add comments, please log in or register
Fajar Alam
1572
Fajar Alam  

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 

Drazen Penic
2716
Drazen Penic  

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? 

Marco vd Heijden
Moderator
6063
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.
Fajar Alam
1572
Fajar Alam  
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 

Marco vd Heijden
Moderator
6063
Marco vd Heijden  
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.

Fajar Alam
1572
Fajar Alam  
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));

Fajar Alam
1572
Fajar Alam  
At Font color Red , I got an error 
To add comments, please log in or register