Announcement

Collapse
No announcement yet.

Timing not updating

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

  • Timing not updating

    Hello,

    I have the code below. I set up the quote to for 1 minute. I am looking to write data to a file every minute. It writes the data ever minute but the timestamp below is not correct. It keeps on writing the same date/time when I first loaded things.

    var Monfichier = new File("HV.csv");
    var today = new Date();
    var sDate = today.getUTCFullYear();
    var Valeur = 0;
    var strval = "";
    var t60 = 0;
    var t120 = 0;
    var t240 = 0;
    var td = 0;
    var tw = 0;
    var timer = 0;
    var oldvalue = 1;
    var newvalue = 0;

    function preMain()
    {
    setPriceStudy(false);
    setStudyTitle("Ichimoku Signals");
    // setCursorLabelName("10",0);
    // setCursorLabelName("30",1);
    setCursorLabelName("60",1);
    setCursorLabelName("120",2);
    setCursorLabelName("240",3);
    setCursorLabelName("D",4);
    setCursorLabelName("W",5);
    setIntervalsBackfill(true)


    }


    function main()
    {
    nState = getBarState();


    t60 = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(6 0));
    t120 = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(1 20));
    t240 = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(2 40));
    td = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(" D"));
    tw = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(" W"));
    sDate = "";
    sDate = today.getFullYear();
    if ((today.getMonth()+1) < 10)
    sDate += "-0" + (today.getMonth()+1)
    else
    sDate += "-" + (today.getMonth()+1);

    if (today.getDate() < 10)
    sDate += "-0" + (today.getDate());
    else
    sDate += "-" + (today.getDate());

    if (today.getHours() < 10)
    sDate += " 0" + (today.getHours());
    else
    sDate += " " + (today.getHours());

    if (today.getMinutes() < 10)
    sDate += ":0" + (today.getMinutes());
    else
    sDate += ":" + (today.getMinutes());

    if (today.getSeconds() < 10)
    sDate += ":0" + (today.getSeconds());
    else
    sDate += ":" + (today.getSeconds());
    timer = 0;
    timer = today.getSeconds();

    if (( isLastBarOnChart() == true ) && (nState == BARSTATE_NEWBAR))
    {
    newvalue = t60 + t120 + t240 + td + tw;


    debugPrintln(timer);
    // if ((newvalue != oldvalue))
    {
    strval = "";
    Monfichier.open( "at" );
    strval = getSymbol() + "," + t60.getValue(0) + "," + t120.getValue(0) + "," + t240.getValue(0) + "," + td.getValue(0) + "," + tw.getValue(0)+","+sDate;
    Monfichier.writeln(strval);
    Monfichier.close()
    oldvalue = newvalue;
    }
    sDate = "";

    }

    return new Array(t60,t120,t240,td,tw);
    }

  • #2
    Manesh
    See this post in reply to a similar question
    Alex


    Originally posted by sunman4008 View Post
    Hello,

    I have the code below. I set up the quote to for 1 minute. I am looking to write data to a file every minute. It writes the data ever minute but the timestamp below is not correct. It keeps on writing the same date/time when I first loaded things.

    var Monfichier = new File("HV.csv");
    var today = new Date();
    var sDate = today.getUTCFullYear();
    var Valeur = 0;
    var strval = "";
    var t60 = 0;
    var t120 = 0;
    var t240 = 0;
    var td = 0;
    var tw = 0;
    var timer = 0;
    var oldvalue = 1;
    var newvalue = 0;

    function preMain()
    {
    setPriceStudy(false);
    setStudyTitle("Ichimoku Signals");
    // setCursorLabelName("10",0);
    // setCursorLabelName("30",1);
    setCursorLabelName("60",1);
    setCursorLabelName("120",2);
    setCursorLabelName("240",3);
    setCursorLabelName("D",4);
    setCursorLabelName("W",5);
    setIntervalsBackfill(true)


    }


    function main()
    {
    nState = getBarState();


    t60 = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(6 0));
    t120 = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(1 20));
    t240 = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(2 40));
    td = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(" D"));
    tw = efsExternal("Ichimainheatmap2.efs",getSymbol,inv(" W"));
    sDate = "";
    sDate = today.getFullYear();
    if ((today.getMonth()+1) < 10)
    sDate += "-0" + (today.getMonth()+1)
    else
    sDate += "-" + (today.getMonth()+1);

    if (today.getDate() < 10)
    sDate += "-0" + (today.getDate());
    else
    sDate += "-" + (today.getDate());

    if (today.getHours() < 10)
    sDate += " 0" + (today.getHours());
    else
    sDate += " " + (today.getHours());

    if (today.getMinutes() < 10)
    sDate += ":0" + (today.getMinutes());
    else
    sDate += ":" + (today.getMinutes());

    if (today.getSeconds() < 10)
    sDate += ":0" + (today.getSeconds());
    else
    sDate += ":" + (today.getSeconds());
    timer = 0;
    timer = today.getSeconds();

    if (( isLastBarOnChart() == true ) && (nState == BARSTATE_NEWBAR))
    {
    newvalue = t60 + t120 + t240 + td + tw;


    debugPrintln(timer);
    // if ((newvalue != oldvalue))
    {
    strval = "";
    Monfichier.open( "at" );
    strval = getSymbol() + "," + t60.getValue(0) + "," + t120.getValue(0) + "," + t240.getValue(0) + "," + td.getValue(0) + "," + tw.getValue(0)+","+sDate;
    Monfichier.writeln(strval);
    Monfichier.close()
    oldvalue = newvalue;
    }
    sDate = "";

    }

    return new Array(t60,t120,t240,td,tw);
    }

    Comment


    • #3
      Hi,

      Try moving the following two variables from outside the main function (declared as global variables and set only once) to inside main (here they will be local variables set on every tick):

      var today = new Date();
      var sDate = today.getUTCFullYear();


      Wayne

      Comment

      Working...
      X