Download MetaTrader 5

Where is my code error ?

To add comments, please log in or register
evgenykei
48
evgenykei  

It is a code of event my expert:

CTrade  trade;

CPositionInfo myposition; 

void OnTick()
  {
   if(IsNewBar()) 
     {
       if(myposition.Select(_Symbol)==true)  //Case 1
        {
                trade.PositionClose(_Symbol);
        }
      
      if (myposition.Select(_Symbol)==false)  //Case 2
        {
             // Position open place 
        }
     } 
  }

 

This code works fine in tester but does not work in real: never open position (case 2) if before that position was closed (case 1). Why ?. Once more time - expert works fine in tester (open and close positions).

Carl Schreiber
6779
Carl Schreiber  
evgenykei:

It is a code of event my expert:

CTrade  trade;

CPositionInfo myposition; 

void OnTick()
  {
   if(IsNewBar()) 
     {

       if(myposition.Select(_Symbol)==true)  //Case 1

        {

                trade.PositionClose(_Symbol);

        }
      
      if (myposition.Select(_Symbol)==false)  //Case 2
        {

             // Position open place 

        }

     } 

  }

 

This code correct works in tester and does not work in real: never open position (case 2) if before that position was closed (case 1). Why ?. Once more time - expert works fine in tester (open and close positions).

please use the SRC-button when you post your code!
To add comments, please log in or register