Announcement

Collapse
No announcement yet.

backtester won't calculate

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

  • backtester won't calculate

    Backtester won't calculate the difference in values between trade entry and exit points.

    Lists all the appropriate trade entry and exit price points, just will not differentiate between Long and Shorts

    below is a sample of the backtest code that is being called. There is no question that the overalL trading strategy routine works because the changes in bar colors are correct and also this routine is being used successfully in fully automated order execution routines,

    I am included two snippets of code;

    the first is what is being used to determine Buy/Sell signals for visual alert by changing chart bar colors. These are the same variable used in the automation routines as well;

    the second set is where the back test commands have been added, producing the results mentioned above

    if (vSMA < SLAMAValue) {

    setPriceBarColor(Color.green);
    setBarThickness(2);
    setBarFgColor(Color.green);


    } else if(SLAMAValue < vSMA) {
    setPriceBarColor(Color.red);
    setBarThickness(2);
    setBarFgColor(Color.red);

    }

    vlastSLAMAValue=SLAMAValue;
    return new Array(SLAMAValue,vSMA);

    Here is the backtest code that is being used

    if(vSMA < SLAMValue && !Strategy.isLong())
    Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);

    {
    setPriceBarColor(Color.green);
    setBarThickness(2);
    setBarFgColor(Color.green);


    } else if(SLAMAValue < vSMA) {
    if(SLAMAValue < vSMA && !Strategy.isShort())
    Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);


    setPriceBarColor(Color.red);
    setBarThickness(2);
    setBarFgColor(Color.red);

    }

    vlastSLAMAValue=SLAMAValue;
    return new Array(SLAMAValue,vSMA);

  • #2
    stockwolf
    Have you tried running a back test using (for example) the BtMovingAverage.efs which has a similar logic?
    I also created the sample efs enclosed below and as far as I can see the Back Tester is reporting all the appropriate values
    Alex

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("MAx2");
        
    setCursorLabelName("MA1",0);
        
    setCursorLabelName("MA2",1);
        
    setDefaultBarFgColor(Color.blue,0);
        
    setDefaultBarFgColor(Color.red,1);
    }

    var 
    xMA1 null;
    var 
    xMA2 null;

    function 
    main() {

        if(
    xMA1==nullxMA1 sma(5);
        if(
    xMA2==nullxMA2 sma(15);
        
        var 
    SMA1 xMA1.getValue(0);
        var 
    SMA2 xMA2.getValue(0);
        if(
    SMA1==null ||SMA2==null) return;
        
        if(
    SMA1>SMA2 && !Strategy.isLong()){
            
    Strategy.doLong("Long",Strategy.CLOSE,Strategy.THISBAR);
        } else if (
    SMA1<SMA2 && !Strategy.isShort()){
            
    Strategy.doShort("Short",Strategy.CLOSE,Strategy.THISBAR);
        }

        return new Array (
    SMA1,SMA2);

    Comment

    Working...
    X