Hello,
Would you please help me with this code that is not working ?
Thank you
/*---------------------------------------------------------------------------------------------------
INDICATOR: PIERRE JMA JMA crossover
DESCRIPTION: Plots two SMA and two JMA moving averages.
Trades on both SMA crossing JMA
----------------------------------------------------------------------------------------------------*/
function preMain() {
setStudyTitle("PIERRE MA5-JMA5 MA10 JMA10 CO V4");
setDefaultBarFgColor(Color.cyan, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarFgColor(Color.yellow, 3);
setDefaultBarThickness(2,0);
setPlotType(PLOTTYPE_INSTANTCOLORLINE);
setPriceStudy(true);
}
var vJMA1, vJMA2, vSMA1, vSMA2;
var vHigh;
var vLow;
var BarCntr = 0;
var study1 = null
var study2 = null
function main(Price, JMA_len1, JMA_phase1, JMA_len2, JMA_phase2, offset, _BGcolor) {
//{{Action 1 condition
if (
vJMA1 >= vSMA1
&&
vJMA2 >= vSMA2
) onAction1()
//}}End Action 1
//{{Action 2 Condition
else if (
vJMA1 < vSMA1
&&
vJMA2 < vSMA2
) onAction2();
//}}End Action 2
/* input validation */
if (Price == null) Price = "Close"; else if (typeof(Price) != "string") return;
if (JMA_len1 == null) JMA_len1 = 5; else if (JMA_len1 < 0) JMA_len1 = 0;
if (JMA_phase1 == null) JMA_phase1 = 0; else JMA_phase1 = Math.min(100,Math.max(-100,JMA_phase1)) ;
if (JMA_len2 == null) JMA_len2 = 10; else if (JMA_len2 < 0) JMA_len2 = 0;
if (JMA_phase2 == null) JMA_phase2 = 0; else JMA_phase2 = Math.min(100,Math.max(-100,JMA_phase2)) ;
if (offset == null) offset = 0; else offset = Math.round(offset) ;
if (_BGcolor == null) _BGcolor = 1;
/* initialization */
if (getBarState() == BARSTATE_ALLBARS) {
myJMAstudy1 = new JurikJMAStudy(JMA_len1,JMA_phase1,0,Price);
myJMAstudy2 = new JurikJMAStudy(JMA_len2,JMA_phase2,offset,Price);
mySMAstudy1 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
mySMAstudy2 = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);
}
/* core program */
vJMA1 = myJMAstudy1.getValue(JurikJMAStudy.JMA) ;
vJMA2 = myJMAstudy2.getValue(JurikJMAStudy.JMA) ;
if(study1 == null) study1 = sma(5);
var vSMA1 = study1.getValue(0);
if(vSMA1 == null)
return;
if(study2 == null) study2 = sma(10);
var vSMA2 = study2.getValue(0);
if(vSMA2 == null)
return;
/* trading conditions */
if (vJMA1 == null || vJMA2 == null || vSMA1 == null || vSMA2 == null) return;
function onAction1() {
if(!Strategy.ishort()) {
Strategy.doCover("CrossUp cut shorts", Strategy.OPEN, Strategy.NEXTBAR);
}
if(!Strategy.isLong()) {
setBarFgColor(Color.cyan) ;
}
else Strategy.doLong("Crossing Up", Strategy.OPEN, Strategy.NEXTBAR);
setBarFgColor(Color.cyan) ;
}
function onAction2() {
if(!Strategy.isLong()) {
Strategy.doSell("CrossDn cut longs", Strategy.OPEN, Strategy.NEXTBAR);
}
if(!Strategy.isShort()) {
setBarFgColor(Color.red) ;
}
else Strategy.doShort("Crossing Down", Strategy.OPEN, Strategy.NEXTBAR);
setBarFgColor(Color.red) ;
}
return new Array(vJMA1, vJMA2, vSMA1, vSMA2);
}
Would you please help me with this code that is not working ?
Thank you
/*---------------------------------------------------------------------------------------------------
INDICATOR: PIERRE JMA JMA crossover
DESCRIPTION: Plots two SMA and two JMA moving averages.
Trades on both SMA crossing JMA
----------------------------------------------------------------------------------------------------*/
function preMain() {
setStudyTitle("PIERRE MA5-JMA5 MA10 JMA10 CO V4");
setDefaultBarFgColor(Color.cyan, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarFgColor(Color.yellow, 3);
setDefaultBarThickness(2,0);
setPlotType(PLOTTYPE_INSTANTCOLORLINE);
setPriceStudy(true);
}
var vJMA1, vJMA2, vSMA1, vSMA2;
var vHigh;
var vLow;
var BarCntr = 0;
var study1 = null
var study2 = null
function main(Price, JMA_len1, JMA_phase1, JMA_len2, JMA_phase2, offset, _BGcolor) {
//{{Action 1 condition
if (
vJMA1 >= vSMA1
&&
vJMA2 >= vSMA2
) onAction1()
//}}End Action 1
//{{Action 2 Condition
else if (
vJMA1 < vSMA1
&&
vJMA2 < vSMA2
) onAction2();
//}}End Action 2
/* input validation */
if (Price == null) Price = "Close"; else if (typeof(Price) != "string") return;
if (JMA_len1 == null) JMA_len1 = 5; else if (JMA_len1 < 0) JMA_len1 = 0;
if (JMA_phase1 == null) JMA_phase1 = 0; else JMA_phase1 = Math.min(100,Math.max(-100,JMA_phase1)) ;
if (JMA_len2 == null) JMA_len2 = 10; else if (JMA_len2 < 0) JMA_len2 = 0;
if (JMA_phase2 == null) JMA_phase2 = 0; else JMA_phase2 = Math.min(100,Math.max(-100,JMA_phase2)) ;
if (offset == null) offset = 0; else offset = Math.round(offset) ;
if (_BGcolor == null) _BGcolor = 1;
/* initialization */
if (getBarState() == BARSTATE_ALLBARS) {
myJMAstudy1 = new JurikJMAStudy(JMA_len1,JMA_phase1,0,Price);
myJMAstudy2 = new JurikJMAStudy(JMA_len2,JMA_phase2,offset,Price);
mySMAstudy1 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
mySMAstudy2 = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);
}
/* core program */
vJMA1 = myJMAstudy1.getValue(JurikJMAStudy.JMA) ;
vJMA2 = myJMAstudy2.getValue(JurikJMAStudy.JMA) ;
if(study1 == null) study1 = sma(5);
var vSMA1 = study1.getValue(0);
if(vSMA1 == null)
return;
if(study2 == null) study2 = sma(10);
var vSMA2 = study2.getValue(0);
if(vSMA2 == null)
return;
/* trading conditions */
if (vJMA1 == null || vJMA2 == null || vSMA1 == null || vSMA2 == null) return;
function onAction1() {
if(!Strategy.ishort()) {
Strategy.doCover("CrossUp cut shorts", Strategy.OPEN, Strategy.NEXTBAR);
}
if(!Strategy.isLong()) {
setBarFgColor(Color.cyan) ;
}
else Strategy.doLong("Crossing Up", Strategy.OPEN, Strategy.NEXTBAR);
setBarFgColor(Color.cyan) ;
}
function onAction2() {
if(!Strategy.isLong()) {
Strategy.doSell("CrossDn cut longs", Strategy.OPEN, Strategy.NEXTBAR);
}
if(!Strategy.isShort()) {
setBarFgColor(Color.red) ;
}
else Strategy.doShort("Crossing Down", Strategy.OPEN, Strategy.NEXTBAR);
setBarFgColor(Color.red) ;
}
return new Array(vJMA1, vJMA2, vSMA1, vSMA2);
}
Comment