Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with EnterLongStopLimit()

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

    Problem with EnterLongStopLimit()

    Hi.., i use demo nt8 with cqg

    i've problem to backtesting with Enter Long Stop Limit....

    See this thread :



    it said:

    now i see Ninjascript Output (usually i see Log)..

    In NinjaScript Output i see this error:


    Disabling NinjaScript strategy 'ntforumesignal/67481990'
    Strategy 'ntforumesignal/67481990': An order placed at '16/02/2016 00:03:00' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
    Enabling NinjaScript strategy 'ntforumesignal/67481990' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes



    i use NQ 03-16 (setting originally)





    with this code :

    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.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 ntforumesignal : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "ntforumesignal";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.AdoptAccountPosition;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    }
    else if (State == State.Configure)
    {
    }
    }
    protected override void OnBarUpdate()
    {
    //Add your custom strategy logic here.
    if (CrossAbove(Close,Open,1)) EnterLongStopLimit(Close[0]+1 * TickSize,Close[0]); 
    else if (CrossBelow(Close,Open,1)) EnterShortStopLimit(Close[0]-1 * TickSize,Close[0]);
    }
    }
    }

    when i run code i don't see any historical signal in chart
    Last edited by esignal; 02-23-2016, 02:08 AM.

    #2
    Hello,

    Thanks for your post.

    In the error message you posted, "Disabling NinjaScript strategy 'ntforumesignal/67481990'
    Strategy 'ntforumesignal/67481990': An order placed at '16/02/2016 00:03:00' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met
    ." is advising that your strategy placed an order before the BarsRequiredToTrade condition was met. As a result the order submitted was not placed and the strategy disabled itself to prevent any further issues.

    In your strategy the BarsRequiredToTrade is set to 20 bars which means that there must have been a trade condition that existed in that first 20 bars. Your code in the "OnBarUpdate() section does not show a check of CurrentBar or for BarsRequiredToTrade. Please see the helpguide here for an example of the check required before placing the first trade: http://ninjatrader.com/support/helpG...redtotrade.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3

      #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.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 lucaStrategy : Strategy
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "lucaStrategy";
      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;
      AddPlot(Brushes.Orange, "Plotta1");
      }
      else if (State == State.Configure)
      {
      }
      }

      protected override void OnBarUpdate()
      {
      if (CurrentBar < (BarsRequiredToTrade+5)) //(+5 , so i'm more safe
      return;

      if (CrossAbove(Close, Open, 1)) EnterLongStopLimit(Close[0] + 1 * TickSize, Close[0]);
      else if (CrossBelow(Close, Open, 1)) EnterShortStopLimit(Close[0] - 1 * TickSize, Close[0]);




      I don't see signal (i add line with currentBar < (BarsRequiredToTrade)

      If i write : "EnterLong or EnterShort i don't have a problem...it all okey.."
      The problem arrived when i use EnterLongStopLimit or EnterShortStopLimit
      Last edited by esignal; 02-23-2016, 10:56 AM.

      Comment


        #4
        Hello,

        Thanks for your reply.

        The EnterShort and EnterLong are market order methods. The EnterLongStopLimit and EnterShortStopLimit are limit order methods and as the screen shot error message shows you are placing them incorrectly relative to the current price. You may want to increase the values above or below the close price. Note that you are setting the stop price the same as close[0]. Make both the limit and the stop price farther, either above close (Long) or below close (short).
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          hi,


          i want to enter the next candle...in space 1 tick ...see pics below



          Can you help me to code correct it?

          thanks..i've problem to understand this

          Comment


            #6
            Hello,

            Thanks for your reply.

            I don't understand your entry criteria but when you are wanting to place the order you need to check that the current price is above or below the entry needed, for example (going long):

            if (your entry criteria here) // for example moving average rising, etc.
            {
            if (Close[0] < High[1]) // is current price less than prior bar high?
            {
            EnterLongLimitStop(High[1]+1*Ticksize, High[1]+1*TickSize); // place order 1 tick above high to go long
            }
            }
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              hi,,i dont' want this : Close[0] < High[1])....

              I want this : Close[0] > Open[0]) (i want to use it with renko candle...now i'm only testing with minute bars)






              if (Close[0] > Open[0]) // is current price less than prior bar high?

              EnterLongStopLimit(Close[0] + 2 * TickSize, Close[0] + 1 * TickSize); // place order 1 tick above high to go long

              else if (Close[0] <Open[0]) EnterShortStopLimit(Close[0] - 2 * TickSize, Close[0] - 1 * TickSize);
              is correct this ?
              Last edited by esignal; 02-24-2016, 07:37 AM.

              Comment


                #8
                Hello,

                Thanks for your reply.

                The issue here is that you are trying to place your limit order close to where price may be trading at. With reference to your picture of what you would like to do, when using Calculate.OnBarClose, your strategy will be executing once at the end of the bar (that shows the high of 4400). At that time you do not know what the current price is on the following bar and price may already be well above or below where you want to enter causing the entry order issue.

                I would suggest to either move the limit orders further away from price or use Calculate.OnEachTick (or Calculate.OnPriceChange) in order to know where price is and be able to make sure you are not trying to place the order when price has already passed it by.

                Changing your code to Calculate.OnEachTick (or OnPriceChange) can have unintended consequences and you may want to have parts of your code only execute once per bar while other parts to calculate on each tick. We have an example of how to separate your code here: http://ninjatrader.com/support/forum...ad.php?t=19387 I am not suggesting you need to do this, only letting you know that it is possible to calculate on each tick and on each bar.
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by yertle, Yesterday, 08:38 AM
                7 responses
                28 views
                0 likes
                Last Post yertle
                by yertle
                 
                Started by bmartz, 03-12-2024, 06:12 AM
                2 responses
                21 views
                0 likes
                Last Post bmartz
                by bmartz
                 
                Started by funk10101, Today, 12:02 AM
                0 responses
                5 views
                0 likes
                Last Post funk10101  
                Started by gravdigaz6, Yesterday, 11:40 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by MarianApalaghiei, Yesterday, 10:49 PM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X