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

Price CrossAbove Help.

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

    Price CrossAbove Help.

    Hi,
    I'm brand new to NT, and Strategy development, and pretty new to trading in general so please bare with me.
    I'm trying to build a strategy where I input different price levels and as those levels are crossed above or below there is a EnterLongStopMarketet() order placed. I am finding it strangely difficult to write the code so that when the current "price" crosses above or below the order is created. I understand that I can use the "Crossabove(Close, ,1)", but the problem I have is that I can't wait until the 1, or 5, or 10 minute candle close to place the order. This is a intraday, fast paced strategy that needs to activate the order the second price crosses above or below a set point.
    I hope it is something super simple I am missing, I worked for a few hours last night trying to come to a solution. Thank you so much in advance!

    #2
    Hello todc55,

    Thank you for your post.

    Something you could do is use 'greater than/less than' instead of 'cross above/cross below' for your condition to compare if the current Close price is above (greater than)/below (less than) a specific price level.

    Also, if you would like to have an order placed the moment a condition becomes true, you would need to run your strategy with a Calculate mode of 'On Each Tick' or 'On Price Change'. If you were to run your strategy with a Calculate mode of 'On Bar Close', the strategy would wait till the close of a bar when the condition becomes true before placing the order. Note the Calculate mode would be changed using the Calculate drop-down menu in the Strategy's Properties section when enabling your strategy.

    See this help guide documentation for more information about Calculate - https://ninjatrader.com/support/help.../calculate.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon!
      Thanks for your quick response. So if I use the greater/less than function I still have to use it as an (onbarclose). So I figured the solution to that was to run the strategy on a 1 second chart so that the problem is remedied, that way my orders are set on the 1 second candles instead of the 1 minute. So the other obstacle I had after I figured to use the 1 second chart was if the order was placed but not filled in the same candle, the order was automatically cancelled. That wont work either because sometimes after the order is placed it might take 3 or 4 candles before it hits the 'stop price' and the order gets executed. I found the isLiveUntilCancelled function on a stopmar****rder, but when I tried to run the strategy NT wouldnt let me enable the strategy.
      Attached is a note with what i am trying to accomplish, so hopefully it helps you understand the issues I'm having. I set specific price levels (KPL) and they each have a 1 point buffer above and below. Orders are create at the KPL and need to be filled at the + or - buffer. They will then sell when they reach the buffer zone of the next KPL.

      Comment


        #4
        Here is a Test Script I have started with just to get the first actions working properly. However it isn't working yet. NT won't let me enable this when i bring it up on a chart and it doesnt tell me why.
        Thanks!!


        #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 TEST1 : Strategy
        {
        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Strategy here.";
        Name = "TEST1";
        Calculate = Calculate.OnEachTick;
        EntriesPerDirection = 1;
        EntryHandling = EntryHandling.AllEntries;
        IsExitOnSessionCloseStrategy = false;
        ExitOnSessionCloseSeconds = 3;
        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;
        KPLa = 1;
        Buf = 1;
        }
        else if (State == State.Configure)
        {
        }
        }

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

        if (CurrentBars[0] < 1)
        return;

        // Set 1
        if (CrossAbove(Close, KPLa, 1))
        {
        EnterLongStopMarket(1, true, 1, KPLa + Buf, "Cross Entry");
        }

        }

        #region Properties
        [NinjaScriptProperty]
        [Range(1, double.MaxValue)]
        [Display(Name="KPLa", Order=1, GroupName="Parameters")]
        public double KPLa
        { get; set; }

        [NinjaScriptProperty]
        [Range(1, double.MaxValue)]
        [Display(Name="Buf", Order=2, GroupName="Parameters")]
        public double Buf
        { get; set; }
        #endregion

        }
        }

        Comment


          #5
          Hello todc55,

          Thank you for your note.

          When testing the code you shared, I was able to enable the strategy on a chart.

          IsLiveUntilCanceled would need to be used to keep an order alive. See the example script in this help guide link for an example of using IsLiveUntilCanceled to keep orders alive.

          Keeping Orders Alive - https://ninjatrader.com/support/help...ders_alive.htm

          In your script, I see you have the barsInProgressIndex parameter set to 1 for EnterLongStopMarket(). Using a barsInProgress of 1 means that orders would be submitted to a secondary data series added to the script and your script does not add a secondary series. You would need to set the barsInProgressIndex parameter to 0 to have the order submitted to the primary series.

          See the help guide documentation below for more information.
          BarsInProgress - https://ninjatrader.com/support/help...inprogress.htm
          EnterLongStopMarket() - https://ninjatrader.com/support/help...stopmarket.htm

          To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

          In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.
          Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

          Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
          https://ninjatrader.com/support/foru...121#post791121

          Please let me know if I may further assist
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Brandon,
            You are the man. The reason it wouldn't let me enable was apparently because of the barsinprogess(1). I changed it to (0) and it enabled for me. Like I said I am really new to this and I just didn't understand what all of the jargon meant when I was working on it last night. Thank you for your help. I am going to keep piecing this together and I'm sure ill be back with more questions.
            Thank You

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by JoMoon2024, Today, 06:56 AM
            0 responses
            6 views
            0 likes
            Last Post JoMoon2024  
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            17 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            6 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,786 views
            0 likes
            Last Post Leafcutter  
            Started by poplagelu, Today, 05:00 AM
            0 responses
            3 views
            0 likes
            Last Post poplagelu  
            Working...
            X