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

CrossOver Intrabar Execution Issue | Need multiple entries intrabar

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

    CrossOver Intrabar Execution Issue | Need multiple entries intrabar

    Hi, I am having an issue with my Intrabar strategy, I would like the executions intrabar to occur on crossover's intrabar. Most of the time there is multiple crossover events intrabar but my strategy is only executing once per bar. Ocassionally running it on sim with live data I will get multiple triggers on the same bar, but I think there is something wrong with my code. Please help


    Hi, I am having an issue with my Intrabar strategy, I would like the executions intrabar to occur on crossover's intrabar. Most of the time there is multiple crossover events intrabar but my strategy is only executing once per bar. Ocassionally running it on sim with live data I will get multiple triggers on the same bar, but I think there is something wrong with my code. Please help

    Is there a method to calculate faster than each tick? I'm building a high frequency strategy and will need the quickest execution when crossovers occur.



    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class PriceActionBotV2 : Strategy
    {
    private Line X Line X1;
    private Line Y Line Y1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "PriceActionBotV2";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.High;
    OrderFillResolutionType = BarsPeriodType.Minute;
    OrderFillResolutionValue = 1;
    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;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    Line X1 = Line X(Close);
    Line Y1 = Line Y(Close);
    Line X1.Plots[0].Brush = Brushes.Navy;
    Line Y1.Plots[0].Brush = Brushes.Orange;
    AddChartIndicator(Line X1);
    AddChartIndicator(Line Y1);
    }
    }

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

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (CrossAbove(Line X1, Line Y1, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"long");
    }

    // Set 2
    if (CrossBelow(Line X1, Line Y1, 1))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), @"short");
    }

    }
    }
    }

    #2
    Hello osmanigarces,

    Executing a strategy on each tick would be the fastest that you can calculate a strategy, that is calculated for every tick that the market has.

    The code that you provided does not appear to be valid and would not compile, is this code that you tried to make yourself or was this code generated by an external tool? If this is pseudocode please instead post your actual code so we can better assist.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello osmanigarces,

      Executing a strategy on each tick would be the fastest that you can calculate a strategy, that is calculated for every tick that the market has.

      The code that you provided does not appear to be valid and would not compile, is this code that you tried to make yourself or was this code generated by an external tool? If this is pseudocode please instead post your actual code so we can better assist.
      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 EMACrossOverBot : Strategy
      {
      private EMA EMA1;
      private EMA EMA2;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "EMACrossOverBot";
      Calculate = Calculate.OnEachTick;
      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;
      }
      else if (State == State.Configure)
      {
      }
      else if (State == State.DataLoaded)
      {
      EMA1 = EMA(Close, 2);
      EMA2 = EMA(Open, 2);
      EMA1.Plots[0].Brush = Brushes.Navy;
      EMA2.Plots[0].Brush = Brushes.Orange;
      AddChartIndicator(EMA1);
      AddChartIndicator(EMA2);
      }
      }

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

      if (CurrentBars[0] < 1)
      return;

      // Set 1
      if (CrossAbove(EMA1, EMA2, 1))
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), @"long");
      }

      // Set 2
      if (CrossBelow(EMA1, EMA2, 1))
      {
      EnterShort(Convert.ToInt32(DefaultQuantity), @"short");
      }

      }
      }
      }

      region Wizard settings, neither change nor remove

      Picture example : Here the blue line crossed under the orange and triggered a short then it recrossed above it and did not trigger a long on the same candle.

      Comment


        #4
        Hello osmanigarces,

        It looks like the image you attached did not upload so I was unable to see what that was. In regard to the crossover entry, have you tried using a Print to confirm the condition did become true? You can also try using TraceOrders to check if the entry was ignored.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello osmanigarces,

          It looks like the image you attached did not upload so I was unable to see what that was. In regard to the crossover entry, have you tried using a Print to confirm the condition did become true? You can also try using TraceOrders to check if the entry was ignored.

          https://ninjatrader.com/support/help...ub=traceorders
          Im getting this on the trace order output

          3/8/2024 3:22:14 PM Strategy 'PriceActionBotV4/321308461': Entered internal SubmitOrderManaged() method at 3/8/2024 3:22:14 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long' FromEntrySignal=''
          3/8/2024 3:22:14 PM Strategy 'PriceActionBotV4/321308461': Ignored SubmitOrderManaged() method at 3/8/2024 3:22:14 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
          3/8/2024 3:22:14 PM Strategy 'PriceActionBotV4/321308461': Entered internal SubmitOrderManaged() method at 3/8/2024 3:22:14 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long' FromEntrySignal=''
          3/8/2024 3:22:14 PM Strategy 'PriceActionBotV4/321308461': Ignored SubmitOrderManaged() method at 3/8/2024 3:22:14 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
          3/8/2024 3:22:14 PM Strategy 'PriceActionBotV4/321308461': Entered internal SubmitOrderManaged() method at 3/8/2024 3:22:14 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long' FromEntrySignal=''
          3/8/2024 3:22:14 PM Strategy 'PriceActionBotV4/321308461': Ignored SubmitOrderManaged() method at 3/8/2024 3:22:14 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
          3/8/2024 3:22:15 PM Strategy 'PriceActionBotV4/321308461': Entered internal SubmitOrderManaged() method at 3/8/2024 3:22:15 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long' FromEntrySignal=''
          3/8/2024 3:22:15 PM Strategy 'PriceActionBotV4/321308461': Ignored SubmitOrderManaged() method at 3/8/2024 3:22:15 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1


          Basically every second a new line is created. How do you think I can restructure the script for it to work as intended?

          Comment


            #6
            Hello osmanigarces,

            The log message is only mentioning the Buy order or the EnterLong, that message is happening because of the EntriesPerDirection. The condition to enter long keeps becoming true while you are already in a long position so the subsequent entries are being ignored. I don't see any messages about a Sell or EnterShort order in that output, do you see any prints referencing a Sell order in the output?

            Additional what specifically is the goal, are you trying to keep reversing the position on each cross? If we make the assumption the script enters long and then the condition with EnterShort happens it should reverse the position, you would see a close position and enter short.

            I would also suggest adding a Print action into the second set to confirm the second condition is becoming true, you can use the NinjaScript output window to monitor and see if that condition became true.

            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by StockTrader88, 03-06-2021, 08:58 AM
            45 responses
            3,991 views
            3 likes
            Last Post johntraderuser2  
            Started by TAJTrades, Today, 09:46 AM
            0 responses
            7 views
            0 likes
            Last Post TAJTrades  
            Started by rhyminkevin, Yesterday, 04:58 PM
            5 responses
            62 views
            0 likes
            Last Post dp8282
            by dp8282
             
            Started by realblubb, Today, 09:28 AM
            0 responses
            8 views
            0 likes
            Last Post realblubb  
            Started by AaronKoRn, Yesterday, 09:49 PM
            1 response
            19 views
            0 likes
            Last Post Rikazkhan007  
            Working...
            X