Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BackTest MACD

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

    BackTest MACD

    I would like to backtest going long or short when the MACD D Crosses Over or Under on a 0
    i want to know the diffrence between Walk Forward Optimization, Optimizer and BackTest and what is the role of the parameters (it's not clair for me) and how can i use it in my case, Thanks
    I use NinjaTrader 7.
    protected override void OnBarUpdate()
    {

    if(Historical){
    return ;
    }
    double value = MACD(fast, slow, smooth).Diff[0];
    if((value>0 && OpenOrder==null){
    {
    EnterLong(10, "O_MACDL");
    }

    if((value<0 && old_value>value) && OpenOrder!=null )
    {
    if(OpenOrder.OrderState.ToString()=="Filled")
    {

    ExitLong("C_MACDL,OpenOrder.Name);

    }
    }
    }

    #2
    Hello soma8,

    Thanks for your post.

    Please review the helpguide links below for an understanding of the differences and the use of.

    Backtest - A backtest allows you to analyze the historical performance of a strategy.
    Link to helpguide on running a backtest: http://ninjatrader.com/support/helpG...a_strategy.htm

    Optimize - Optimization is the process of testing a range of values through iterative backtests to determine the optimal input values over the historical test period based on your best result criterion.
    Link to helpguide on Optimize a strategy: http://ninjatrader.com/support/helpG...a_strategy.htm

    Walk forward - optimization is the process by which you optimize strategy input parameters on a historical segment of market data, then test the strategy forward in time on data following the optimization segment using the optimized input values. The central idea is that you evaluate strategy performance data on the test data, not the data used in the optimization. This process is then repeated by moving the optimization and test segments forward in time.
    Link to helpguide on Walkforward optimization: http://ninjatrader.com/support/helpG...e_a_strate.htm

    Note: As the backtest process uses only historical data, your first statement "if (Historical) {return;} would prohibit backtest functionality so you would need to comment that statement out for backtesting.

    Comment


      #3
      Thank you,

      I commented "if (Historical) {return;}"
      Can you please explain how can i use the parameters for my code?

      Comment


        #4
        Hello soma8,

        Thanks for your reply.

        In a nutshell, for example, with reference to your MACD variables of fast, slow, smooth you can opitimize over a range that you can set. Please review the video: http://ninjatrader.com/support/movie...A-Strategy.htm

        I recommend that you go through all of the previous links before jumping into optimizing to help you understand backtesting first.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        105 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        53 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        35 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        38 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        74 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X