//@Name:Elder-Ray Indicator //@Description:Based on Alexander Elder's book: Trading for a Living //@Returns: Number //@Width:55 // See 'Trading for a Living' for more details // // Care has been taken in preparing this code but it is provided without guarantee. // You are welcome to modify and extend it. Please add your name as a modifier if you distribute it. // // How to use: This Column script should be used in conjunction with the Elder Ray Bear/ Bull Histogram Technical indicator scripts // It can be used two ways: // Method 1: Add the column to a list of shares. Run a sort on the Elder Ray Column // All those with a 1 meet the criteria for a buy signal // All those with a -1 are sell signals. // You should check the other technical criteria of MACD/Force Index and Stochastics to decide if signal is true // Method 2: Use the column as criteria in a data mining filter // Any errors or observations please feel free to contact me // version 1.0 8/5/08 // kenny@halleynet.com http://www.halleynet.co.uk function init() { } function getVal(share) { var period=13; var longperiod =100; var BullPower = new Array(); var BearPower = new Array(); var sma = new Array(); var ma1 = new MA(period, MA.Exponential); var ma2 = new MA(longperiod, MA.Simple); var data = share.getPriceArray(); for (var i=0; i< data.length; i++) { var maVal=ma1.getNext(data[i].close); sma[i]=ma2.getNext(data[i].close); BullPower[i]=data[i].high-maVal; BearPower[i]=data[i].low-maVal; } var t = data.length-1; //today var y = (data.length - 2);//yesterday if (sma[t] > sma[y]) { // confirm we are in an uptrend if (BullPower[y] > 0 && BearPower[y]< 0 && BullPower[t] > 0 && BearPower[t]>0){ var sig = 1; } else { var sig = 0; } } else if (sma[t]< sma[y]) { // confirm we are in a downtrend if (BullPower[y] > 0 && BearPower[y]< 0 && BullPower[t] < 0 && BearPower[t]<0){ var sig = -1; }else{ var sig = 0; } } return sig; }