Announcement

Collapse
No announcement yet.

Data Watchdog

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

  • Data Watchdog

    There are several posts regarding connection lost/restore and how do you know if it was lost while you were out. So here is a possible workaround - perhaps not elegant but I think it works: 2 parts 1) an efs that logs it's last data time, 2) a vbs (windows script) that checks that file every x seconds and reports.
    ===========================================
    //////////////// zLogDataTime.efs here ////////////////////////
    //
    // Recommended use:
    // Open a 1 minute chart of an index or other symbol that has frequent updates (such as DIA)
    // Place this efs on the chart
    // Place the WatchDog.vbs in any folder you choose
    // Start the watchdog by double-clicking on it
    // (it runs in the background - it will not show in the task bar)
    // To stop it set the OnOff parm in this efs to 0.
    // It will look for updates at the set interval (default 60 seconds)
    // On time gap will notify you with a Msgbox
    //
    // logs symbol, hour, minute, second (Ex: DIA,09:21:00)
    // into file "zLogDataTime.txt"
    // into default folder "C:\Program Files\FormulaOutput"
    //
    var vSym = null;
    var vHH = null;
    var vMM = null;
    var vSS = null;
    var vHHMMSS = null;
    var vLine = null;
    var vStudyTitle = "zLogDataTime";
    var vOutputFileName = null;

    function preMain() {
    setPriceStudy(false);
    setStudyTitle(vStudyTitle);
    setCursorLabelName(vStudyTitle,0);
    setColorPriceBars(false);
    setComputeOnClose();
    setIntervalsBackfill(true);
    var fp1 = new FunctionParameter("OnOff", FunctionParameter.NUMBER);
    fp1.setUpperLimit(1); // On
    fp1.setLowerLimit(0); // Off
    fp1.setDefault(1); // startup On
    }

    function main(OnOff) {
    if(OnOff == 0) {
    if(vLine == "stop") {
    return vLine;
    } else {
    vLine = "stop";
    // open output file as new
    vOutputFileName = vStudyTitle + ".txt"
    var f = new File(vOutputFileName);
    f.open("wt"); //new file - overwrite old
    f.writeln(vLine);
    f.close();
    return vLine;
    }
    }
    // get symbol and time to log
    vSym = getSymbol();
    vHH = getHour(0);
    if(vHH < 10) vHH = "0" + vHH
    vMM = getMinute(0);
    if(vMM < 10) vMM = "0" + vMM
    vSS = getSecond(0);
    if(vSS < 10) vSS = "0" + vSS
    vHHMMSS = vHH + ":" + vMM + ":" + vSS
    vLine = vSym + "," + vHHMMSS
    // open output file as new
    vOutputFileName = vStudyTitle + ".txt"
    var f = new File(vOutputFileName);
    f.open("wt"); //new file - overwrite old
    f.writeln(vLine);
    f.close();
    return vHHMMSS;
    }
    //////////////// WatchDog.vbs here ////////////////////////
    ===========================================
    Option Explicit
    '
    ' WatchDog: make sure eSignal charts keep getting data
    ' (this does not show in task bar, but does show as wscript in processes)
    '
    '*********** Paths that might change ************************************************** ****************
    Dim vDataPath '*** PATH to your data file
    vDataPath = "C:\Program Files\eSignal\FormulaOutput\zLogDataTime.txt" 'change to match efs created file
    '
    Dim vSecToWait
    vSecToWait = 60 'look every minute
    '
    Dim vPathToSoundFile
    vPathToSoundFile = "C:\$$wav\Sound1.wav" 'CHANGE THIS To A LOUD and LONG sound
    'note - after the sound file plays, you must manually close the media player
    '************************************************* ************************************************** *
    '
    Dim vHHxMMxSS, vHHxMMxSSPrev
    Dim vDataLine, vStartTime, vSym, vLen, vLoc, vRtn
    Dim oFSO, oFileIn
    '
    Wscript.Echo "WatchDog Started: " & Now
    '
    Do 'until you get a valid answer
    vRtn = InputBox("0=No,1=TestSound","Do you want a sound test?")
    If vRtn = "0" Then Exit Do
    If vRtn = "1" Then Exit Do
    Loop
    If vRtn = "1" Then
    Call PlaySound
    End If
    '
    'get link to file system support
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    '
    Call GetData 'get first data record
    vHHxMMxSSPrev = vHHxMMxSS 'save it for compare
    '
    Do 'forever - until stopped with text file or task manager
    Call Wait(vSecToWait)
    Call GetData
    If vHHxMMxSS = vHHxMMxSSPrev Then
    Call PlaySound
    Wscript.Echo "No new time data since: " & vHHxMMxSSPrev & ", now is: " & Now
    Do 'until you get a valid answer
    vRtn = InputBox("0=Stop,1=KeepGoing","Continue or Not?")
    If vRtn = "0" Then Exit Do
    If vRtn = "1" Then Exit Do
    Loop
    If vRtn = "0" Then
    Wscript.Echo "stopping"
    Wscript.Quit
    End If
    Else
    vHHxMMxSSPrev = vHHxMMxSS
    End If
    Loop
    '
    Wscript.Quit 'should not get here
    '
    '
    Sub GetData()
    On Error Resume Next
    Err = 0
    Set oFileIn = oFSO.OpenTextFile(vDataPath, 1) '1=read
    If Err <> 0 Then
    Wscript.Echo "Error on file open: " & Err.Number & ", " & Err.Description
    Wscript.Echo "stopping"
    Wscript.Quit
    End If
    vDataLine = ""
    vDataLine = oFileIn.ReadLine
    oFileIn.Close
    vLoc = Instr(1,vDataLine,",") 'locate the beginning of time (symbol length can vary)
    If vLoc = 0 Then 'get symbol
    vSym = vDataLine
    Else
    vSym = Left(vDataLine,vLoc-1)
    End If
    If LCase(vSym) = "stop" Then
    Wscript.Echo "stopping"
    Wscript.Quit
    End If
    vLen = Len(vDataLine) - vLoc 'get len of time data - must be 8
    If vLen <> 8 Then
    Wscript.Echo "Error in time format - Must be HH:MM:SS: " & vDataLine
    Wscript.Echo "stopping"
    Wscript.Quit
    End If
    vHHxMMxSS = Mid(vDataLine,vLoc+1,8) 'get time
    End Sub
    '
    '
    Sub Wait(nSec)
    'wait for n seconds
    If nSec < 1 Then nSec = 1
    vStartTime = Now
    Do While DateDiff("s", vStartTime, Now) < nSec
    Wscript.Sleep 1000
    Loop
    End Sub
    '
    '
    Sub PlaySound()
    Dim oSHL
    Set oSHL = CreateObject("Wscript.Shell")
    'oSHL.Run "wmplayer.exe " & vPathToSoundFile, 1, True '=wait
    oSHL.Run "wmplayer.exe " & vPathToSoundFile, 1, False '=Dont Wait
    End Sub
    ===========================================
Working...
X