Last active
January 1, 2024 19:36
-
-
Save caglarenes/f39c74e7ed98ea66214607581b612807 to your computer and use it in GitHub Desktop.
SuperTrendScan
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
const TradingView = require('../main'); | |
const fs = require('fs'); | |
const readline = require('readline'); | |
const net = require("net"); | |
let streams; | |
const server = net.createServer((stream) => { | |
console.log("Server: on connection"); | |
streams = stream; | |
stream.on("data", (buffer) => { | |
console.log("Got data:", buffer.toString()); | |
stream.write("Reverse me"); | |
}); | |
stream.on("end", () => { | |
console.log("Stream ended"); | |
server.close(); | |
}); | |
}); | |
async function processLineByLine() { | |
var stocks = ["BIST:BMSTL", "BIST:MAVI", "BIST:THYAO", "BIST:IZMDC", "BIST:TUPRS", "BIST:HEKTS", "BIST:EREGL", "BIST:DOAS", "BIST:AKSGY", "BIST:SDTTR", "BINANCE:BTCUSD", "BINANCE:BTCTRY", "BINANCE:XRPUSD"]; | |
var range = 52; | |
var waitInSeconds = 1; | |
var timeframe = '1D'; | |
var atrSetting = 2; | |
for await (const line of stocks) { | |
(async () => { | |
const client = new TradingView.Client(); | |
const chart = new client.Session.Chart(); | |
chart.setMarket(line, { | |
timeframe: timeframe, | |
range: range, | |
}); | |
//Supertrend indicator ID | |
TradingView.getIndicator('PUB;VfOPXWDHDPhORvJYRTcuHOyeqpOcRR45').then((indic) => { | |
indic.setOption("ATR_Multiplier", atrSetting); | |
const STD = new chart.Study(indic); | |
STD.onError((...err) => { | |
console.log('Study error:', ...err); | |
}); | |
STD.onReady(() => { | |
// LAST BAR INFO | |
//console.log(STD.periods[0]); | |
if (STD.periods[0]["SuperTrend_Direction_Change"] == 1) { | |
if (STD.periods[0]["SuperTrend_Buy"] == 1) { | |
direction = "BUY SIGNAL"; | |
} | |
else { | |
direction = "SELL SIGNAL"; | |
} | |
console.log(`${direction} on ${line}`); | |
} | |
}); | |
STD.onUpdate(() => { | |
client.end(); | |
}); | |
}); | |
})(); | |
await new Promise(resolve => setTimeout(resolve, waitInSeconds * 1000)); | |
} | |
console.log(`FINISHED`); | |
} | |
processLineByLine(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment