Announcement

Collapse
No announcement yet.

Export info to file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Export info to file

    Hello,

    I am trying to export the current bar and a couple of bars back to a file. I have the following which does not seem to work. What am I doing wrong?

    -Mike

    var counter = 0;
    var newDateObject = new Date(year, month, day);

    function main()
    {
    var nBarIndex = getCurrentBarIndex();
    var nBarState = getBarState();

    var f = new File("newsymbol.txt");
    f.open( "at" );
    if(getBarStateInterval("d") == BARSTATE_NEWBAR)
    {
    counter = 0;
    // debugPrintln("open=",close(0));
    f.writeln(open(0)+",",high(0)+","+low(0)+","+close (0));
    }
    f.close();
    }

  • #2
    Hi,

    Here is one way to do it:
    PHP Code:
    function preMain(){
        
    setPriceStudy(true);
    }
    var 
    xSym=getSymbol()+",D"
    var 
    myOpen_1,myHigh_1,myLow_1,myClose_1;

    function 
    main() {
        if(
    day(0)!=day(-1)){//at first bar of each new day
            
    var lookback 1;//lookback of 1 day ago, change the "1" to whatever lookback is needed
            
    myOpen_1 open(-lookbacksym(xSym));
            
    myHigh_1 high(-lookbacksym(xSym));
            
    myLow_1 low(-lookbacksym(xSym));
            
    myClose_1 close(-lookbacksym(xSym));
            if (
    myOpen_1 == null || myHigh_1 == null || myLow_1 == null || myClose_1 == null) return;
            var 
    = new File("newsymbol.txt"); 
            
    f.open"at" ); 
            
    f.writeln(myOpen_1+", "+myHigh_1+", "+myLow_1+", "+myClose_1);
            
    f.close(); 
        } 
        
        return new Array(
    myOpen_1,myHigh_1,myLow_1,myClose_1); 

    Wayne
    Last edited by waynecd; 05-12-2013, 08:43 PM.

    Comment

    Working...
    X