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

Strategy Time

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

    Strategy Time

    Hi!!
    I have converted my strategy NT7 to NT8, I do not get enough depth of time.
    The strategy triggers orders at a certain time, but in NT8 it does not use the seconds

    NT7
    Code:
    #region Variables
    // Wizard generated variables
    private int		timeToEntry	= 123050;
    
    protected override void OnBarUpdate()
    if(ToTime(Time[0]) >= timeToEntry

    NT8
    Code:
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    
    Hours       = 12;
    Minutes    = 30;
    Seconds   = 50;
    
    
    
    protected override void OnBarUpdate()
    		{
    			if (BarsInProgress != 0)
    				return;
    			if(CurrentBar < 20) return;
    			
                if ((Times[0][0].TimeOfDay >= new TimeSpan (Hours, Minutes, Seconds))
    Edit: always works in AddDataSeries(BarsPeriodType.Second, 1);
    (or Tick and CalculateOnBarClose = false; )


    The information in https://ninjatrader.com/support/helpGuides/nt8/
    it is not concrete with respect to the subject

    the rest of the strategy works the same as in NT7

    thank you very much NT team
    Last edited by franki; 04-05-2018, 03:09 AM.

    #2
    Hello,

    Thank you for the post.

    I wanted to check, what series are you running the strategy on as its primary? Is it a second based series?

    Also, the sample provided is incomplete so I cannot see where you are using Prints to check your conditions/variables used. If you have not yet added Prints to check the objects you are using, I would suggest doing that as a next step. Prints can tell you if the conditions you use are happening as expected. You can also output the Time object if needed to see what the series timestamps are. We have a short guide to debugging here: https://ninjatrader.com/support/foru...49&postcount=2

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse
      Thanks for answering.
      What do you mean by the main series? 6A 5-18 for example ?? if it refers to "data series" it is one minute in the chart, but it is assigned with "AddDataSeries (BarsPeriodType.Second, 1);" a second, sometimes I experiment with just one tick; The strategy is used in "on each Tick"
      The strategy is used to launch orders at an exact time in the chosen instrument.
      The rest of the code that I have not published is because it works correctly, since the strategy launches the orders executing the time table with depth of hours and minutes, but not seconds.
      Before posting in the forum I searched and read dozens of messages, even using part of the scripts published by the ninjatrader team. But I have not found information to give seconds accuracy in the strategy of NT8, when the strategy works in NT7 if it works well and in depth of seconds

      Code:
      	public class VolandtimeV004 : Strategy
      	{
      		private Order  shortEntry          = null;
              private Order  longEntry           = null;
              private Order  targetLong          = null;
              private Order  targetShort         = null;
              private Order  stopLossShort       = null;
              private Order  stopLossLong        = null;
      	private Order  stopOrder		   = null;	
      	private string oco;
      		
      	protected override void OnStateChange()
      	{
      		if (State == State.SetDefaults)
      		{
      	Description									= @"Time && Volume.";
      	Name										= "VolandtimeV004";
      	Calculate									= Calculate.OnEachTick;
      	EntriesPerDirection							= 1;
      	EntryHandling								= EntryHandling.AllEntries;
      	IsExitOnSessionCloseStrategy				= true;
      	ExitOnSessionCloseSeconds					= 30;
      	IsFillLimitOnTouch							= false;
      	MaximumBarsLookBack							= MaximumBarsLookBack.TwoHundredFiftySix;
      				OrderFillResolution							= OrderFillResolution.Standard;
      				Slippage									= 2;
      				StartBehavior								= StartBehavior.WaitUntilFlat;
      				TimeInForce									= TimeInForce.Day;
      				TraceOrders									= true;
      				RealtimeErrorHandling						= RealtimeErrorHandling.StopCancelClose;
      				StopTargetHandling							= StopTargetHandling.PerEntryExecution;
      				BarsRequiredToTrade							= 20;
      				IsUnmanaged 								= true;
      				IsAdoptAccountPositionAware 				= true;
      				// Disable this property for performance gains in Strategy Analyzer optimizations
      				// See the Help Guide for additional information
      				IsInstantiatedOnEachOptimizationIteration	= true;
      				Bracket									= 5;
      				Hours									= 12;
      				Minutes									= 30;
      				Seconds 									= 55;
      				Profit									= 20;
      				StopLoss									= 10;
      
      
      				
      	
      			}
      			else if (State == State.Configure)
      			{
      				 AddDataSeries(BarsPeriodType.Second, 1);
      				
      			}
      			#region State.Realtime
      			else if (State == State.Realtime)
      			{
      			    var aStrategyPosition = this.Position;
      			    var aRealAccount = PositionAccount;
                      // convert any old historical order object references
                      // to the new live order submitted to the real-time account
      			    if (shortEntry != null)
      			        shortEntry = GetRealtimeOrder(shortEntry);
      				if (longEntry != null)
      			        longEntry = GetRealtimeOrder(longEntry);
      				if (targetLong != null)
      			        targetLong = GetRealtimeOrder(targetLong);
      				if (targetShort != null)
      			        targetShort = GetRealtimeOrder(targetShort);
      				if (stopLossShort != null)
      			        stopLossShort = GetRealtimeOrder(stopLossShort);
      				if (stopLossLong != null)
      			        stopLossLong = GetRealtimeOrder(stopLossLong);
      				if (stopOrder != null)
      					stopOrder = GetRealtimeOrder (stopOrder);
      				
      			}
      			#endregion
      		}
      
      		protected override void OnBarUpdate()
      		{
      //			if (BarsInProgress != 0)
      //				return;
      			if(CurrentBar < 20) return;
      			
                  if ((Times[0][0].TimeOfDay >= new TimeSpan (Hours, Minutes, Seconds)) 
      				&& longEntry == null && shortEntry == null
                      && Position.MarketPosition == MarketPosition.Flat)
                  {
                    
                    
      				if (State == State.Historical)
      					oco = DateTime.Now.ToString() + CurrentBar + "entry";
      				else
      					oco = GetAtmStrategyUniqueId() + "entry";
      I again present the logical part of the strategy, except for the order management that is based on the script of NT_JIM UnmanagedTemplate_NT8 09-17. With my modifications to adjust some parameters that do not interfere with the temporal sequence.

      *The information on MSDN is unclear and is diffuse with respect to the time code that I need

      Thank you.

      Comment


        #4
        Hello,

        Thank you for the reply.

        In this situation, I would expect that you dont see any second granularity for what you are trying to use for the condition. You are referencing specifically the Primary series of 1 minute: Times[0][0].

        If the primary has time stamps of 1 minute, there are no second timestamps in that series besides 00. Even using OnEachTick you are still referencing the primary 1-minute series so the timestamps will only report the current building bars timestamp. You would either access the last Close bar price using OnBarClose, or the current building bars price/time which is spaced to be incremental with the timeframe chosen.

        To access seconds in time, you would need to use a series that has that granularity or use OnMarketData and the Time that comes through there for each tick. Alternatively accessing a secondary tick series such as Times[1][0] should produce different results as the second series has second granularity.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello NinjaTrader_Jesse
          finally the successful configuration has been Chart 1 second
          Code:
          AddDataSeries (BarsPeriodType.Second, 2);
          Code:
          (Times [1] [0] .TimeOfDay> = new TimeSpan (Hour, Minute, Second)
          In this situation, it makes me think that Data Series # in chart has more relevance than "AddDataSeries (BarsPeriodType ...." or (Times [1] [0] .TimeOfDay> = new TimeSpan .... into the script

          In NT7 the relevance is of AddDataSeries in the script and with the simple command "" if (ToTime (Time [0])> = timeToEntry "" executes the logic of the script independently of the timeframe of the chart
          I'm really grateful to you.
          Thanks for your help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by PaulMohn, Today, 12:36 PM
          0 responses
          2 views
          0 likes
          Last Post PaulMohn  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          38 views
          0 likes
          Last Post love2code2trade  
          Started by alifarahani, Today, 09:40 AM
          2 responses
          14 views
          0 likes
          Last Post alifarahani  
          Started by junkone, Today, 11:37 AM
          3 responses
          20 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by frankthearm, Yesterday, 09:08 AM
          12 responses
          44 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X