need help... simple open read and write in data memory.

 
Hi, anyone can tech me, here site
https://docs.mql4.com/files/FileClose

I just want a simple write-in and read-out of total buy and sell in data memory hold, but i still get no ball above site.

I try to write simple and test, many problem in below.

   int handle;
   int value;  
   handle=FileOpen("buytt.dat",FILE_CSV|FILE_READ,';');
   if(handle>0)
   {
      value=FileReadNumber(handle);
      Print(_BuyTotal," > ",value);
      Comment("BUY ",value);
      FileClose(handle);
   }  
   
   handle=FileOpen("buytt.dat", FILE_CSV|FILE_WRITE, ';');
   if(_BuyTotal > handle)
   {
     FileWrite(handle, _BuyTotal);
     FileClose(handle);
     Comment("A ",_BuyTotal," > ",value);
   } else {Comment("B ",_BuyTotal," > ",value);
     if(_BuyTotal == 0)
     {Comment("C ",_BuyTotal," > ",value);
       handle=FileOpen("buytt.dat", FILE_CSV|FILE_WRITE, ';');
       FileWrite(handle, _BuyTotal);
       FileClose(handle);       
     }     
   }
 
And than sense of the given line?

if(_BuyTotal > handle)
As I understand, sense of variable _BuyTotal - quantity of the open positions, and handle - the index of a file. These are absolutely different characteristics
 
There can be you meant the following?
if(_BuyTotal > value)
 
hi, scriptong. thanks to reply

still have problem, mean total come 2. this 'value' is always change 2 or 0 repeat again

print(_BuyTotal > value); <<i try to print the record as this script above, always change 2 > 2, 2 > 0, 2 > 2, 2 > 0...
if(_BuyTotal > value)

and
print(_BuyTotal > handle); the totals is come 2, and buytt.dat record 2, but handle only get 1. if(2 > 1)?
if(_BuyTotal > handle)

can anyone help, what wrong with it?

egt520
 
 
   int handle;
   int value;  
   handle=FileOpen("buytt.dat",FILE_CSV|FILE_READ,';');
   if(handle>0)
   {
      value=FileReadNumber(handle);
      Print(_BuyTotal," > ",value);
      Comment("BUY ",value);
      FileClose(handle);
   } 
 
 
   
   if(_BuyTotal > handle)
   {
 
     handle=FileOpen("buytt.dat", FILE_CSV|FILE_WRITE, ';');
 
     FileWrite(handle, _BuyTotal);
     FileClose(handle);
 
     Comment("A ",_BuyTotal," > ",value);
   } else {Comment("B ",_BuyTotal," > ",value);
     if(_BuyTotal == 0)
     {Comment("C ",_BuyTotal," > ",value);
       
       handle=FileOpen("buytt.dat", FILE_CSV|FILE_WRITE, ';');
       
       FileWrite(handle, _BuyTotal);
       FileClose(handle);       
 
     }     
   }
 
Hi Integer, thank you for reply.

still have problem. when the totals increase to 2, the buytt.dat record is 2, and handle still get 1?? not reset get 2??

print(_BuyTotal > handle);>> print out is (2 > 1)? Not (2 > 2)?
if(_BuyTotal > handle)

here i attach the picture
 
what relations between handle and orders count?
 
i want use if buytotals decrease one and close all order.

if(buytotals > handle) true to close order.

in buytt.dat file already record 2, mean handle is give we 2, but the handle still give 1 in the record?

here the picture
  int _GetLastError = 0;
   for ( int z = OrdersTotal() - 1; z >= 0; z -- )
   {
     if ( !OrderSelect( z, SELECT_BY_POS ) )
     {
     _GetLastError = GetLastError();
     Print( "OrderSelect( ", z, ", SELECT_BY_POS ) - Error #", _GetLastError );
     continue;
     }
     if ( OrderMagicNumber() == magic && OrderSymbol() == Symbol() )
     {
       switch ( OrderType() )
       {
          case OP_BUY:
            _BuyTicket = OrderTicket();
            _BuyTotal  ++;
            break;
       }    
     }
   }
 
   int handle;
   int value;  
   handle=FileOpen("buytt.txt",FILE_CSV|FILE_READ,';');
   if(handle>0)
   {
      value=FileReadNumber(handle);
      Print(_BuyTotal," > ",handle);
      Comment("BUY ",_BuyTotal," > ",handle);
      FileClose(handle);
   } 
 
   if(_BuyTotal > handle)
   {
     handle=FileOpen("buytt.txt", FILE_CSV|FILE_WRITE, ';');
 
     FileWrite(handle, _BuyTotal);
     FileClose(handle);
     Comment("A ",_BuyTotal," > ",handle);
 
   } else {Comment("B ",_BuyTotal," > ",handle);
     if(_BuyTotal == 0)
     {Comment("C ",_BuyTotal," > ",handle);
       
       handle=FileOpen("buytt.txt", FILE_CSV|FILE_WRITE, ';');
       
       FileWrite(handle, _BuyTotal);
       FileClose(handle);       
 
   } 

 
handle value does not depend on data in file. Use GlobalVariable its easier and more conveniently
 
can you give me guide? i have no idea. just beginning learn from site, a lot still don't understand.. tech me point. pls... and thanks
 
_BuyTotal is responsible for quantity of orders which at you is equal to 2. This number also writing in a file. At the same time variable handle always equal to 1, as the file at you is used one. Explain more particularly, that should do the resulted piece of a code and then we can help you
Причина обращения: