Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting different StopLoss for different times of day

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

    Setting different StopLoss for different times of day

    How can I set up different stoploss for different times of day? What I want to do is set a stoploss between the hours of midnight and 5:30am. I've been trying to use

    if (ToTime(Time[0]) >= 000000 && ToTime(Time[0]) <= 053000)
    {
    SetStopLoss(CalculationMode.Ticks, 12);
    }

    but this hasn't worked for me. With this it seems all my entries are then set to 12 ticks for a stoploss. Please help!

    Thanks,
    Lee

    #2
    Lee, what value have you setup for the other times of the day when this does not trigger?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I don't have any stoploss set up for other times of day. For other times of day, I don't want a stoploss. I only want a stoploss for the time I have indicated. However, when I try setting the stoploss between midnight and 5:30am, all my entries seem to exit when the stop is hit, even those outside of the indicated times.

      Comment


        #4
        You should not work with the Set() methods, but rather the Exit() ones, or you just move it that far away that it would never really be hit, thus being effectively no stoploss in your scenario.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          For using the Exit() methods, would that be something like:

          if (GetCurrentAsk() < Position.AvgPrice - 24 * TickSize)
          {
          Exit("position name");
          }
          What I'm hoping to say is that if the current ask price is 24 ticks below my entry price for a position, then exit that position. This is assuming a long position. Please let me know what you think. Thanks.

          Comment


            #6
            That should work logically, however Exit alone is not enough, for a market order exit try for example ExitShort(), ExitLong().
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks! I'll be sure to try the ExitLong/Short() strategies. I also have another issue. I'm trying to run specific trades during the hours of midnight to 12noon and then starting them up again from 3pm to midnight. This is my script:
              if (ToTime(Time[0]) >= 000000 && ToTime(Time[0]) <= 120000)
              {
              "Enter trades"
              }

              if (ToTime(Time[0]) >= 150000)
              {
              "Enter trades"
              }

              It seems I'm having trouble with this set-up. Sometimes my trades don't seem to execute around the hours right before midnight. Doesn't the 2nd if statement cover from 3pm till midnight, while the first one covers from midnight till noon?
              Last edited by Xiongl80; 09-07-2010, 02:34 AM.

              Comment


                #8
                Lee, I would suggest you add prints to those sections of code to check how it triggers on your charts and timezone and then adjust as needed.

                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  One more question...

                  I've just recently developed an automated strategy that runs off of 2 different timeframes. But when I ran my strategy in sim mode during the trading day, my trades didn't execute. It looks like nothing happened at all, as if none of my entries even registered. But when I went to run my strategy in the Strategy Analyzer, there were at least 3 trades that could have fired off. I understand that sometimes the Strategy Analyzer isn't exactly like real-time streaming data, but I wouldn't think all 3 entries missed. Is there something special that has to be done when entering a 2 timeframe strategy compared to a 1 timeframe strategy? All of my 1 timeframe strategies have been working as expected.

                  Comment


                    #10
                    Do you see any errors when running those MultiSeries strategies realtime then? Did you work with TraceOrders to get additional debug info to the output window?



                    Which CalculateOnBarClose setting were you using running it live?

                    As a 'should be working' MultiSeries example strategy, you can apply the SampleMultiTimeFrame from us to check.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      My CalculateOnBarClose is set to false. How does that effect your trading? I was reading your guide on the issue, and from what I understand, setting it to true calculates your strategy at the close of each bar and setting it to false calculates on each tick update. Please correct me if I'm wrong. Also, I just learned about TraceOrders so I plan to start implementing them. And my log didn't show any errors for my strategy in real-time. I have also worked with your SampleMultiTimeFrame startegy and it works fine.

                      Comment


                        #12
                        Your CalculateOnBarClose understanding is correct for realtime time use, for backtesting : this is defaulted to 'true', as the intrabar formation (how the ticks came in) is unknown at this point unfortunately. I suggest you work then with TraceOrders and Prints to check exactly when / if your own MTF strategy triggers as you would expect, perhaps also simplifying the code first is a good idea to start with a version you know working as it should, then you can add complexity later.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks! I was able to break my code down by layers and found the error. One too many 0's in my 150000 time command. Thanks for all the help. Now to run my system and see if it operates as expected.

                          Comment


                            #14
                            When you say the intrabar information for tick data is unknown at this time, is that a limitation of NT? If so, does NT plan to save a timestamp to tick data in the future that would allow for more accurate backtesting? Also, are TraceOrders and Print statements used with Microsoft Visual for debugging? Today I tried using a Console.Write command, but was unsuccessful. I was wondering if it was because I don't have Visual.

                            Comment


                              #15
                              The intrabar formation is generally not known when backtesting, you have access to the OHLCV data of the bar you're working on. Timestamps are available on tick data though as they are on any other series (down to 1 second granularity).

                              TraceOrders and Print would go into your output window that can be opend via the Tools menu in the Control Center.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by quantismo, 04-17-2024, 05:13 PM
                              3 responses
                              25 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              7 responses
                              34 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cls71, Today, 04:45 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post cls71
                              by cls71
                               
                              Started by mjairg, 07-20-2023, 11:57 PM
                              3 responses
                              214 views
                              1 like
                              Last Post PaulMohn  
                              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                              4 responses
                              547 views
                              0 likes
                              Last Post PaulMohn  
                              Working...
                              X