• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Benjaminf, Today, 02:21 PM
0 responses
4 views
0 likes
Last Post Benjaminf  
Started by chrismcdermut, Today, 01:46 PM
1 response
6 views
0 likes
Last Post NinjaTrader_Kate  
Started by dpolyakov, Today, 01:13 PM
3 responses
14 views
0 likes
Last Post dpolyakov  
Started by tjendra, Today, 12:15 PM
3 responses
9 views
0 likes
Last Post tjendra
by tjendra
 
Started by lunardiplomacy, Today, 11:46 AM
4 responses
17 views
0 likes
Last Post lunardiplomacy  
Working...
X