写入文件

| 发表于 2020-7-27 02:55:57 | 显示全部楼层 |复制链接
  1. bool first = true;
  2. bool Now_IsConnected = false;
  3. bool Pre_IsConnected = true;
  4. datetime Connect_Start = 0, Connect_Stop = 0;
  5. int init() { start(); return(0); }
  6. int start()
  7. {
  8. int handle = FileOpen( "_IsConnected.txt", FILE_WRITE | FILE_READ, " " );
  9. FileSeek( handle, 0, SEEK_END );
  10. FileWrite( handle, "- - - - - - - - - - - Expert initialized  - - - - - - - - - -" );
  11. while ( !IsStopped() )
  12. {
  13. Pre_IsConnected = Now_IsConnected;
  14. Now_IsConnected = IsConnected();
  15. if ( first ) { Pre_IsConnected = !Now_IsConnected; }
  16. if ( Now_IsConnected != Pre_IsConnected )
  17. {
  18. if ( Now_IsConnected )
  19. {
  20. Connect_Start = LocalTime();
  21. if ( !first )
  22. {
  23. FileSeek( handle, -55, SEEK_CUR );
  24. FileWrite( handle, "- - - OffLine- - -       " + TimeToStr( Connect_Stop, TIME_DATE ) + "       " + TimeToStr( Connect_Stop, TIME_SECONDS ) + " - " + TimeToStr( Connect_Start, TIME_SECONDS ) );
  25. }
  26. if ( IsStopped() ) { break; }
  27. FileWrite( handle, "+ + + OnLine + + +       " + TimeToStr( Connect_Start, TIME_DATE ) + "       " + TimeToStr( Connect_Start, TIME_SECONDS ) + " - " );
  28. }
  29. else
  30. {
  31. Connect_Stop = LocalTime();
  32. if ( !first )
  33. {
  34. FileSeek( handle, -55, SEEK_CUR );
  35. FileWrite( handle, "+ + + OnLine + + +       " + TimeToStr( Connect_Start, TIME_DATE ) + "       " + TimeToStr( Connect_Start, TIME_SECONDS ) + " - " + TimeToStr( Connect_Stop, TIME_SECONDS ) );
  36. }
  37. if ( IsStopped() ) { break; }
  38. FileWrite( handle, "- - - OffLine- - -       " + TimeToStr( Connect_Stop, TIME_DATE ) + "       " + TimeToStr( Connect_Stop, TIME_SECONDS ) + " - " );
  39. }
  40. }
  41. first = false;
  42. FileFlush( handle );
  43. Sleep(1000);
  44. }
  45. if ( Now_IsConnected )
  46. {
  47. FileSeek( handle, -55, SEEK_CUR );
  48. FileWrite( handle, "+ + + OnLine + + +       " + TimeToStr( Connect_Start, TIME_DATE ) + "       " + TimeToStr( Connect_Start, TIME_SECONDS ) + " - " + TimeToStr( LocalTime(), TIME_SECONDS ) );
  49. }
  50. else
  51. {
  52. FileSeek( handle, -55, SEEK_CUR );
  53. FileWrite( handle, "- - - OffLine- - -       " + TimeToStr( Connect_Stop, TIME_DATE ) + "       " + TimeToStr( Connect_Stop, TIME_SECONDS ) + " - " + TimeToStr( LocalTime(), TIME_SECONDS ) );
  54. }
  55. FileWrite( handle, "- - - - - - - - - - - Expert was stoped - - - - - - - - - - -\n" );
  56. FileClose( handle );
  57. return(0);
  58. }
复制代码
最近访问 头像模式
举报

评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册