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

Error Backtesting and Optimizing a simple strategy

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

    Error Backtesting and Optimizing a simple strategy

    Good day.

    First of all, i want to say thanks to the incredible team of Ninjatrader to give us a such a great and powerful tool to trading the markets.

    Maybe my problem is simple but i've been searching about it and cannot find a solution.

    I created a FXCM Demo account, to test the Ninjatrader 8 software and learn how to use it, but even if i start backtesting or optimizing a simple strategy it appears an error "Strategy 'HMACruce/-1': An order placed at '02-01-2019 1:30:00' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.", and gives weird results like you can see on the screenshot i shared.
    If i test with the Sample MA Crossover strategy from the platform, don't appears the error but the weird results are there.

    This is a fresh installation, i don't changed any setting.

    There is a problem with my demo account? The instalation is corrupted? There is an additional setting that must to be done? I appreciate any help.

    Logic of the strategy of the screenshot

    #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 HMACruce_2019_11_01_06 : Strategy
    {
    private HMA HMA1;
    private HMA HMA2;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "HMACruce";
    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 = true;
    Target = 20;
    Stoploss = 15;
    HMALenta_Period = 14;
    HMARapida_Period = 5;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    HMA1 = HMA(Close, Convert.ToInt32(HMARapida_Period));
    HMA2 = HMA(Close, Convert.ToInt32(HMALenta_Period));
    SetProfitTarget("", CalculationMode.Ticks, Target);
    SetStopLoss("", CalculationMode.Ticks, Stoploss, false);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (CrossAbove(HMA1, HMA2, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if (CrossBelow(HMA1, HMA2, 1))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by NRITV, Today, 01:15 PM
1 response
5 views
0 likes
Last Post NinjaTrader_Jesse  
Started by maybeimnotrader, Yesterday, 05:46 PM
5 responses
24 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by quantismo, Yesterday, 05:13 PM
2 responses
16 views
0 likes
Last Post quantismo  
Started by frankthearm, Today, 09:08 AM
6 responses
27 views
0 likes
Last Post frankthearm  
Started by adeelshahzad, Today, 03:54 AM
5 responses
33 views
0 likes
Last Post NinjaTrader_BrandonH  
Working...
X