Backtesting shows orders that should not have triggered, why?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #166141 quote
    JakobFreimannJakobFreimann
    Participant
    New

    Hi everyone,

    I am just starting out learning how to code with very simple scripts. The code below should trigger a Long Order when the MA20 crosses above the MA50 and sell when the MA20 goes below the MA50. However when backtesting there are a lot of orders that where triggered that shouldn’t have been. Am I doing something obviously wrong?

    // Conditions to enter long positions// Conditions to enter long positions
    IF NOT LongOnMarket AND Average[20](close) CROSSES OVER Average[50](close) THEN
    BUY 20 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    If LongOnMarket AND Average[20](close) CROSSES UNDER Average[50](close)THEN
    SELL AT MARKET
    ENDIF

     

    See attached image for trade that should not have been triggered.

    Any pointers really appreciated. Also I did not find a search on the forum, I am sure this was asked before. If there is a search please let me know.

    Screen-Shot-2021-04-04-at-11.28.40-am.png Screen-Shot-2021-04-04-at-11.28.40-am.png
    #166153 quote
    GraHalGraHal
    Participant
    Master

    Your code shows SMA and your image shows EMA.

    #166179 quote
    JakobFreimannJakobFreimann
    Participant
    New

    oh.. thanks. Fixed it and now seems to be working fine.

    GraHal thanked this post
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Backtesting shows orders that should not have triggered, why?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by JakobFreimannJakobFreimann
5 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/04/2021
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...