Last active
May 29, 2020 14:41
-
-
Save snowkidind/b141bb357cc109c781304bdc10f5ca0c to your computer and use it in GitHub Desktop.
Caveman example using SnowSignals model output for simplified forecasting.
This file contains hidden or 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
// Note: internal implementation. This does not use the snowsignals-api npm package, examples coming soon | |
// see also http://snowsignals.com:3333/apiDocs | |
const signalsApi = require('../api.js'); | |
module.exports = { | |
whatThink: function(job){ | |
return new Promise(async (resolve, reject) => { | |
job.emaslowemaw = 40; | |
signalsApi.dataRequest(job) | |
.then((output) => { | |
const display = output.firstAnalysis.basicAnalysis.flatRelease.display; | |
const candlesSinceXover = output.firstAnalysis.basicAnalysis.analysis.candlesSinceXover; | |
// only look at the last 7 candles | |
let recentWedgeCollapse = false; | |
let recentFlat = false; | |
let recentSecondHMAT = false; | |
let recentCrossover = false; | |
let currentBar = display.length; | |
let range = 7; | |
if (currentBar < range){ | |
range = currentBar; | |
} | |
for (let i = currentBar - range; i < currentBar; i++){ | |
for (let j = 0; j < display[i].indicators.length; j++) { | |
// looking for WC and flat | |
display[i].indicators.forEach((indicator) => { | |
// bull and bear | |
if (indicator.status === 'flat'){ | |
recentFlat = true; | |
} | |
// bull and bear | |
if(indicator.status === 'wedgeCollapse'){ | |
recentWedgeCollapse = true; | |
} | |
// bull only | |
if(indicator.status === 'hiMagATSecondParabola'){ | |
recentSecondHMAT = true; // take profit zone | |
} | |
}) | |
} | |
// need to get a recent crossover indicator here | |
if (candlesSinceXover < 2) { | |
recentCrossover = true; | |
} | |
} | |
// this is histogram data, which includes analog indicators | |
// console.log(output.scoringData.key[0].esell[0].id) | |
const channel = output.firstAnalysis.basicAnalysis.flatRelease.channel; | |
const indicators = output.firstAnalysis.basicAnalysis.flatRelease.indicators.status; | |
const unstuntedChannel = output.firstAnalysis.basicAnalysis.flatRelease.indicators.unstuntedChannel; | |
const pri = output.firstAnalysis.basicAnalysis.flatRelease.indicators.parabolicReleaseIndex; | |
let say = []; | |
if (indicators.length > 0){ | |
console.log(indicators); | |
if (channel === 'bull') { | |
for (let i = 0; i < indicators.length; i++) { | |
switch (indicators[i].status) { | |
case 'flat': | |
say.push('I SMELL PREDATOR IN BUSHES'); | |
break; | |
case 'stunted': | |
say.push('ME NOT KNOW'); | |
break; | |
case 'wedgeCollapse': | |
say.push('RUN RUN'); | |
break; | |
case 'parabolicRelease': | |
say.push('HOLD TIGHT'); | |
break; | |
case 'secondParabolicRelease': | |
say.push('LOOKING LIKE FRESH STEGOSARUS TONIGHT'); | |
break; | |
case 'hiMagATSecondParabola': | |
say.push('FRED FLINSTONE SELL THAT YABBA DABBA DOO'); | |
break; | |
case 'pullback': | |
say.push('PRICE GO UP SOON AFTER DOWN A LITTLE'); | |
break; | |
case 'flattedExpansion': | |
say.push('SUN COMING A SECOND TIME'); | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
else { | |
// bear channel indicators | |
for (let i = 0; i < indicators.length; i++) { | |
switch (indicators[i].status) { | |
case 'flat': | |
say.push('DINOSAUR EGGS FOR BREAKFAST'); | |
break; | |
case 'stunted': | |
say.push('ME NOT KNOW'); | |
break; | |
case 'wedgeCollapse': | |
say.push('SUN RISING'); | |
break; | |
case 'parabolicRelease': | |
say.push('DARK TIMES'); | |
break; | |
case 'fastParabolicRelease': | |
say.push('NO HOPE'); | |
break; | |
case 'secondParabolicRelease': | |
say.push('WHERES MY T-BONE'); | |
break; | |
case 'secondFastParabolicRelease': | |
say.push('THAT BARNEY IS ALWAYS AT THE BOTTOM'); | |
break; | |
case 'unstunted': | |
say.push('FALL IN BOTTOMLESS PIT'); | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
} | |
if (recentCrossover){ | |
say.push('SUN AND MOON IN SKY'); | |
} | |
if (unstuntedChannel){ | |
if (channel === 'bull') { | |
let pass = true; | |
for (let i = 0; i < say.length; i++) { | |
if (say[i].length > 0) pass = false; // means already something to say | |
} | |
// If the star indicator fired, we are in a sell zone | |
if (recentSecondHMAT){ | |
pass = false; | |
say.push('ME NOT KNOW, SUN ALREADY ROSE'); | |
} | |
// if we are recently flat, and nothing has happened yet | |
if (recentFlat && pass) { | |
pass = false; | |
say.push('ME NOT KNOW'); | |
} | |
// if a channel collapse fired recently yet still in a bull channel | |
if (recentWedgeCollapse && pass) { | |
pass = false; | |
say.push('ME NOT KNOW'); | |
} | |
if (pass) say.push('PRICE GO UP'); | |
} else { | |
if (say.length === 0) { | |
say.push('PRICE GO DOWN') | |
} | |
} | |
} | |
else { | |
// unstunted channel | |
say.push('OUT HUNTING') | |
} | |
let sayingsNewLine = ''; | |
let sayingsHTML = ''; | |
for (let i = 0; i < say.length; i++) { | |
sayingsNewLine += (say[i] + '\n'); | |
sayingsHTML += (say[i] + '<br />'); | |
} | |
console.log("say"); | |
console.log(say); | |
resolve({cavemanSay: sayingsNewLine, cavemanSayHtml: sayingsHTML, caveman: say, parameters: job}); | |
}) | |
.catch((error) => { | |
console.log('bad: ', error); | |
reject(error) | |
}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment