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

stoping trading on the first five days of my script

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

    stoping trading on the first five days of my script

    I just want to stop my script for trading the first five days, how can I do that?

    #2
    Hello dafonseca,

    Thank you for the post.

    If you know how many bars that is for the series you are using you could use the CurrentBar in a condition. What series is being used?

    Here is a simple example assuming the series was Daily bars:

    Code:
    if(CurrentBar < 5) return;
    This could also be accomplished in other ways depending on the overall goal, if you simply want to return for 5 days worth of data using the current bar is likely the most simple way.



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

    Comment


      #3
      the problem is I am using 1 min bars, but i have to get theses:
      if(ToTime(Time[0])== ToTime(9, 31, 00) || ToTime(Time[0])== ToTime(9, 34, 00))
      {
      if (BarsInProgress == 1)
      {
      priorClosePrice = PriorDayOHLC().PriorClose[0];
      priorClosePrice1 = PriorDayOHLC().PriorClose[1];
      priorClosePrice2 = PriorDayOHLC().PriorClose[2];
      priorClosePrice3 = PriorDayOHLC().PriorClose[3];
      priorClosePrice4 = PriorDayOHLC().PriorClose[4];
      priorClosePrice5 = PriorDayOHLC().PriorClose[5];
      }
      }
      when i run the strtegy the log shows an error since on the first day there are 4 days out of range, What i need is RETURN until the fifth day

      Comment


        #4
        Hello dafonseca,

        What is the primary that you are using? You may be able to account for this by checking that the primary has enough data before running this code, I would otherwise need that detail to know how to proceed here.

        For multi series scripts you can do the following to prevent it from doing anything before enough bars are available, this would help if your primary was a daily as an example:

        if(CurrentBars[0] < 5 || CurrentBars[1] < 5) return;

        If you need 5 days of minute bars you may need to do 1440 * 5 to get a count for that.



        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          the problem with current bars solution is that OIL (CL futures trades 24 horas)are there 1440 bars on 24 hrs trading? there is no such function as CURRENTDAY????that would solve my problem

          Comment


            #6
            Hi dafonseca,
            To determine, if you have a new day, you could compare the date of the current bar with the date of the previous bar. If they are not the same, you have a new day.
            If you have a new day, increase a dayCounter int by one.
            For one dataseries: If (Time[0].Date != Time[1].Date] ) { dayCounter = dayCounter+1 } else { no change }
            For >1 dataseries use Times. Example (still looking at the primary series): If[Times[0][0].Date =! Times[0][1].Date ) { see above}
            As long as the dayCounter is less than 5, return. Only if it is greater or equal to five, run the rest of your code including setting your variables.
            NT-Roland

            P.S.: If you like my suggestion for "Preload bars" please kindly vote for it. Could be so easy to ensure everything is up and running immediately after starting or restarting a strategy.
            Dear Experts, Can I preload a certain number of bars to ensure custom indicators used in the strategy are already up and running correctly when the strategy

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by knowmad, Today, 03:52 AM
            0 responses
            17 views
            0 likes
            Last Post knowmad
            by knowmad
             
            Started by tradingnasdaqprueba, Today, 03:42 AM
            0 responses
            12 views
            0 likes
            Last Post tradingnasdaqprueba  
            Started by Haiasi, 04-25-2024, 06:53 PM
            4 responses
            63 views
            0 likes
            Last Post effraenk  
            Started by ccbiasi, 11-23-2017, 06:06 AM
            5 responses
            2,213 views
            0 likes
            Last Post leodavis  
            Started by kujista, Yesterday, 12:39 AM
            2 responses
            14 views
            0 likes
            Last Post kujista
            by kujista
             
            Working...
            X