Announcement

Collapse
No announcement yet.

BackTest Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • BackTest Problem

    Hi everyone!

    Since I'm new to Java programming, can anyone tell me why this script does not produce any backtest values? I want to test a formula with a ma average stop trigger. I want to be able to change parameter values in the backtest window frame.
    If this can be written in a shorter form, please feel free to do so!!!!

    Thanks for any help!!!
    Angelo

    /************************************************** *******
    By Alexis C. Montenegro for eSignal © December 2004
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a
    description of any changes you make.
    ************************************************** ********/

    var fpArray = new Array()
    var nNewTrade // new trade trigger
    var nsignal // long/short direction trigger
    var StopMargin // Incremental stop


    function preMain() {

    setPriceStudy(true);
    setStudyTitle("ADXDM_MA Strategy");
    setCursorLabelName("MA", 0);
    setDefaultBarFgColor(Color.RGB(255,104,32),0)
    setDefaultBarThickness(2,0);
    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(18);
    }
    fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(14);
    }
    fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setDefault("");
    }
    fpArray[x] = new FunctionParameter("Interval", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setDefault("");
    }
    fpArray[x] = new FunctionParameter("LineColor1", FunctionParameter.COLOR);
    with(fpArray[x++]){
    setName("DI+ Color");
    setDefault(Color.blue);
    }
    fpArray[x] = new FunctionParameter("LineColor2", FunctionParameter.COLOR);
    with(fpArray[x++]){
    setName("DI- Color");
    setDefault(Color.red);
    }
    fpArray[x] = new FunctionParameter("LineColor3", FunctionParameter.COLOR);
    with(fpArray[x++]){
    setName("ADX Color");
    setDefault(Color.magenta);
    }
    fpArray[x] = new FunctionParameter("Line1", FunctionParameter.STRING);
    with(fpArray[x++]){
    setName("Display DI+");
    addOption("ON");
    addOption("OFF");
    setDefault("ON");
    }
    fpArray[x] = new FunctionParameter("Line2", FunctionParameter.STRING);
    with(fpArray[x++]){
    setName("Display DI-");
    addOption("ON");
    addOption("OFF");
    setDefault("ON");
    }
    fpArray[x] = new FunctionParameter("Line3", FunctionParameter.STRING);
    with(fpArray[x++]){
    setName("Display ADX");
    addOption("ON");
    addOption("OFF");
    setDefault("OFF");
    }
    fpArray[x] = new FunctionParameter("LineHist", FunctionParameter.STRING);
    with(fpArray[x++]){
    setName("Hist ADX");
    addOption("LINE");
    addOption("HIST");
    setDefault("LINE");
    }
    fpArray[x] = new FunctionParameter("Type2", FunctionParameter.STRING);
    with(fpArray[x++]){
    addOption("sma");
    addOption("ema");
    addOption("wma");
    addOption("vwma");
    setDefault("sma");
    }
    fpArray[x] = new FunctionParameter("Length2", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(12);
    }
    fpArray[x] = new FunctionParameter("Source2", FunctionParameter.STRING);
    with(fpArray[x++]){
    addOption("open");
    addOption("high");
    addOption("low");
    addOption("close");
    addOption("hl2");
    addOption("hlc3");
    addOption("ohlc4");
    setDefault("close");
    }
    fpArray[x] = new FunctionParameter("Offset2", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setDefault(0);
    }
    fpArray[x] = new FunctionParameter("StopMargin", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(.25)
    setDefault(.25);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);

    }
    }
    var bInit = false;
    var xMA = null;
    var xADX = null;
    var xPDI = null;
    var xNDI = null;


    function main(Length,Smoothing,Symbol,Interval,LineColor1,L ineColor2,LineColor3,Line1,Line2,Line3,LineHist,
    Type2,Length2,Source2,Offset2,StopMargin,Params) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xADX = adx(Length,Smoothing,sym(vSymbol));
    xPDI = pdi(Length,Smoothing,sym(vSymbol));
    xNDI = ndi(Length,Smoothing,sym(vSymbol));
    xMA = offsetSeries(eval(Type2)(Length,eval(Source2)(sym( vSymbol))),Offset2);
    setShowTitleParameters(eval(Params));
    setStudyTitle(Symbol+ " MA "+Length2+" "+Interval);
    bInit = true;
    }



    // This Tests if stop is breached
    if (Strategy.isInTrade() == true && (Strategy.isLong() == true)){
    if (close <= (xMA + StopMargin)){
    Strategy.doSell("close Long", Strategy.CLOSE, Strategy.THISBAR, Strategy.getDefaultLotSize());
    }
    }
    if (Strategy.isInTrade() == true && (Strategy.isShort() == true)){
    if (close >= (xMa + StopMargin)){
    Strategy.doLong("close short", Strategy.CLOSE, Strategy.THISBAR, Strategy.getdefaultLotSize());
    }
    }

    // This executes a new Trade
    if(Strategy.isInTrade() == false){
    if((xPDI > xNDI) && (close >= (xMA + StopMargin))){
    nNewTrade = 1; //New trade trigger
    nsignal = 1 ; // Buy Signal
    }
    }
    if ((xNDI < xPDI) && (close <= (xMA + StopMargin))){
    nNewTrade = 1; //New trade trigger
    nsignal = -1 ; // Sell Signal
    }

    // Executes New Trade or (reverses one) if ONLY nNewtrade is triggered ...
    if(nNewTrade ==1 ){
    if (Strategy.isInTrade() == true) {
    if ((nsignal > 0) && (Strategy.isShort() == true)){
    Strategy.doCover("Exit short", Strategy.CLOSE, Strategy.THISBAR, Strategy.getdefaultLotSize());
    Strategy.doLong ( "Rev short", Strategy.CLOSE, Strategy.THISBAR, Strategy.getdefaultLotSize());
    }
    if ((nSignal < 0) && (Strategy.isLong() == true)){
    Strategy.doSell("Exit Long", Strategy.CLOSE, Strategy.THISBAR, Strategy.getdefaultLotSize());
    Strategy.doShort("Rev Long", Strtategy.CLOSE, Strategy.THISBAR, Strategy.getdefaultLotSize());
    }
    } else {
    if (nsignal > 0){
    Strategy.doLong("Go Long", Strategy.CLOSE, Strategy.THISBAR, getdefaultLotSize());
    }
    if (nsignal < 0){
    Strategy.doShort("Go Short", Strategy.CLOSE, Strategy.THISBAR, Strategy.getdefaultLotSize());
    }
    } // end if in Trade
    nNewTrade = 0;
    nsignal = 0;
    } //end execution of NEW TRADE


    if (close() >= xMA) {
    setPriceBarColor(Color.RGB(166,202,240));

    }else if(close() <= xMA){
    setPriceBarColor(Color.RGB(255,0,0));
    }


    return getSeries(xMA);
    }
    ang.

  • #2
    Hello Angelo,

    The code you have posted is using EFS2 functions, which will not work in version 7.8. If you are running the current 7.9 Beta, I would recommend that you revert back to 7.8 for your formula needs. At this time we only want those users who are more fluent with the formula language to test the EFS2 functionality. We won't be providing guidance for custom EFS2 development in this forum until the official release of 7.9.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment

    Working...
    X