Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

The backtest result is always zero!

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

    The backtest result is always zero!

    Hello.
    I wrote a strategy in Ninja and the test result was zero.
    I replaced the terms of the strategy with simple terms (which do not matter!).
    But still the result on time 1 minute of each symbol is zero.

    I get the data from the FXCM broker and my connection is established and there is a green circle at the bottom left of the screen.
    Also, the ninja sample strategy, which is SMA 10-25 cross, has non-zero results (so the data is connected!)

    what is the problem ?

    In this section, I will put the sample code with simple conditions! :

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class TEST : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Let's do it!";
    Name = "TEST";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = false;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if(Low[0] < Low[1] && Low[1] < Low[2])
    EnterLong(100,@"Long");

    if(High[0] > High[1] && High[1] > High[2])
    EnterShort(100,@"Short");

    }
    }
    }
    Thanks for your help

    #2
    Hello alichi50,

    Thank you for your note.

    When testing the code you shared, I am seeing the following error message appear in the Log tab of the Control Center.

    Error on calling OnBarUpdate method on bar 0: ....

    This error indicates that there are not enough bars loaded before the strategy processes. To ensure there are enough bars loaded, you would need to add a CurrentBar check to your strategy at the top of the OnBarUpdate() method. The code would look something like this.

    If (CurrentBar < 1)
    return;

    See the help guide documentation below for more information.
    Make sure you have enough bars - https://ninjatrader.com/support/help...ou+have+enough

    I look forward to assisting further.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by r68cervera, Today, 05:29 AM
    0 responses
    3 views
    0 likes
    Last Post r68cervera  
    Started by geddyisodin, Today, 05:20 AM
    0 responses
    6 views
    0 likes
    Last Post geddyisodin  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    6 responses
    35 views
    0 likes
    Last Post JonesJoker  
    Started by GussJ, 03-04-2020, 03:11 PM
    12 responses
    3,241 views
    0 likes
    Last Post Leafcutter  
    Started by AveryFlynn, Today, 04:57 AM
    0 responses
    7 views
    0 likes
    Last Post AveryFlynn  
    Working...
    X