Could someone help me with global vars
I wish to have a efs running on one longer timeframe that set global vars after each bar close.
On a shorter Timeframe, I would like it to read the relevant global var and action if met
Below is the script for the longer tf, that set the global vars
var vLastAlert = -1;
function preMain() {
setColorPriceBars(true);
setPriceStudy(true);
setStudyTitle("Long TF Chart");
setGlobalValue ("30low",0);
setGlobalValue ("30high",0);
setComputeOnClose(true)
}
function main() {
if (
(close(-1) > open(-1))
) onAction1()
else if (
(close(-1) < open(-1))
) onAction2();
return null;
}
function postMain() {
}
function onAction1() {
setPriceBarColor(Color.RGB(155,0,0));
var low = open(-1)
var high = close(-1)
setGlobalValue ("30low",low);
setGlobalValue ("30high",high);
vLastAlert = 1;
}
function onAction2() {
setPriceBarColor(Color.RGB(0,255,0));
var low = close()
var high = open()
setGlobalValue ("30low",low);
setGlobalValue ("30high",high);
vLastAlert = 2;
}
This script is for the slower timefram
var vLastAlert = -1;
function preMain() {
//setComputeOnClose(true)
setPriceStudy(true);
setStudyTitle("Lower TF");
setCursorLabelName("30low", 0);
setCursorLabelName("30high", 1);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarThickness(1, 0);
setDefaultBarThickness(1, 1);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
}
function main() {
if (
close(-1) > getGlobalValue("30high")&&
close(-1) > getGlobalValue("30low")
) onAction1()
else if (
close(-1) < getGlobalValue("30high")&&
close(-1) < getGlobalValue("30low")
) onAction2();
return new Array(
null,
null
);
}
function postMain() {
}
function onAction1() {
var vHL = high() - low();
var vVar = vHL * 0.25;
var vAddVar = vVar * 0.35;
var buy = "buy" + getGlobalValue("30high")
drawTextRelative(0, high() + (vVar + vAddVar +vVar ), buy, Color.black, Color.red, Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
vLastAlert = 1;
}
function onAction2() {
vLastAlert = 2;
var vHL = high() - low();
var vVar = vHL * 0.25;
var vAddVar = vVar * 0.35;
var sell = "Sell + getGlobalValue("30low")
drawTextRelative(0, high() + (vVar + vAddVar +vVar ), sell, Color.black, Color.red, Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
}
Apreciate any help, I have a feeling it something to do with time
I wish to have a efs running on one longer timeframe that set global vars after each bar close.
On a shorter Timeframe, I would like it to read the relevant global var and action if met
Below is the script for the longer tf, that set the global vars
var vLastAlert = -1;
function preMain() {
setColorPriceBars(true);
setPriceStudy(true);
setStudyTitle("Long TF Chart");
setGlobalValue ("30low",0);
setGlobalValue ("30high",0);
setComputeOnClose(true)
}
function main() {
if (
(close(-1) > open(-1))
) onAction1()
else if (
(close(-1) < open(-1))
) onAction2();
return null;
}
function postMain() {
}
function onAction1() {
setPriceBarColor(Color.RGB(155,0,0));
var low = open(-1)
var high = close(-1)
setGlobalValue ("30low",low);
setGlobalValue ("30high",high);
vLastAlert = 1;
}
function onAction2() {
setPriceBarColor(Color.RGB(0,255,0));
var low = close()
var high = open()
setGlobalValue ("30low",low);
setGlobalValue ("30high",high);
vLastAlert = 2;
}
This script is for the slower timefram
var vLastAlert = -1;
function preMain() {
//setComputeOnClose(true)
setPriceStudy(true);
setStudyTitle("Lower TF");
setCursorLabelName("30low", 0);
setCursorLabelName("30high", 1);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarThickness(1, 0);
setDefaultBarThickness(1, 1);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
}
function main() {
if (
close(-1) > getGlobalValue("30high")&&
close(-1) > getGlobalValue("30low")
) onAction1()
else if (
close(-1) < getGlobalValue("30high")&&
close(-1) < getGlobalValue("30low")
) onAction2();
return new Array(
null,
null
);
}
function postMain() {
}
function onAction1() {
var vHL = high() - low();
var vVar = vHL * 0.25;
var vAddVar = vVar * 0.35;
var buy = "buy" + getGlobalValue("30high")
drawTextRelative(0, high() + (vVar + vAddVar +vVar ), buy, Color.black, Color.red, Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
vLastAlert = 1;
}
function onAction2() {
vLastAlert = 2;
var vHL = high() - low();
var vVar = vHL * 0.25;
var vAddVar = vVar * 0.35;
var sell = "Sell + getGlobalValue("30low")
drawTextRelative(0, high() + (vVar + vAddVar +vVar ), sell, Color.black, Color.red, Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
}
Apreciate any help, I have a feeling it something to do with time
Comment