Skip to content

Instantly share code, notes, and snippets.

@herenow
Last active November 30, 2018 16:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herenow/fd29bc4a6d2c1236533de9e963ec2d5f to your computer and use it in GitHub Desktop.
Save herenow/fd29bc4a6d2c1236533de9e963ec2d5f to your computer and use it in GitHub Desktop.
TensorCharts Price Voice Update Script
// 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