need help... with open write and read.

 
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);       
     }     
   }
 
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
Reason: