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 Start Time Greater than End Time

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

    Strategy Start Time Greater than End Time

    I have an issue with strategy start and end time

    Based on this thread
    Support for the development of custom automated trading strategies using NinjaScript.


    I am using this code

    Code:
    if(StartTime<StopTime
    					&& ToTime(Time[0]) >= (StartTime * 100) 
    					&& ToTime(Time[0]) <= (StopTime * 100))
    					
    					trade=true;
    
    				else if (StartTime>StopTime)
    				{
    					if ((ToTime(Time[0]) >= (StartTime*100) && ToTime(Time[0]) <= 235959) || ToTime(Time[0]) < (StopTime * 100))
    					
    					trade=true;	
    				}		
    				
    				else
    					trade=false;
    Inputs for start and end time are:

    Code:
    				StartTime = 1500;
    				StopTime = 1230;

    So the strategy crosses over sessions.

    It seemed like it worked, but it is not working anymore. This has been a real headache, is there a simpler way to code this?
    -EC_Chris-
    NinjaTrader Ecosystem Vendor - Emergent Cybernetics

    #2
    Hello EC_Chris,

    Thanks for opening the thread.

    I suggest to add debug prints to your code so you can see if this trade bool is getting set appropriately, or if there is another part of the logic that is preventing your orders from submitting.

    I have created a demonstration showing how debugging prints can be used with the Strategy Analyzer to analyze the strategy logic.

    Demo: https://www.screencast.com/t/nDBZkW9s

    Additional tips on debugging can be found here: https://ninjatrader.com/support/foru...ead.php?t=3418

    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Same issue, I just reset strategy on start of each interval. Like time 1 to 160000 or 170000 to 240000

      Comment


        #4
        Hello Kubera2024 and EC_Chris,

        I have included an export for my demonstration video yesterday. This can be tested in the Strategy Analyzer and the prints that show if the filter "trade" becomes true or false can be observed in the NinjaScript Output window.

        For the thread's reference, additional examples on time checks can be seen in the sample here: https://ninjatrader.com/support/foru...ead.php?t=3226

        Please let us know if we can be of further assistance.
        Attached Files
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,604 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        13 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X