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

Entry Only During Specific Times

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

    Entry Only During Specific Times

    I want to enter trades based on an indicator during certain times only. I get the following to work just fine, but only for one time at a time.

    if (Rising(CCI(10)) == true
    && ToTime(Time[0]) >= 13000 && ToTime(Time[0]) <= 60000)

    The problem comes when I do this,

    if (Rising(CCI(10)) == true
    && ToTime(Time[0]) >= 13000 && ToTime(Time[0]) <= 60000
    && ToTime(Time[0]) >= 70000 && ToTime(Time[0]) <= 73000
    && (oTime(Time[0]) >= 80000 && ToTime(Time[0]) <= 83000
    && ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 110000)

    I get no trades, I even tried this,

    if (Rising(FisherTransform(10)) == true
    && (ToTime(Time[0]) >= 13000 && ToTime(Time[0]) <= 60000)
    && (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) <= 73000)
    && (ToTime(Time[0]) >= 80000 && ToTime(Time[0]) <= 83000)
    && (ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 110000))

    Still no luck. Without having to have 14 conditions I would like the latter to work, I still have more times and need to add Falling. Thanks in advanced.

    #2
    Originally posted by Hammerhorn View Post
    I want to enter trades based on an indicator during certain times only. I get the following to work just fine, but only for one time at a time.

    if (Rising(CCI(10)) == true
    && ToTime(Time[0]) >= 13000 && ToTime(Time[0]) <= 60000)

    The problem comes when I do this,

    if (Rising(CCI(10)) == true
    && ToTime(Time[0]) >= 13000 && ToTime(Time[0]) <= 60000
    && ToTime(Time[0]) >= 70000 && ToTime(Time[0]) <= 73000
    && (oTime(Time[0]) >= 80000 && ToTime(Time[0]) <= 83000
    && ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 110000)

    I get no trades, I even tried this,

    if (Rising(FisherTransform(10)) == true
    && (ToTime(Time[0]) >= 13000 && ToTime(Time[0]) <= 60000)
    && (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) <= 73000)
    && (ToTime(Time[0]) >= 80000 && ToTime(Time[0]) <= 83000)
    && (ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 110000))

    Still no luck. Without having to have 14 conditions I would like the latter to work, I still have more times and need to add Falling. Thanks in advanced.
    from what you write, I am going to presume that you wrote the math without ever writing the English. So I will translate to the English and it will then be obvious why you have written a set of conditions that is impossible to ever satisfy.
    (ToTime(Time[0]) >= 13000 && ToTime(Time[0]) <= 60000)
    && (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) <= 73000)
    translates to:
    "If the time of the current bar is after 0130hrs and before 0600hrs and the current bar time is at the same time after 0700hrs ..."

    There is no time that is before 0600hrs and after 0700hrs. That is physically and mathematically impossible. IOW, your condition is never going to be true.

    These kind of logic errors can usually be avoided if you start by writing down your logic in language, before trying to code it.

    Comment


      #3
      I realized the error, in that the condition was not separating them out and was doing exactly what you say, but I am just now realizing my mistake, &&. Very rusty on writing script (ten years or more), can I use OR in place of &&? Will I get my goal of not having to write a condition for each time frame?

      Comment


        #4
        Originally posted by Hammerhorn View Post
        I realized the error, in that the condition was not separating them out and was doing exactly what you say, but I am just now realizing my mistake, &&. Very rusty on writing script (ten years or more), can I use OR in place of &&? Will I get my goal of not having to write a condition for each time frame?
        A logical "OR" should work.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AaronKoRn, Today, 09:49 PM
        0 responses
        6 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Today, 08:42 PM
        0 responses
        9 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Today, 07:51 PM
        0 responses
        10 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,976 views
        3 likes
        Last Post jhudas88  
        Started by rbeckmann05, Today, 06:48 PM
        0 responses
        9 views
        0 likes
        Last Post rbeckmann05  
        Working...
        X