There have been a number of posts concerning use of getSeries and displaying an indicator from one time frame in another.
However I wish to display a histogram type indicator using assigned values for certain events and cannot see how to build a series so that the indicator is drawn properly without having to refresh it continually.
Any help to a solution would be welcome.
Robert
However I wish to display a histogram type indicator using assigned values for certain events and cannot see how to build a series so that the indicator is drawn properly without having to refresh it continually.
Any help to a solution would be welcome.
Robert
PHP Code:
/*************************************************************
Title : Donchian Channel Histogram
By : Robert Cameron
Incept : July 27, 2013
Version : 0.0.0
--------------------------------------------------------------
**************************************************************
Release History
**************************************************************
July 27, 2013 - Inception & Prototype
0.0.0
==============================================================
*/
// Used in preMain() for user selection
var fpArray = new Array();
// ###########################################################
function preMain(){
// ###########################################################
// STUDY FIXED PARAMETERS
setPriceStudy(false);
setStudyTitle("DCH");
// VARIABLES
var x=0;
// USER SELECTION
//-----------------------
// Donchian
fpArray[x] = new FunctionParameter("nDCLengthP", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(10); //10
}
fpArray[x] = new FunctionParameter("sDCTriggerP", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("open");
addOption("high");
addOption("low");
addOption("close");
addOption("hl2");
addOption("hlc3");
addOption("ohlc4");
setDefault("close"); //close
}
fpArray[x] = new FunctionParameter( "sOscStyP", FunctionParameter.STRING);
with(fpArray[x++]){
setName("Oscillator Style");
addOption("SOLID");
addOption("DASH");
addOption("DOT");
addOption("DASHDOT");
addOption("DASHDOTDOT");
setDefault( "SOLID" );
}
fpArray[x] = new FunctionParameter( "nOscThckP", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Oscillator Thickness");
setLowerLimit( 1 );
setUpperLimit( 10 );
setDefault( 5 );
}
fpArray[x] = new FunctionParameter( "sOscPltP", FunctionParameter.STRING);
with(fpArray[x++]){
setName("Oscillator Plot");
addOption("LINE");
addOption("CIRCLE");
addOption("DOT");
addOption("SQUARE");
addOption("SQUAREWAVE");
addOption("HISTOGRAM");
addOption("FLATLINES");
addOption("INSTANTCOLORLINE");
setDefault( "HISTOGRAM" );
}
//Symbol & Interval
fpArray[x] = new FunctionParameter("sSymbolP", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("sIntervalP", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
// Base Line
fpArray[x] = new FunctionParameter( "cBLP", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("BL Color");
setDefault( Color.yellow); //yellow
}
fpArray[x] = new FunctionParameter( "sBLStyP", FunctionParameter.STRING);
with(fpArray[x++]){
setName("BL Style");
addOption("SOLID");
addOption("DASH");
addOption("DOT");
addOption("DASHDOT");
addOption("DASHDOTDOT");
setDefault( "SOLID" );
}
fpArray[x] = new FunctionParameter( "nBLThckP", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("BL Thickness");
setLowerLimit( 1 );
setUpperLimit( 2 );
setDefault( 1 );
}
// Oscillator Colors
fpArray[x] = new FunctionParameter( "cTrEStUP", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Up");
setDefault( Color.white); //white
}
fpArray[x] = new FunctionParameter( "cTrEStDP", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Dn");
setDefault( Color.magenta); //magenta
}
fpArray[x] = new FunctionParameter( "cTrNTP", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("No Trend");
setDefault( Color.yellow); //yellow
}
// Points
// MDC
fpArray[x] = new FunctionParameter( "nMDC_STL", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("MDC Limit");
setLowerLimit( 0 );
setDefault( 0.5 ); //0.5
}
// ==========================================================
} // END PreMain Function
// ==========================================================
// ##########################################################
// MAIN
function main(
nDCLengthP, sDCTriggerP, sOscStyP, nOscThckP, sOscPltP, sSymbolP, sIntervalP, cBLP,
sBLStyP, nBLThckP, cTrEStUP, cTrEStDP, cTrNTP, nMDC_STL
){
// ##########################################################
// ****************************************
if ( getBarState() == BARSTATE_ALLBARS ){
// ----------------------------------------
/////////////////////////////////////
// Set up Line Drawing & Cursor Info
setDefaultBarFgColor(cTrNTP, 0);
setDefaultBarStyle(eval("PS_"+sOscStyP), 0);
setDefaultBarThickness(nOscThckP, 0);
setCursorLabelName("DCH", 0);
setPlotType(eval("PLOTTYPE_"+sOscPltP), 0);
// SYMBOL & INTERVAL
if(sSymbolP == null) sSymbolP = getSymbol();
if(sIntervalP == null) sIntervalP = getInterval();
vSymbol = sSymbolP+","+sIntervalP;
// STUDIES & VARIABLES
xMDC = middleDonchian(nDCLengthP,sym(vSymbol));
var vMDCm;
xDCSource = eval(sDCTriggerP+"('" + vSymbol + "')"); //usually close('ES M3,1500T')
var vDCSrcM;
var rMDCm;
// Base Line
addBand(0, eval("PS_"+sBLStyP), nBLThckP, cBLP, "Center");
// ----------------------------------------
return null;
} // END ALLBARS
// ========================================
////////////////////////////////////////////
// This will return null if no data exists for the given symbol
if (getOldestBarIndex() == null) return;
//////////
// CALCULATION AREA
vMDCm = getSeries(xMDC);
vDCSrcM = getSeries(xDCSource);
// Mid Donchian Channel vs close
if (vDCSrcM>vMDCm){
rMDCm=nMDC_STL;
}else if (vDCSrcM<vMDCm){
rMDCm=-nMDC_STL;
}else{
rMDCm=0;
}
// ****************************************
// COLORING AREA
// ----------------------------------------
if (rMDCm >=nMDC_STL){
setDefaultBarFgColor(cTrEStUP, 0);
}else if (rMDCm <=nMDC_STL){
setDefaultBarFgColor(cTrEStDP, 0);
}else{
setDefaultBarFgColor(cTrNTP, 0);
}
// ----------------------------------------
// END COLORING AREA
// ========================================
// ****************************************
// DISPLAY RESULT
// ----------------------------------------
return rMDCm;
// ----------------------------------------
// END DISPLAY RESULT
// ========================================
// ========================================================
} // END Main Processing Function
// ========================================================
Comment