I am running this study in a 150 tick chart for AB #F :
function preMain()
{
setPriceStudy(true);
}
var PriceArray = new Array(21);
function numericalsort(a, b){ return (a-b); }
function main()
{
PriceArray[20] = high(0);
for(i = 0; i <= 20; i++)
PriceArray[i] = PriceArray[i + 1];
PriceArray[20] = low(0);
for(i = 0; i <= 20; i++)
PriceArray[i] = PriceArray[i + 1];
debugClear();
debugPrintln("PriceArray: " + PriceArray);
//var newprice = PriceArray.sort(numericalsort);
// debugPrintln("newprice: " + newprice);
}
This puts the high and low price values of the last 10 price bars into an array named PriceArray. I want to determine the highest or lowest value in the array, so I added the function 'numericsort' to do this, and then had intended on reading the first or last index position in the array to get the value I want. My problem is that when I use the sort function to sort the values, it also CHANGES the price values in the array. If you run this with and without the debug line commented out, you'll see this change.
Does anyone have a method for accomplishing what I need to do?
Thanks
function preMain()
{
setPriceStudy(true);
}
var PriceArray = new Array(21);
function numericalsort(a, b){ return (a-b); }
function main()
{
PriceArray[20] = high(0);
for(i = 0; i <= 20; i++)
PriceArray[i] = PriceArray[i + 1];
PriceArray[20] = low(0);
for(i = 0; i <= 20; i++)
PriceArray[i] = PriceArray[i + 1];
debugClear();
debugPrintln("PriceArray: " + PriceArray);
//var newprice = PriceArray.sort(numericalsort);
// debugPrintln("newprice: " + newprice);
}
This puts the high and low price values of the last 10 price bars into an array named PriceArray. I want to determine the highest or lowest value in the array, so I added the function 'numericsort' to do this, and then had intended on reading the first or last index position in the array to get the value I want. My problem is that when I use the sort function to sort the values, it also CHANGES the price values in the array. If you run this with and without the debug line commented out, you'll see this change.
Does anyone have a method for accomplishing what I need to do?
Thanks
Comment