Hi,
I am totally new to EFS or any sort of Programming languages. I am trying to make a strategy for backtesting.
The idea is this:
Generate a random number 1 for Long and 0 for short
Draw text above Bar, "1" for long, "0" for short
Color Bar Green for Long and red for Short
I came up with the Script below but I do not know how to make it work. Anybody please help. Thanks. TCW
function preMain() {
setPriceStudy(true);
setStudyTitle("Random");
setCursorLabelName("Random");
setColorPriceBars(true);
setDefaultPriceBarColor(Color.black);
}
// Global Variables
var x = null;
var bInit = false;
function main() {
if(getCurrentBarIndex() == 0) return;
if (bInit == false) {
x = Math.floor(Math.random() * 2);
}
}
var rx = x.getValue(0);
if (rx = 0) {
drawTextRelative(0, high(0), rx, Color.red, null, Text.BOLD|Text.BOTTOM|Text.FRAME, null, 12);
}
if (rx = 1) {
drawTextRelative(0, high(0), rx, Color.lime, null, Text.BOLD|Text.BOTTOM|Text.FRAME, null, 12);
}
I am totally new to EFS or any sort of Programming languages. I am trying to make a strategy for backtesting.
The idea is this:
Generate a random number 1 for Long and 0 for short
Draw text above Bar, "1" for long, "0" for short
Color Bar Green for Long and red for Short
I came up with the Script below but I do not know how to make it work. Anybody please help. Thanks. TCW
function preMain() {
setPriceStudy(true);
setStudyTitle("Random");
setCursorLabelName("Random");
setColorPriceBars(true);
setDefaultPriceBarColor(Color.black);
}
// Global Variables
var x = null;
var bInit = false;
function main() {
if(getCurrentBarIndex() == 0) return;
if (bInit == false) {
x = Math.floor(Math.random() * 2);
}
}
var rx = x.getValue(0);
if (rx = 0) {
drawTextRelative(0, high(0), rx, Color.red, null, Text.BOLD|Text.BOTTOM|Text.FRAME, null, 12);
}
if (rx = 1) {
drawTextRelative(0, high(0), rx, Color.lime, null, Text.BOLD|Text.BOTTOM|Text.FRAME, null, 12);
}
Comment