I am trying to get stocks list from Chartink.com screener in Google sheet.
But I am not able to do so, Kindly help.
A1 is https://chartink.com/screener/macd-cross-51432
B1 is (+{cash}+(+latest+macd+line(+26+,+12+,+9+)+>+latest+macd+signal(+26+,+12+,+9+)+and+1+day+ago++macd+line(+26+,+12+,+9+)+<=+1+day+ago++macd+signal(+26+,+12+,+9+)+and+latest+close+<=+300+and+latest+rsi(+14+)+>+70+)+)+
C1 is groupcount(+1+where+daily+macd+line(+26+,+12+,+9+)+>+daily+macd+signal(+26+,+12+,+9+)+and+1+day+ago++macd+line(+26+,+12+,+9+)+<=+1+day+ago++macd+signal(+26+,+12+,+9+)),groupcount(+1+where+daily+close+<=+300),groupcount(+1+where+daily+rsi(+14+)+>+70)
function Chartinkupload() {
// Get the URL, scan_clause, and debug_clause from specific cells
const url = SpreadsheetApp.getActiveSheet().getRange("A1").getValue();
const scanClause = SpreadsheetApp.getActiveSheet().getRange("B1").getValue();
const debugClause = SpreadsheetApp.getActiveSheet().getRange("C1").getValue();
// Prepare the payload data
const payloadData = {
"scan_clause": scanClause,
"debug_clause": debugClause
};
// Convert payload to JSON string
const payload = JSON.stringify(payloadData);
try {
// Send POST request with JSON payload and muteHttpExceptions option
const response = UrlFetchApp.fetch(url, {
method: "POST",
payload: payload,
contentType: "application/json",
muteHttpExceptions: true // Added option to mute HTTP exceptions
});
// Check for successful response
if (response.getResponseCode() === 200) {
const json = response.getContentText();
const chartinkData = JSON.parse(json);
// Write data to the "chartink" sheet starting from cell A1
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("chartink");
sheet.clear(); // Clear existing data
sheet.getRange(1, 1).setValue(json); // Write JSON response to cell A1
Logger.log("Data written to sheet 'chartink'");
} else {
Logger.log("Error fetching data: " + response.getResponseCode());
}
} catch (error) {
Logger.log("Error during upload: " + error.message);
}
}
type here
Google sheet should get data like this
Sr. Stock Name Symbol Links % Chg Price Volume
Afroz Alam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.