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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        559 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        546 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X