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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        50 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        16 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        22 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        23 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X