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

Different time filters depending on instrument

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

    Different time filters depending on instrument

    What would be the best way to code specific time filters for individual instruments? Would this be right?

    OnBarUpdate()
    if (Instrument.MasterInstrument.Name == ES)
    {
    (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)
    }
    else if (Instrument.MasterInstrument.Name == NQ)
    {
    (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) < 110000)
    }

    #2
    Hello mrre1,


    I have modified your conditions below:

    Code:
    [LEFT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]        {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2](Instrument.MasterInstrument.Name ==[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"ES"[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]&& (ToTime(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]) >=[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]50000[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]&& ToTime(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]) <[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]100000[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                        [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#008000]//Add your action here[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  }[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]
    [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2](Instrument.MasterInstrument.Name ==[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"NQ"[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]&& (ToTime(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]) >=[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]70000[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]&& ToTime(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]) <[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]110000[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                        [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#008000]//Add your action here[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                  }     [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]        }[/SIZE][/FONT][FONT=Courier New][SIZE=2][/SIZE][/FONT]



    Here is the ToTime() and the MasterInstrument.Name Help Guides to assist you further.



    [/LEFT]
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      How would a person go about putting these time filters at the beginning of the OBU section with everything else to follow? Based on your code I put it like this at the beginning but it is not filtering in optimization although it is compiling correctly:

      if ((Instrument.MasterInstrument.Name == "EMD" && (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))
      || (Instrument.MasterInstrument.Name == "CL" && (ToTime(Time[0]) >= 60000 && ToTime(Time[0]) < 110000))
      || (Instrument.MasterInstrument.Name == "GC" && (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) < 120000))
      || (Instrument.MasterInstrument.Name == "NQ" && (ToTime(Time[0]) >= 80000 && ToTime(Time[0]) < 130000)))

      Comment


        #4
        Originally posted by mrre1 View Post
        How would a person go about putting these time filters at the beginning of the OBU section with everything else to follow? Based on your code I put it like this at the beginning but it is not filtering in optimization although it is compiling correctly:

        if ((Instrument.MasterInstrument.Name == "EMD" && (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))
        || (Instrument.MasterInstrument.Name == "CL" && (ToTime(Time[0]) >= 60000 && ToTime(Time[0]) < 110000))
        || (Instrument.MasterInstrument.Name == "GC" && (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) < 120000))
        || (Instrument.MasterInstrument.Name == "NQ" && (ToTime(Time[0]) >= 80000 && ToTime(Time[0]) < 130000)))
        If a correctly written filter fails to actually filter, it is usually because it has been nulled. Are you sure that you do not have a spurious semi-colon after your filter statement?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by benmarkal, Yesterday, 12:52 PM
        3 responses
        23 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by helpwanted, Today, 03:06 AM
        1 response
        18 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        11 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        244 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        388 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X