Skip to content

Instantly share code, notes, and snippets.

@episage
Created May 2, 2023 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save episage/0293682a0f33d2da7e43be3edcf3f52a to your computer and use it in GitHub Desktop.
Save episage/0293682a0f33d2da7e43be3edcf3f52a to your computer and use it in GitHub Desktop.
Create Horizontal Ray in TradingView from browser console
function createHorizontalRay(epoch, price) {
window.c = window.TradingViewApi.activeChart();
// Ht
window.ht = window.c._chartWidget.paneWidgets()[0];
// l = chart undo model
window.chartModel = window.c._chartWidget._model
var point = {index: epochToCandleIndex(epoch), price: price};
var linetool = 'LineToolHorzRay';
window.chartModel.createLineTool({
pane: window.ht.state(),
point,
linetool,
});
function epochToCandleIndex(epoch) {
var chartModel = window.chartModel;
var coord = chartModel.timeScale().timeToCoordinate(epoch)
return chartModel.timeScale().coordinateToIndex(coord)
}
}
createHorizontalRay(1680447654, 1.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment