Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trading Hours for Different Markets

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

    Trading Hours for Different Markets

    Hello

    I'm running an automated strategy across multiple markets and I want it to stop sending signals during certain times of the day when there's noise (economic indicators, etc).

    This works well with the ToTime function, but I'm having trouble when integrating all (market specific) "no trade times".

    Here's an example for a single market (the DAX):

    if (Instrument.MasterInstrument.Name == "FDAX" && ToTime(Time[0]) > 81000 && ToTime(Time[0]) < 143000 || ToTime(Time[0]) > 143000 && ToTime(Time[0]) < 155000 || ToTime(Time[0]) > 160000)
    {
    TradingHoursDax = true;
    }

    This works well but it has to be adapted for every market (MasterInstrument.Name is modified).

    Now, when integrating all markets into one line of code, it looks like this:

    if (TradingHoursDax == true || TradingHoursEuro == true etc)
    {
    TradingHours = true;
    }

    Finally, TradingHours = true is integrated into my trading criteria, but this is where it stops working.
    The strategy simply ignores it and executes a signal even if it triggers during a "no trade time".
    Any idea on what went wrong here would be much appreciated.

    Thanks

    #2
    Depending on how you've defined TradingHoursDax and TradingHourEuro, etc, your TradingHours flag might always be true, however this is just a guess as I don't know how these bools are set.

    You will need to debug these conditions you have setup by printing TradingHours and the other flags you've set up to ensure these conditions are returning the value you expected when you set this up.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks for your reply Matthew. I thought about that too, but this is prevented by the Instrument.MasterInstrument.Name == ... function that's different for every market, ie for the Euro it would be Instrument.MasterInstrument.Name == "6E", for the DAX Instrument.MasterInstrument.Name == "FDAX", etc

      Every market has its own bool, with market-specific trading hours and the name of the market, which is obviously unique and therefore prevents that the flag is always true.

      I can't see why this logic doesn't work.

      Thanks

      Comment


        #4
        Hello,

        Can you share the code you used so we may review your logic?

        I understand what you're trying to accomplish and by all accounts this should work, but in order to see why the logic you've used does not work, I'd really need to see your code in this area.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Sure, thanks Matthew. This is the snippet (for two markets only, enough to illustrate the point):

          First, the market-specific trading hours are defined:

          if (Instrument.MasterInstrument.Name == "FDAX" && ToTime(Time[0]) > 81000 && ToTime(Time[0]) < 143000 || ToTime(Time[0]) > 143000 && ToTime(Time[0]) < 155000 || ToTime(Time[0]) > 160000)
          {
          TradingHoursDax = true;
          }

          else
          {
          TradingHoursDax = false;
          }



          if (Instrument.MasterInstrument.Name == "6E" && (ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 061000) || (ToTime(Time[0]) > 061000 && ToTime(Time[0]) < 143000) || (ToTime(Time[0]) > 143000 && ToTime(Time[0]) < 155000) || (ToTime(Time[0]) > 160000))
          {
          TradingHoursEuro = true;
          }

          else
          {
          TradingHoursEuro = false;
          }



          Then, the different trading hour criteria are all included in one boolean (to allow for the strategy to be generic for all markets)

          if (TradingHoursDax == true || TradingHoursEuro == true)
          {
          TradingHours = true;
          }

          else
          {
          TradingHours = false;
          }

          And finally, the trading hour criteria are added to my other entry criteria:

          if(My conditions here && TradingHours == true)

          {
          orderId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.StopLimit,High[0]+1*TickSize,High[0]+1*TickSize, TimeInForce.Day, orderId, "Strategy", GetAtmStrategyUniqueId());
          orderPlacedLong = true;
          }

          Comment


            #6
            Hello laocoon,

            I believe the reason why you are not getting the results you are expecting is because your if conditions. For example the second condition is almost always going to be true. condition
            Originally posted by laocoon View Post

            if (Instrument.MasterInstrument.Name == "6E" && (ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 061000) || (ToTime(Time[0]) > 061000 && ToTime(Time[0]) < 143000) || (ToTime(Time[0]) > 143000 && ToTime(Time[0]) < 155000) || (ToTime(Time[0]) > 160000))
            {
            TradingHoursEuro = true;
            }

            else
            {
            TradingHoursEuro = false;
            }
            I have colored in the statements that will be processed together. If anyone of them are true in the indicated colors your condition will be true. The same will be with your statement about setting your TradingHours variable.

            Example:
            Code:
            if ( false || true )
            {
                // is always going to be processed since only 1 or the other has to be true when using the 'or' "||" operator.
            }

            You may easily see what I mean if you place a Print() statement inside the else of your "6E" condition like ' Print("In Else of 6E: "+Time[0]); '
            Last edited by NinjaTrader_JC; 05-10-2013, 08:44 AM.
            JCNinjaTrader Customer Service

            Comment


              #7
              Thanks a lot JC & Matthew, you were of course right.
              I simply added the instrument name to every "ToTime" bit of every boolean and now it works perfectly.

              Thanks again.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              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
              6 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by josh18955, 03-25-2023, 11:16 AM
              6 responses
              436 views
              0 likes
              Last Post Delerium  
              Started by FAQtrader, Today, 03:35 PM
              0 responses
              9 views
              0 likes
              Last Post FAQtrader  
              Started by rocketman7, Today, 09:41 AM
              5 responses
              20 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X