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 GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,221 views
        0 likes
        Last Post xiinteractive  
        Started by andrewtrades, Today, 04:57 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        7 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        438 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        9 views
        0 likes
        Last Post FAQtrader  
        Working...
        X