I am trying to add a moving band around a moving average (in this case a vwap band from the amvwap.efs study - but any moving average will do). What I need to do is find the high/low of the day from the start of the day to the current bar and then just basically do:
(hi-low)/2 and add/subtract from the vwap band.
So I first started trying to plot the band by using the high/low values from the getTodayOHLC.efs file:
ie. todayHi=call(".\\OHLC\\getTodayOHLC.efs", "High");
but that did not work because it gets the current high/low for the entire day...so my bands didn't work to well.
Then I decided to use the functions:
todayHi = highest(vCounter, high() );
todayLow = lowest (vCounter, low() );
where vCounter is a count of bars for the current day...thtat seemed to work, but it seems to HOG the CPU a lot and takes forever for me to create a 1 min chart onn my quad cpu machine...
so then I tried to create my own running high/low indicators for the day by using my own variables. But what I found was the data never seemed to be correct and the high and lows I start with at 9:30am (I am using a 2 day template for testing, start time 9:30, end 4:00pm) don't matche the high/low bars of my esignal chart (I changed the curstor screen to show the bar#). There must be something wrong with esignal, or something wrong with my code...
For example, I am looking at VMW (vmware) for the open on Mar26. Esignal shows bar -76 as 24.87 and 24.66 as high/low respectively...when I dump the data in the data window, it shows as 25.08 24.93 respectively...the stock didn't even trade at that level yet!
Is it my code? Here it is:
If you uncomment the following lines, yoou will see what happens when it works..note, you should use a 5 min period.
[php]
//todayHi = highest(vCounter, high() );
//todayLow = lowest (vCounter, low() );
[php]
attached is a snapshot of how it works with the highest(...) and lowest(...) api
the 2nd attachment is of how it does not work...note the bar # in the cursor screen, and then the bar number in the left output window...they do not match. I don't know why.
(hi-low)/2 and add/subtract from the vwap band.
So I first started trying to plot the band by using the high/low values from the getTodayOHLC.efs file:
ie. todayHi=call(".\\OHLC\\getTodayOHLC.efs", "High");
but that did not work because it gets the current high/low for the entire day...so my bands didn't work to well.
Then I decided to use the functions:
todayHi = highest(vCounter, high() );
todayLow = lowest (vCounter, low() );
where vCounter is a count of bars for the current day...thtat seemed to work, but it seems to HOG the CPU a lot and takes forever for me to create a 1 min chart onn my quad cpu machine...
so then I tried to create my own running high/low indicators for the day by using my own variables. But what I found was the data never seemed to be correct and the high and lows I start with at 9:30am (I am using a 2 day template for testing, start time 9:30, end 4:00pm) don't matche the high/low bars of my esignal chart (I changed the curstor screen to show the bar#). There must be something wrong with esignal, or something wrong with my code...
For example, I am looking at VMW (vmware) for the open on Mar26. Esignal shows bar -76 as 24.87 and 24.66 as high/low respectively...when I dump the data in the data window, it shows as 25.08 24.93 respectively...the stock didn't even trade at that level yet!
Is it my code? Here it is:
PHP Code:
var fpArray = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("LR_VWAP_MPD");
setCursorLabelName("MPD+1",0);
setDefaultBarFgColor(Color.red,0);
//setPlotType(PLOTTYPE_SQUAREWAVE,2);
// VWAP
setCursorLabelName("VWAP",1);
setDefaultBarFgColor(Color.blue,1);
//setPlotType(PLOTTYPE_SQUAREWAVE,1);
setDefaultBarThickness(2,1);
setCursorLabelName("MPD-1",2);
setDefaultBarFgColor(Color.red,2);
//setPlotType(PLOTTYPE_SQUAREWAVE,2);
//askForInput();
var x=0;
fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
with(fpArray[x++]){
setName("Show Parameters");
setDefault(false);
}
}
// rnd function - round to two places
function format(value) { // Round the price to 2 digits
// NOTE: can just return value if u think there is a rounding problem
value *= 100 ;
return Math.round(value, 2 )/100 ;
}
var amLib = addLibrary("amStudies.efsLib");
var dsLib = addLibrary("dsFunctions.efsLib");
var bInit = false
var vCounter = 0
var xVWAP = null;
var todayHi=0;
var todayLow=0;
function main(Symbol,Interval,Params) {
if(bInit==false){
with( amLib ) {
if(Symbol == null)
Symbol = getSymbol();
if(Interval == null)
Interval = getInterval();
var vSymbol = Symbol+","+Interval;
xVWAP = amVWAP(sym(vSymbol));
setShowTitleParameters(eval(Params));
bInit=true;
}
}
var nVWAP = getSeries(xVWAP); //retrieve the VWAP series
var nStdDev = 0;
if(getDay(0)!=getDay(-1) && getBarState()==BARSTATE_NEWBAR){ //if a new day and new bar
vCounter=0; //set vCounter to 0
// init to 1st bars of the day...
todayHi = high(getCurrentBarIndex());
todayLow = low(getCurrentBarIndex());
debugPrintln ("------------------NEW DAY---------------------------");
debugPrintln ("bar: " + bar + "-1st day bar: high= " + todayHi + " LOW= " + todayLow);
}
if(getBarState()==BARSTATE_NEWBAR){ //if a new bar
vCounter++; //increment vCounter by 1
bar=getCurrentBarIndex();
if (todayHi < high(bar))
{
debugPrintln ("bar: " + bar + " NewHI: " + format(high(bar)) + " oldhi: " + format(todayHi));
todayHi=high(bar);
}
if (todayLow > low(bar))
{
debugPrintln ("bar: " + bar + " NewLO: " + format(low(bar)) + " oldLo: " + format(todayLow));
todayLow=low(bar);
}
///*
debugPrintln ("bar: " + bar +
" high : " + format(todayHi) +
" low : " + format(low(bar)) +
" open : " + format(open(bar)) +
" close: " + format(close(bar)));
//*/
}
var nVWAP = xVWAP.getValue(0);
if(nVWAP==null ) return;
// get highest high/low in lookback period...
// which should
//todayHi = highest(vCounter, high() );
//todayLow = lowest (vCounter, low() );
//debugPrintln ("bar: " + getCurrentBarIndex() + " high: " + todayHi + " low: " + todayLow);
// //+ " avg: " + (todayHi-todayLow)/2);
//debugPrintln("counter: " +vCounter);
mpd= (todayHi-todayLow)/2;
return new Array ( nVWAP+(mpd),
nVWAP,
nVWAP-(mpd));
}
[php]
//todayHi = highest(vCounter, high() );
//todayLow = lowest (vCounter, low() );
[php]
attached is a snapshot of how it works with the highest(...) and lowest(...) api
the 2nd attachment is of how it does not work...note the bar # in the cursor screen, and then the bar number in the left output window...they do not match. I don't know why.
Comment