Last active
November 30, 2018 16:07
-
-
Save herenow/fd29bc4a6d2c1236533de9e963ec2d5f to your computer and use it in GitHub Desktop.
TensorCharts Price Voice Update Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Settings | |
var changeThresholdPct = 1.0; // Notify by voice when the price moves up or down this percentage | |
var beepChangeThresholdPct = 0.25; // Notify with a beep when the price moves up or down this percentage | |
// Scopes | |
var lastPx = self.lastPx; | |
var beepLastPx = self.beepLastPx; | |
if(trades.length!=0){ | |
var currentPx = trades[0].Price; | |
// First run, only set the lastPx | |
if(lastPx == null || beepLastPx == null) { | |
self.lastPx = currentPx; | |
self.beepLastPx = currentPx; | |
} else { | |
var changePct = Math.round((((currentPx / lastPx) - 1.0) * 100) * 100) / 100; | |
var beepChangePct = Math.round((((currentPx / beepLastPx) - 1.0) * 100) * 100) / 100; | |
if(changePct > changeThresholdPct || changePct < -changeThresholdPct) { | |
if(changePct > 0) { | |
speak("Up " + changePct + "%, trading @ $" + currentPx); | |
} else { | |
speak("Down " + changePct + "%, trading @ $" + currentPx); | |
} | |
self.lastPx = currentPx; | |
} | |
if(beepChangePct > beepChangeThresholdPct || beepChangePct < -beepChangeThresholdPct) { | |
var numBeeps = Math.min(Math.round(Math.abs(beepChangePct) / beepChangeThresholdPct), 10); // Ring up/down how many "threshold ticks" changed | |
var beepType = 2; // Default negative beep | |
// Positive beep | |
if(beepChangePct > 0) { | |
beepType = 1; | |
} | |
for(var i = 0; i < numBeeps; i++) { | |
setTimeout(function() { beep(beepType); }, i*100); | |
} | |
self.beepLastPx = currentPx; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment