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

Tick data conflicting with volume data?

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

    Tick data conflicting with volume data?

    I'm troubleshooting a larger strategy that I'm working on, and am gradually moving code over to a testing strategy to isolate the issue. When I add a single line of code, the strategy analyzer will show 0 trades. The single line of code is tick data to the StateConfigure area. I've tried two options, the one currently in place, and the one commented out:
    Code:
    else if (State == State.Configure)
                {
                    AddDataSeries("MES SEP23", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
                    //AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }​
    I do need tick data, as I'll be adding orderflow tools later on. I also want to add that even though I'm pulling in tick data, I'm using it on minute timeframes. Here is the whole code for the test strategy:
    Code:
    #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 volmatesting : Strategy
        {
            private OrderFlowCumulativeDelta cumulativeDelta;
            private EMA ema2;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Strategy here.";
                    Name                                        = "volmatesting";
                    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                            = 2;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;
    
                    VolMAPeriod = 60;
                    VolMultiplierHigh = 2.0;
                    VolMultiplierLow = 0.5;
                }
                else if (State == State.Configure)
                {
                    AddDataSeries("MES SEP23", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
                    //AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }
                else if (State == State.DataLoaded)
                {
                    ema2 = EMA(Volume, VolMAPeriod);
                }
            }
    
            protected override void OnBarUpdate()
            {
                double VolumeUpperBound = (ema2[0] * VolMultiplierHigh);
                double VolumeLowerBound = (ema2[0] * VolMultiplierLow);
    
                if (Volume[0] > VolumeUpperBound)
                    {
                       EnterLong(1, @"voltest");
                    }
                if (
                     (Volume[0] <= VolumeUpperBound)
                     && (Volume[0] >= VolumeLowerBound))
                    {
                        ExitLong(1, @"voltest", @"voltest");
                    }
                if ((Volume[0] <= VolumeLowerBound))
                    {
                        EnterShort(1, @"voltest");
                    }
                if (
                     (Volume[0] <= VolumeUpperBound)
                     && (Volume[0] >= VolumeLowerBound))​
                    {
                        ExitShort(1, @"voltest", @"voltest");
                    }
            }
            #region Properties
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="VolMAPeriod", Order=3, GroupName="Parameters")]
            public int VolMAPeriod
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, double.MaxValue)]
            [Display(Name="VolMultiplierHigh", Order=4, GroupName="Parameters")]
            public double VolMultiplierHigh
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(0.1, double.MaxValue)]
            [Display(Name="VolMultiplierLow", Order=5, GroupName="Parameters")]
            public double VolMultiplierLow
            { get; set; }
            #endregion
        }
    }​
    Please advise on how to still get volume data while pulling in tick data.

    Thank you!

    Edit:

    With more testing, starting from a different point, I've gathered that the specific conflict is between these lines:
    Code:
    double VolumeUpperBound = (ema2[0] * VolMultiplierHigh);
    double VolumeLowerBound = (ema2[0] * VolMultiplierLow);​
    and this line
    Code:
     AddDataSeries("MES SEP23", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
    I can calculate VolumeUpperBound and VolumeLowerBound and use them in the strategy if I don't add tick data, or I can have tick data if I comment out those two lines and just use the ema as a trading condition instead.
    Last edited by jourdale; 07-02-2023, 02:45 PM.

    #2
    Hello jourdale,

    Thanks for your post.

    In the code you shared I see your Entry and Exit orders are using the same Signal Name properties. Each Entry and Exit order should have unique signal names. For example, "Entry Long" for the long entry order, "Entry Short" for the short exit order, "Exit Long" for the long exit order, and "Exit Short" for the short exit order.

    What exactly is the issue you are having when using the code you shared?

    Do you see an error message appear in the Log tab of the Control Center? If so, what exactly does it report?

    Have you added debugging prints to the script to understand how your logic is evaluating?

    If not, debugging prints should be added to the strategy to understand how it is processing the logic in your script if you have not yet done so.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      The issue is that if I include tick data I can't create these doubles:
      Code:
      double VolumeUpperBound = (ema2[0] * VolMultiplierHigh);
      double VolumeLowerBound = (ema2[0] * VolMultiplierLow);​​
      If I do it will not produce any trades regardless of what I set them to. I know for a fact trades should be triggering. Either there's a conflict with ninjascript somewhere, or I've programmed this incorrectly. I'm leaning towards the latter.

      I will attempt to add debugging prints
      Last edited by jourdale; 07-02-2023, 06:25 PM.

      Comment


        #4
        Just an update, I was actually able to do everything I needed in the strategy builder. Thanks for the help!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rhyminkevin, Today, 04:58 PM
        4 responses
        52 views
        0 likes
        Last Post dp8282
        by dp8282
         
        Started by iceman2018, Today, 05:07 PM
        0 responses
        5 views
        0 likes
        Last Post iceman2018  
        Started by lightsun47, Today, 03:51 PM
        0 responses
        7 views
        0 likes
        Last Post lightsun47  
        Started by 00nevest, Today, 02:27 PM
        1 response
        14 views
        0 likes
        Last Post 00nevest  
        Started by futtrader, 04-21-2024, 01:50 AM
        4 responses
        50 views
        0 likes
        Last Post futtrader  
        Working...
        X