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 Natoc, Today, 03:04 AM
0 responses
2 views
0 likes
Last Post Natoc
by Natoc
 
Started by Rudy2323, Today, 02:56 AM
0 responses
5 views
0 likes
Last Post Rudy2323  
Started by BarakSel, Today, 02:13 AM
0 responses
8 views
0 likes
Last Post BarakSel  
Started by CarpetHooligan, Yesterday, 05:49 PM
0 responses
16 views
0 likes
Last Post CarpetHooligan  
Started by EquityTrader, Yesterday, 03:33 PM
0 responses
15 views
0 likes
Last Post EquityTrader  
Working...
X