Hi All,
I've got a simple formula that is supposed to assign a value to a global variable unless the value is null (therefore the global variable will always equal something). However, for some reason the global var seems to be changing to null on each run through. I cannot figure out why it isn't holding it's value! Any help would be much appreciated.
In the below example NextSupport and NextResistance should always equal something, I cannot work out why they are being set back to null at any stage!
Cheers,
- Willl
Here is the code:
Here is the output:
I've got a simple formula that is supposed to assign a value to a global variable unless the value is null (therefore the global variable will always equal something). However, for some reason the global var seems to be changing to null on each run through. I cannot figure out why it isn't holding it's value! Any help would be much appreciated.
In the below example NextSupport and NextResistance should always equal something, I cannot work out why they are being set back to null at any stage!
Cheers,
- Willl
Here is the code:
//Configuration Variables
var DistanceToResistanceToEnter = 0.02;
var StopValue = 2;
//Global Variables
var NextResistance = null; //CURRENT RESISTANCE POINT
var NextSupport = null; //CURRENT SUPPORT POINT
var TradePrice = null;
var vLastAlert = -1;
//PreMain
function preMain(){
}
function main()
{
//Load studies
var UpMagnet = efsExternal("/Advanced/Arps Crown Jewels/Arps Price Magnets - UP.efs");
UpMagnet1 = getSeries(UpMagnet, 0)
var DownMagnet = efsExternal("/Advanced/Arps Crown Jewels/Arps Price Magnets - DN.efs");
DownMagnet1 = getSeries(DownMagnet, 0)
//Load variables that change
debugPrintln("UpMagnet1: " + UpMagnet1);
debugPrintln("DownMagnet1: " + DownMagnet1);
if(DownMagnet1 == 0 || DownMagnet1 == null)
{
debugPrintln("NextSupport didn't change: " + DownMagnet1 + "(" + NextSupport + ")")
} else {
debugPrintln("NextSupport changing to: " + DownMagnet1 + "(" + NextSupport + ")")
NextSupport = DownMagnet1
}
if(UpMagnet1 == 0 || UpMagnet1 == null)
{
debugPrintln("NextResistance didn't change: " + UpMagnet1 + "(" + NextResistance + ")")
} else {
debugPrintln("NextResistance changing to: " + UpMagnet1 + "(" + NextResistance + ")")
NextResistance = UpMagnet1
}
debugPrintln("NextSupport: " + NextSupport);
debugPrintln("NextResistance: " + NextResistance);
}
var DistanceToResistanceToEnter = 0.02;
var StopValue = 2;
//Global Variables
var NextResistance = null; //CURRENT RESISTANCE POINT
var NextSupport = null; //CURRENT SUPPORT POINT
var TradePrice = null;
var vLastAlert = -1;
//PreMain
function preMain(){
}
function main()
{
//Load studies
var UpMagnet = efsExternal("/Advanced/Arps Crown Jewels/Arps Price Magnets - UP.efs");
UpMagnet1 = getSeries(UpMagnet, 0)
var DownMagnet = efsExternal("/Advanced/Arps Crown Jewels/Arps Price Magnets - DN.efs");
DownMagnet1 = getSeries(DownMagnet, 0)
//Load variables that change
debugPrintln("UpMagnet1: " + UpMagnet1);
debugPrintln("DownMagnet1: " + DownMagnet1);
if(DownMagnet1 == 0 || DownMagnet1 == null)
{
debugPrintln("NextSupport didn't change: " + DownMagnet1 + "(" + NextSupport + ")")
} else {
debugPrintln("NextSupport changing to: " + DownMagnet1 + "(" + NextSupport + ")")
NextSupport = DownMagnet1
}
if(UpMagnet1 == 0 || UpMagnet1 == null)
{
debugPrintln("NextResistance didn't change: " + UpMagnet1 + "(" + NextResistance + ")")
} else {
debugPrintln("NextResistance changing to: " + UpMagnet1 + "(" + NextResistance + ")")
NextResistance = UpMagnet1
}
debugPrintln("NextSupport: " + NextSupport);
debugPrintln("NextResistance: " + NextResistance);
}
Here is the output:
NextResistance: null
NextSupport: null
NextResistance didn't change null(null)
NextSupport didn't change null(null)
DownMagnet1: null
UpMagnet1: null
NextResistance: 0.70736
NextSupport: 0.70463
NextResistance changing to: 0.70736 (0.70736)
NextSupport changing to: 0.70463 (0.70463)
DownMagnet1: 0.70463
UpMagnet1: 0.70736
NextSupport: null
NextResistance didn't change null(null)
NextSupport didn't change null(null)
DownMagnet1: null
UpMagnet1: null
NextResistance: 0.70736
NextSupport: 0.70463
NextResistance changing to: 0.70736 (0.70736)
NextSupport changing to: 0.70463 (0.70463)
DownMagnet1: 0.70463
UpMagnet1: 0.70736
Comment