Announcement

Collapse
No announcement yet.

wrong display when Strategy.XXX functions are used

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

  • wrong display when Strategy.XXX functions are used

    I hv written below EFS based on MA crossover. One of the line will change color (long: orange, short: red, white: no position). However, after adding a few rows for backtesting (Strategy.xxx), the line is not showing the correct result again.

    The problem happens for row 61/62. The strange thing is that it displays wrong color for Strategy.isInTrade(). However, if I change it to Strategy.isShort(), the color is correct. So what is wrong?

    - correct display for Strategy.isShort()


    - wrong display for Strategy.isLong() or Strategy.isInTrade()


    - EFS
    var EMA_Interval_0 = 10;
    var EMA_Interval_1 = 30;
    var EMA_Interval_2 = 60;
    var nMALength = 20;

    var OverallTrend = "No Trend";

    var EMA0FgColor = Color.grey;

    function preMain()
    {
    var x=0;
    setPriceStudy(true);
    setStudyTitle("System backtest");
    setCursorLabelName("EMA2",0);
    setDefaultBarThickness(4,0);
    setDefaultBarFgColor(Color.blue,0);
    setCursorLabelName("EMA1",1);
    setDefaultBarThickness(4,1);
    setDefaultBarFgColor(Color.purple,1);
    setCursorLabelName("EMA0",2);
    setDefaultBarThickness(4,2);
    setDefaultBarFgColor(Color.cyan,2);

    setComputeOnClose(true);

    }


    function main()
    {
    vEMA0 = ema(nMALength, inv(EMA_Interval_0));
    vEMA1 = ema(nMALength, inv(EMA_Interval_1));
    vEMA2 = ema(nMALength, inv(EMA_Interval_2));

    if ( vEMA0==null || vEMA1==null || vEMA2==null ) return;

    OverallTrend_previous=OverallTrend;
    if ( vEMA0>vEMA1 && vEMA1>vEMA2 )
    OverallTrend = "Up";
    else if ( vEMA0<vEMA1 && vEMA1<vEMA2 )
    OverallTrend = "down";
    else
    OverallTrend = "No Trend";

    switch (OverallTrend) {
    case "Up":
    EMA0FgColor = Color.RGB(255,128,0);
    if ( !Strategy.isInTrade() ) {
    Strategy.doLong("Long",Strategy.MARKET,Strategy.NE XTBAR);
    }
    break;
    case "Down":
    EMA0FgColor = Color.magenta;
    if ( !Strategy.isInTrade() )
    Strategy.doShort("Short",Strategy.MARKET,Strategy. NEXTBAR);
    break;
    case "No Trend":
    EMA0FgColor = Color.white;

    if ( Strategy.isInTrade() ) {
    Strategy.doCover("Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.ALL);
    }
    break;
    default:
    }
    setDefaultBarFgColor(EMA0FgColor,2);

    return new Array (vEMA2, vEMA1, vEMA0);
    }
    Last edited by Richard Yu; 07-24-2005, 07:50 PM.

  • #2
    the file
    Attached Files

    Comment


    • #3
      I hv found the mistake. I hv misunderstood the use of the different Strategy.XXX functions and hv corrected them (attached here). However, the backtest results are not showing the runups and drawdown info. The figures/charts under the tabs "periodic analysis" and "graphs" are completely missing. Pls advise. thx.
      Attached Files

      Comment


      • #4
        Attached is the Analyzer output in html format
        Attached Files

        Comment


        • #5
          Richard
          The problem is that you define OverallTrend = "down" but then you look for case = "Down"
          Alex

          Comment


          • #6
            I hv changed it from "down" to "Down" but there are still no figures/charts under the tabs "periodic analysis" and "graphs". Pls advise. thx.
            Attached Files

            Comment


            • #7
              Richard
              Remove setComputeOnClose() which is not required when running a back test
              Alex

              Comment

              Working...
              X