Advertisement
AJEET-SINGH

Export Data from Amibroker

Jun 26th, 2022
1,077
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. dayhours = ParamToggle("Day hours only", "No|Yes");
  3. fmkdir("e:\\AmiBackupD\\");
  4. SetBarsRequired(100000,100000);
  5. lname = Name(); // gets the name of the symbol
  6. // note: if you have names with invalid characters like / you must rename the file before you try to create a Name
  7. // add an IF line for each symbol you need to rename
  8. if (lname == "ER2U8-GLOBEX-FUT") lname = "ER2U8";
  9.  
  10. fh = fopen( "e:\\AmiBackupD\\" + lname + ".csv", "w");
  11. if( fh )
  12. {
  13.     if(Interval() == inDaily OR Interval() == inMonthly OR Interval() ==
  14. inWeekly)
  15.     {
  16.         fputs( "Ticker,Date,Open,High,Low,Close,Volume \n", fh );
  17.         for( i = 0; i < BarCount; i++ )
  18.         {
  19.             y = Year();
  20.             m = Month();
  21.             d = Day();
  22.             fputs( Name() + "," , fh );
  23.             ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ i ] );
  24.             fputs( ds, fh );
  25.             qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
  26. ],V[ i ] );
  27.             fputs( qs, fh );
  28.             if(i == 65500 OR i == 130000 OR i == 196500 OR i == 262000)
  29.             {
  30.                 fclose( fh );
  31.                 if(i == 65500  ) fh = fopen( "e:\\AmiBackupD\\" + lname + " A.csv", "w");
  32.                 if(i == 130000 ) fh = fopen( "e:\\AmiBackupD\\" + lname + " B.csv", "w");
  33.                 if(i == 196500 ) fh = fopen( "e:\\AmiBackupD\\" + lname + " C.csv", "w");
  34.                 if(i == 262000 ) fh = fopen( "e:\\AmiBackupD\\" + lname + " D.csv", "w");
  35.             }
  36.         }
  37.     }
  38.     else // intraday so add time field
  39.     {
  40.         fputs( "Ticker,Date,Time,Open,High,Low,Close,Volume \n", fh );
  41.         y = Year();
  42.         m = Month();
  43.         d = Day();
  44.         r = Hour();
  45.         e = Minute();
  46.         n = Second();
  47.    
  48.         for( i = 1; i < BarCount; i++ )
  49.         {
  50.             if (dayhours AND LastValue(TimeNum()) >= 92900 AND LastValue(TimeNum()) <=
  51. 161500)
  52.             {
  53.                 fputs( Name() + "," , fh );
  54.                 ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ i ] );
  55.                 fputs( ds, fh );
  56.  
  57.                 ts = StrFormat("%02.0f:%02.0f:%02.0f,", r[ i ],e[ i ],n[ i ] );
  58.                 fputs( ts, fh );
  59.  
  60.                 qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
  61. ],V[ i ] );
  62.                 fputs( qs, fh );
  63.             }
  64.             else
  65.             {
  66.                 fputs( Name() + "," , fh );
  67.                 ds = StrFormat("%02.0f-%02.0f-%02.0f,", m[ i ], d[ i ], y[ i ] );
  68.                 fputs( ds, fh );
  69.  
  70.                 ts = StrFormat("%02.0f:%02.0f:%02.0f,", r[ i ],e[ i ],n[ i ] );
  71.                 fputs( ts, fh );
  72.  
  73.                 qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n", O[ i ],H[ i ],L[ i ],C[ i
  74. ],V[ i ] );
  75.                 fputs( qs, fh );
  76.             }
  77.             if(i == 65500 OR i == 130000 OR i == 196500 OR i == 262000)
  78.             {
  79.                 fclose( fh );
  80.                 if(i == 65500  ) fh = fopen( "e:\\AmiBackupD\\" + lname + " A.csv", "w");
  81.                 if(i == 130000 ) fh = fopen( "e:\\AmiBackupD\\" + lname + " B.csv", "w");
  82.                 if(i == 196500 ) fh = fopen( "e:\\AmiBackupD\\" + lname + " C.csv", "w");
  83.                 if(i == 262000 ) fh = fopen( "e:\\AmiBackupD\\" + lname + " D.csv", "w");
  84.             }
  85.         }
  86.     }
  87.     fclose( fh );
  88. }
  89.  
  90. Buy = 1;
  91. _SECTION_BEGIN("Price");
  92. SetChartOptions(0,chartShowArrows|chartShowDates);
  93. _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
  94. Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
  95. _SECTION_END();
Advertisement
RAW Paste Data Copied
Advertisement