var fpArray = []; var vMA1 = null; var xMA2 = null; var xMA3 = null; function preMain(){ setPriceStudy(true); setStudyTitle("EMA"); setCursorLabelName("EMA_1", 0); setDefaultBarFgColor(Color.blue, 0); setDefaultBarThickness(1, 0); setCursorLabelName("EMA_2", 1); setDefaultBarFgColor(Color.white, 1); setDefaultBarThickness(1, 1); setCursorLabelName("EMA_3", 2); setDefaultBarFgColor(Color.magenta, 2); setDefaultBarThickness(1, 2); var x=0; fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER); fpArray[x].setLowerLimit(1); fpArray[x++].setDefault(8); fpArray[x] = new FunctionParameter("Offset", FunctionParameter.NUMBER); fpArray[x++].setDefault(0); fpArray[x] = new FunctionParameter("IntervalTwo", FunctionParameter.NUMBER); fpArray[x].setLowerLimit(1); fpArray[x++].setDefault(2); fpArray[x] = new FunctionParameter("IntervalThree", FunctionParameter.NUMBER); fpArray[x].setLowerLimit(1); fpArray[x++].setDefault(3); fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING); with(fpArray[x++]){ setName("Source"); addOption("Close"); addOption("High"); addOption("Low"); addOption("Open"); addOption("HL/2"); addOption("HLC/3"); addOption("OHLC/4"); setDefault("Close"); } fpArray[x] = new FunctionParameter("Type", FunctionParameter.STRING); with(fpArray[x++]){ setName("Type"); addOption("MAStudy.SIMPLE"); addOption("MAStudy.EXPONENTIAL"); addOption("MAStudy.WEIGHTED"); addOption("MAStudy.VOLUMEWEIGHTED"); setDefault("MAStudy.EXPONENTIAL"); } } function main(Length, Offset, IntervalTwo, IntervalThree, Source, Type){ if(getBarState() == BARSTATE_ALLBARS){ vMA1 = new MAStudy(Length, Offset, Source, eval(Type)); xMA2 = ema(Length, close(inv(IntervalTwo))); xMA3 = ema(Length, close(inv(IntervalThree))); } if(vMA1.getValue(MAStudy.MA,0) > vMA1.getValue(MAStudy.MA,-1)) setBarFgColor(Color.green); else setBarFgColor(Color.red); return [vMA1.getValue(MAStudy.MA), xMA2.getValue(0), xMA3.getValue(0)]; }