Announcement

Collapse
No announcement yet.

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]

    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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        133 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        75 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        117 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        113 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        90 views
        0 likes
        Last Post CarlTrading  
        Working...
        X