Hello,
I have the problem the "Strategy Analyzer" do not give me the right results. In the EFS-Code below I can display the entry candels and exit candels at the "Formula Output" but the Strategy Analyzer does not make the entries and exits like are displayed at the "Formula Output". I don't understand why the Strategy Analyzer make a Long-Short Position every 5 minutes (see backtest1.jpg). My aim is it to get only the entry the exit candels(times) like they are in the efs - code. Maybe I am doing something wrong regarding the Strategy Analyzer Settings?!
Thanks for help.
regards
Roland
CODE
------------------------------------------------
var setcolor = true;
var aver = null;
var diffprev = null;
var diff0 = null;
var allhigh=null;
var alllow=null;
var highprev=null;
var lowprev=null;
var emastudy8 = ema(8);
var emastudy21 = ema(21);
var EMA8_0=null;
var EMA21_0=null;
var EMA_signal = false;
var close1 = null;
var close2 = null;
function preMain(){
setStudyTitle("Backtesting3");
setPriceStudy(true);
setColorPriceBars(true);
setDefaultPriceBarColor(Color.grey);
setShowCursorLabel(false);
var iAlert = new FunctionParameter("iAlert", FunctionParameter.BOOLEAN);
iAlert.setDefault( true );
var iDecimals = new FunctionParameter("iDecimals", FunctionParameter.NUMBER);
iDecimals.setDefault( 2 );
iDecimals.setName("Round to X decimals");
var iSymbol = new FunctionParameter("iSymbol", FunctionParameter.STRING);
iSymbol.setDefault( "AAPL" );
var iButtonX = new FunctionParameter("iButtonX", FunctionParameter.NUMBER);
iButtonX.setDefault( 150 );
var iButtonY = new FunctionParameter("iButtonY", FunctionParameter.NUMBER);
iButtonY.setDefault( 95 );
var iFontSize = new FunctionParameter("iFontSize", FunctionParameter.NUMBER);
iFontSize.setName("Button Font Size");
iFontSize.setDefault( 10 );
}
function main( iAlert, iDecimals, iFontSize, iButtonX, iButtonY ) {
if (getBarState() == BARSTATE_NEWBAR)
drawTextPixel(iButtonX, iButtonY, " TREND_ALERT @URL=EFS:editParameters", Color.white, Color.green,
Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.ONT OP|Text.BOLD|Text.BUTTON,
"Comic Sans MS", 13, "UpExp");
xSymbol1 = getSymbol().toUpperCase() ;
vSymbol1 = xSymbol1 +","+ "D";
var vHigh = high();
var vLow = low();
var vClose = close();
var open0 = open(0);
var close0 = close(0);
var high0 = high(0);
var low0 = low(0);
EMA8_0 = emastudy8.getValue(0);
EMA21_0 = emastudy21.getValue(0);
if(vHigh == null || vLow == null) {
return;
}
if (EMA_signal == false) {
debugPrintln (EMA_signal);
if (EMA8_0 >= EMA21_0) {
setPriceBarColor(Color.lime)
debugPrintln ("UP - "+close(0));
if ((Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
Strategy.doCover("Close Short Position",Strategy.CLOSE,Strategy.THISBAR); // Exits prior SHORT trade
debugPrintln ("Close Short!!!");
}
Strategy.doLong("Crossing Up",Strategy.CLOSE,Strategy.THISBAR); // Enters new LONG trade
EMA_signal = true;
}
}
if (EMA_signal == true) {
debugPrintln (EMA_signal);
if (EMA8_0 < EMA21_0) {
setPriceBarColor(Color.red)
debugPrintln ("DOWN - "+close(0));
if ((Strategy.isInTrade() == true) && (Strategy.isLong() == true)) {
Strategy.doSell("Close Long Position",Strategy.CLOSE,Strategy.THISBAR); // Exits prior LONG trade
debugPrintln ("Close Long!!!");
}
Strategy.doShort("Crossing Down",Strategy.CLOSE,Strategy.THISBAR); // Enters new SHORT trade
EMA_signal = false;
}
}
return;
}
function editParameters() {
askForInput(" TREND_ALERT ");
return;
}
//==rnd will round to N digits.
function rnd(value, N) {
var n;
var mult=1;
for(n=0;n<N;n++) mult*=10;
value*=mult;
return Math.round( value,N)/mult;
}
--------------------------------------------------
I have the problem the "Strategy Analyzer" do not give me the right results. In the EFS-Code below I can display the entry candels and exit candels at the "Formula Output" but the Strategy Analyzer does not make the entries and exits like are displayed at the "Formula Output". I don't understand why the Strategy Analyzer make a Long-Short Position every 5 minutes (see backtest1.jpg). My aim is it to get only the entry the exit candels(times) like they are in the efs - code. Maybe I am doing something wrong regarding the Strategy Analyzer Settings?!
Thanks for help.
regards
Roland
CODE
------------------------------------------------
var setcolor = true;
var aver = null;
var diffprev = null;
var diff0 = null;
var allhigh=null;
var alllow=null;
var highprev=null;
var lowprev=null;
var emastudy8 = ema(8);
var emastudy21 = ema(21);
var EMA8_0=null;
var EMA21_0=null;
var EMA_signal = false;
var close1 = null;
var close2 = null;
function preMain(){
setStudyTitle("Backtesting3");
setPriceStudy(true);
setColorPriceBars(true);
setDefaultPriceBarColor(Color.grey);
setShowCursorLabel(false);
var iAlert = new FunctionParameter("iAlert", FunctionParameter.BOOLEAN);
iAlert.setDefault( true );
var iDecimals = new FunctionParameter("iDecimals", FunctionParameter.NUMBER);
iDecimals.setDefault( 2 );
iDecimals.setName("Round to X decimals");
var iSymbol = new FunctionParameter("iSymbol", FunctionParameter.STRING);
iSymbol.setDefault( "AAPL" );
var iButtonX = new FunctionParameter("iButtonX", FunctionParameter.NUMBER);
iButtonX.setDefault( 150 );
var iButtonY = new FunctionParameter("iButtonY", FunctionParameter.NUMBER);
iButtonY.setDefault( 95 );
var iFontSize = new FunctionParameter("iFontSize", FunctionParameter.NUMBER);
iFontSize.setName("Button Font Size");
iFontSize.setDefault( 10 );
}
function main( iAlert, iDecimals, iFontSize, iButtonX, iButtonY ) {
if (getBarState() == BARSTATE_NEWBAR)
drawTextPixel(iButtonX, iButtonY, " TREND_ALERT @URL=EFS:editParameters", Color.white, Color.green,
Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.ONT OP|Text.BOLD|Text.BUTTON,
"Comic Sans MS", 13, "UpExp");
xSymbol1 = getSymbol().toUpperCase() ;
vSymbol1 = xSymbol1 +","+ "D";
var vHigh = high();
var vLow = low();
var vClose = close();
var open0 = open(0);
var close0 = close(0);
var high0 = high(0);
var low0 = low(0);
EMA8_0 = emastudy8.getValue(0);
EMA21_0 = emastudy21.getValue(0);
if(vHigh == null || vLow == null) {
return;
}
if (EMA_signal == false) {
debugPrintln (EMA_signal);
if (EMA8_0 >= EMA21_0) {
setPriceBarColor(Color.lime)
debugPrintln ("UP - "+close(0));
if ((Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
Strategy.doCover("Close Short Position",Strategy.CLOSE,Strategy.THISBAR); // Exits prior SHORT trade
debugPrintln ("Close Short!!!");
}
Strategy.doLong("Crossing Up",Strategy.CLOSE,Strategy.THISBAR); // Enters new LONG trade
EMA_signal = true;
}
}
if (EMA_signal == true) {
debugPrintln (EMA_signal);
if (EMA8_0 < EMA21_0) {
setPriceBarColor(Color.red)
debugPrintln ("DOWN - "+close(0));
if ((Strategy.isInTrade() == true) && (Strategy.isLong() == true)) {
Strategy.doSell("Close Long Position",Strategy.CLOSE,Strategy.THISBAR); // Exits prior LONG trade
debugPrintln ("Close Long!!!");
}
Strategy.doShort("Crossing Down",Strategy.CLOSE,Strategy.THISBAR); // Enters new SHORT trade
EMA_signal = false;
}
}
return;
}
function editParameters() {
askForInput(" TREND_ALERT ");
return;
}
//==rnd will round to N digits.
function rnd(value, N) {
var n;
var mult=1;
for(n=0;n<N;n++) mult*=10;
value*=mult;
return Math.round( value,N)/mult;
}
--------------------------------------------------
Comment