Hello, I am using the MOMofMA efs, as suggested in others threads, to get the tick difference in a 20EMA (using 10 as the lookback period). I would like to show the number, with 1 decimal point, in the bottom right of the price pane, not as an indicator line. Number does show in cursor window now.
My crude fix only gives me a "NaN" display at placement.
Using on YM seems ok, but on AB or NQ doesn't give tick increment, only number difference, do I need a divider on these?
I also want to calculate the difference of a 20LSMA (using 5 as the lookback), can I use this same template? I will place it just above the MADIFF number.
Can you please help?
Here is the code:
var fpArray = new Array();
function preMain() {
//changed the name of EFS and took off indicator line
setPriceStudy(true);
setStudyTitle("MADIFF");
setCursorLabelName("MADIFF", 0);
//setDefaultBarStyle(PS_SOLID, 0);
//setDefaultBarFgColor(Color.blue, 0);
//setDefaultBarThickness(1, 0);
//setPlotType(PLOTTYPE_LINE, 0);
askForInput();
var x=0;
//changed a few of the defaults
fpArray[x] = new FunctionParameter("DIFFLength", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(10);
}
fpArray[x] = new FunctionParameter("MAType", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("sma");
addOption("ema");
addOption("wma");
setDefault("ema");
}
fpArray[x] = new FunctionParameter("MALength", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(20);
}
fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("open");
addOption("high");
addOption("low");
addOption("close");
addOption("hl2");
addOption("hlc3");
addOption("ohlc4");
setDefault("hlc3");
}
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);
}
}
var bInit = false;
//changed name of variable
var xDIFFofMA = null;
function main(DIFFLength,MAType,MALength,Source,Symbol,Inte rval,Params)
{
if(bInit == false){
if(Symbol == null) Symbol = getSymbol();
if(Interval == null) Interval = getInterval();
var vSymbol = Symbol+","+Interval;
//change name of variable
xDIFFofMA = mom(DIFFLength,eval(MAType)(MALength,eval(Source)( sym(vSymbol))));
setShowTitleParameters(eval(Params));
bInit = true;
}
//tried to add text placement
drawTextAbsolute(5,0,xDIFFofMA.toFixed(0),null,nul l,Text.RELATIVETOBOTTOM | Text.BOLD|Text.VCENTER,"Arial",20,"MADIFF");
return getSeries(xDIFFofMA);
}
Any help would be greatly appreciated.
Thank you
My crude fix only gives me a "NaN" display at placement.
Using on YM seems ok, but on AB or NQ doesn't give tick increment, only number difference, do I need a divider on these?
I also want to calculate the difference of a 20LSMA (using 5 as the lookback), can I use this same template? I will place it just above the MADIFF number.
Can you please help?
Here is the code:
var fpArray = new Array();
function preMain() {
//changed the name of EFS and took off indicator line
setPriceStudy(true);
setStudyTitle("MADIFF");
setCursorLabelName("MADIFF", 0);
//setDefaultBarStyle(PS_SOLID, 0);
//setDefaultBarFgColor(Color.blue, 0);
//setDefaultBarThickness(1, 0);
//setPlotType(PLOTTYPE_LINE, 0);
askForInput();
var x=0;
//changed a few of the defaults
fpArray[x] = new FunctionParameter("DIFFLength", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(10);
}
fpArray[x] = new FunctionParameter("MAType", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("sma");
addOption("ema");
addOption("wma");
setDefault("ema");
}
fpArray[x] = new FunctionParameter("MALength", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(20);
}
fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("open");
addOption("high");
addOption("low");
addOption("close");
addOption("hl2");
addOption("hlc3");
addOption("ohlc4");
setDefault("hlc3");
}
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);
}
}
var bInit = false;
//changed name of variable
var xDIFFofMA = null;
function main(DIFFLength,MAType,MALength,Source,Symbol,Inte rval,Params)
{
if(bInit == false){
if(Symbol == null) Symbol = getSymbol();
if(Interval == null) Interval = getInterval();
var vSymbol = Symbol+","+Interval;
//change name of variable
xDIFFofMA = mom(DIFFLength,eval(MAType)(MALength,eval(Source)( sym(vSymbol))));
setShowTitleParameters(eval(Params));
bInit = true;
}
//tried to add text placement
drawTextAbsolute(5,0,xDIFFofMA.toFixed(0),null,nul l,Text.RELATIVETOBOTTOM | Text.BOLD|Text.VCENTER,"Arial",20,"MADIFF");
return getSeries(xDIFFofMA);
}
Any help would be greatly appreciated.
Thank you
Comment