TLDR; Trying to update the tradingview settings for a strategy automatically and simple element.value doesn't work.
Hi everyone,
I have created a Strategy that works successfully through Pinescript however there is quite a few options in the settings window (E.g RSI Period etc), with a large variety of combinations. I would like to automate the settings for it to run through the backtesting for each setting and record the details of each change (e.g. record RSI Period 4,5,6,7) (edit: not worried about the recording part, that will come easy once the data is in a variable in javascript).
I am a long time trader and relatively proficient with Javascript and Jquery so I thought i'd give it a crack at creating a Chrome Extension to do this. I have created the manifest/content.js, and have managed to make it read the Settings window when it is opened, and manipulate the values however here lies my problem. I am able to get it to change the values however the Strategy doesn't seem to update/it doesn't seem to submit the changes. I have tried to change the .value, then .focus() and .blur() but that doesn't seem to work.
I understand there may be some backend code/hidden fields where the real value is kept but there HAS to be a way to be able to trick the form that a person is doing it (i.e .click() ).
Here's my code I have so far that just changes the value for an element to 1 when CTRL+ALT+SHIFT+D is pressed(but the form does nothing after this):
document.addEventListener('keydown', function (event) {
if (event.ctrlKey && event.altKey && event.shiftKey && event.key == 'D' ) {
loadForm();
}
});
function loadForm(){
var alertElement = document.getElementsByClassName('input-3bEGcMc9 with-end-slot-S5RrC8PC');
console.log(alertElement);
alertElement[6].focus();
alertElement[6].value = '1';
alertElement[6].blur();
var event = new Event('input', {
bubbles: true,
cancelable: true,
});
alertElement[6].dispatchEvent(event);
$("input").blur();
}