OK I used ichimoku(alerts).efs and modified it to become a SAR strategy with stops and limits, display arrows, text, and send me emails. That all works, my question is related to the picture below. The TS line and the KS line cross more than once in the snapshot below, but "long" and "short" and the arrows are only displayed once. What did I do wrong here?
Here's the script. Any help would be appreciated.
Oh, the yelllow line is a WMA so disregard that. I plan on further modifying the strategy to only enter long trades if it is above the cloud and the WMA is moving up. The opposite goes for short trades. I just need to get past this problem so I can make sure my backtesting results are accurate. Thanks!
Here's the script. Any help would be appreciated.
PHP Code:
/********************************
Original file ichimoku(alerts).efs by
Alexis C. Montenegro © June 2003
Ichimoku Euro.efs is an adaptation of
the original file by McLean Van Cleve
*********************************/
var vDonchian = new DonchianStudy(7, 0);
var vDonchian_2 = new DonchianStudy(22, 0);
var vDonchian_3 = new DonchianStudy(7, 22);
var vDonchian_4 = new DonchianStudy(22, 22);
var vDonchian_5 = new DonchianStudy(44, 22);
var vCntr = 0;
function preMain() {
setPriceStudy(true);
setStudyTitle("Ichimoku");
setCursorLabelName("Tenkan", 0);
setCursorLabelName("Kijun", 1);
setCursorLabelName("Chikou", 2);
setCursorLabelName("SenkouA", 3);
setCursorLabelName("SenkouB", 4);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarStyle(PS_SOLID, 2);
setDefaultBarStyle(PS_SOLID, 3);
setDefaultBarStyle(PS_SOLID, 4);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.magenta, 2);
setDefaultBarFgColor(Color.black, 3);
setDefaultBarFgColor(Color.black, 4);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(2, 1);
setDefaultBarThickness(2, 2);
setDefaultBarThickness(2, 3);
setDefaultBarThickness(2, 4);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
setPlotType(PLOTTYPE_LINE, 2);
setPlotType(PLOTTYPE_LINE, 3);
setPlotType(PLOTTYPE_LINE, 4);
var fp1 = new FunctionParameter("MinTick", FunctionParameter.NUMBER);
fp1.setDefault(0.0001); //Edit this value to set a new default
var fp2 = new FunctionParameter("Profit", FunctionParameter.NUMBER);
fp2.setName("Ticks Profit");
fp2.setDefault(40); //Edit this value to set a new default
var fp3 = new FunctionParameter("Stop", FunctionParameter.NUMBER);
fp3.setName("Ticks Stop");
fp3.setDefault(40); //Edit this value to set a new default
}
var vEntryPrice = 0;
var vTargetPrice = 0;
var vStopPrice = 0;
var BarCntr = 0;
function main(MinTick,Profit,Stop) {
var space = 1;
if (getInterval() != "D")
space = high(-1)-low(-1);
if(getBarState()==BARSTATE_NEWBAR){
vCntr +=1;
}
if(vCntr<53)
return;
var SenkouA = (vDonchian_3.getValue(DonchianStudy.BASIS)+vDonchian_4.getValue(DonchianStudy.BASIS))/2;
if(SenkouA>vDonchian_5.getValue(DonchianStudy.BASIS))
setBarBgColor(Color.white,0,vDonchian_5.getValue(DonchianStudy.BASIS),SenkouA);
if(SenkouA<vDonchian_5.getValue(DonchianStudy.BASIS))
setBarBgColor(Color.white,0,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS));
if(getBarState()==BARSTATE_NEWBAR){
if(vDonchian.getValue(DonchianStudy.BASIS,-2)<=vDonchian_2.getValue(DonchianStudy.BASIS,-2)&&
vDonchian.getValue(DonchianStudy.BASIS,-1)>vDonchian_2.getValue(DonchianStudy.BASIS,-1)){
drawTextRelative(0,low(),"é",Color.blue,null,Text.TOP|Text.CENTER|Text.BOLD,"Wingdings",12,"Up"+ BarCntr);
drawTextRelative(-1, low(-1)-(space*0.55),"Long",Color.white,Color.blue,Text.FRAME|Text.ONTOP|Text.BOLD, null,12,"text buy"+BarCntr );
Strategy.doLong("Long",Strategy.MARKET,Strategy.THISBAR);
vEntryPrice = open(0);
vTargetPrice = vEntryPrice+(Profit*MinTick);
vStopPrice = vEntryPrice-(Stop*MinTick);
Alert.playSound("long_eur.wav");
Alert.email("Buy EUR/USD", "Buy EUR/USD" );
}
if(vDonchian.getValue(DonchianStudy.BASIS,-2)>=vDonchian_2.getValue(DonchianStudy.BASIS,-2)&&
vDonchian.getValue(DonchianStudy.BASIS,-1)<vDonchian_2.getValue(DonchianStudy.BASIS,-1)){
drawTextRelative(0,high(),"ê",Color.red,null,Text.BOTTOM|Text.CENTER|Text.BOLD,"Wingdings",12,"Dn"+ BarCntr);
drawTextRelative(-1,high(-1)+(space*0.55),"Short",Color.white,Color.red,Text.FRAME|Text.BOTTOM|Text.BOLD,null,12,"text sell"+BarCntr );
Strategy.doShort("Short",Strategy.MARKET,Strategy.THISBAR);
vEntryPrice = open(0);
vTargetPrice = vEntryPrice-(Profit*MinTick);
vStopPrice = vEntryPrice+(Stop*MinTick);
Alert.playSound("short_eur.wav");
Alert.email("Sell EUR/USD", "Sell EUR/USD" );
}
}
if(Strategy.isLong()==true){
if(high(0)>=vTargetPrice){
Strategy.doSell("Profit Sell",Strategy.STOP,Strategy.THISBAR,null,vTargetPrice);
}
if(low(0)<=vStopPrice){
Strategy.doSell("Stop Sell",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
}
}
if(Strategy.isShort()==true){
if(low(0)<=vTargetPrice){
Strategy.doCover("Profit Cover",Strategy.STOP,Strategy.THISBAR,null,vTargetPrice);
}
if(high(0)>=vStopPrice){
Strategy.doCover("Stop Cover",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
}
}
if(getBarState() == BARSTATE_NEWBAR){
var nNum = 1;
}else{
var nNum = 0;
}
if(getBuildNumber()>636){
setBar(Bar.Value,-26+nNum,2,close(0));
}else{
setBar(Bar.Value,-26+nNum,new Array(null,null,close(0),null,null));
}
return new Array(vDonchian.getValue(DonchianStudy.BASIS),vDonchian_2.getValue(DonchianStudy.BASIS),
null,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS));
}
Comment