Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time Trigger.

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

    Time Trigger.

    Hello to every one.
    Is it possibile to send orders at a specified and pre-defined time?
    For example: sell 1 lot EURUSD @ 12.00 AM

    thank you,

    regards,

    johnlucas


    #2
    johnlucas,

    You can do this through custom programming of a NinjaScript Strategy.

    Code:
    if (ToTime(Time[0]) == 000000)
         EnterShort(1);
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank you Josh!

      is there a way to simplify this through the wizard?

      thank you



      Originally posted by NinjaTrader_Josh View Post
      johnlucas,

      You can do this through custom programming of a NinjaScript Strategy.

      Code:
      if (ToTime(Time[0]) == 000000)
           EnterShort(1);

      Comment


        #4
        Go to the Conditions and Actions page, and add a new condition. Expand the Time category on the left hand side and select time series. On the right hand side select time value and punch in 12:00 AM. In the middle select ==. Then add your action of the trade.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          hello Josh,

          last question...how is it possible through the wizard to send an order cancellation upon the execution of another order.

          I mean: if order1 is executed, then cancel order2.

          thank you very much,

          Johnlucas.

          Comment


            #6
            Unfortunately this would require custom programming to achieve.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi everyone,

              regarding the time of day filter, is it possible to set a user defined input like:

              StrategyStart
              StrategyStop

              and let the user insert the parameters for deciding the time window in which the trades will take place?
              If yes, which would be the format of that user input (int, string, or what)?

              The alternative is to user the timeseries and timevalue in the wizard and changing them each time I would like to try different times of day.

              thank you,

              John.

              Comment


                #8
                add these in the properties section
                Code:
                        [Description("The time to begin trading in HHMM format")]
                        [Category("Parameters")]
                        public int TradeTimeBegin
                        {
                            get { return _tradeTimeBegin; }
                            set { _tradeTimeBegin = Math.Max(0, value); }
                        }
                
                        [Description("The time to end trading in HHMM format")]
                        [Category("Parameters")]
                        public int TradeTimeEnd
                        {
                            get { return _tradeTimeEnd; }
                            set { _tradeTimeEnd = Math.Max(0, value); }
                        }
                Add these in the variables section
                Code:
                        private int _tradeTimeBegin = 930; // Default setting for TradeTimeBegin
                        private int _tradeTimeEnd = 1500; // Default setting for TradeTimeEnd
                Then use this to check if its ok to trade
                Code:
                        private bool TimeToTrade
                        {
                            get
                            {
                                if (_tradeTimeBegin == 0 || _tradeTimeEnd == 0)
                                {
                                    return true;
                                }
                                else
                                {
                                    if (_tradeTimeBegin > _tradeTimeEnd)// sessions that begin previous day and end next day
                                    {
                                        return ToTime(Time[0]) >= _tradeTimeBegin * 100 || ToTime(Time[0]) <= _tradeTimeEnd * 100;
                                    }
                                    else
                                    {
                                        return ToTime(Time[0]) >= _tradeTimeBegin * 100 && ToTime(Time[0]) <= _tradeTimeEnd * 100;
                                    }
                                }
                            }
                        }
                for example:
                Code:
                                if (TimeToTrade)
                                {
                                    Do something here
                                }
                Hope this helps

                Comment


                  #9
                  Hi Laserdan,

                  thank you very much for your help!

                  A question: the code used to check if it's ok to trade:

                  Code:
                  ---------
                  private bool TimeToTrade
                  {
                  get
                  {
                  if (_tradeTimeBegin == 0 || _tradeTimeEnd == 0)
                  {
                  return true;
                  }
                  else
                  {
                  if (_tradeTimeBegin > _tradeTimeEnd)// sessions that begin previous day and end next day
                  {
                  return ToTime(Time[0]) >= _tradeTimeBegin * 100 || ToTime(Time[0]) <= _tradeTimeEnd * 100;
                  }
                  else
                  {
                  return ToTime(Time[0]) >= _tradeTimeBegin * 100 && ToTime(Time[0]) <= _tradeTimeEnd * 100;
                  }
                  }
                  }
                  }
                  ---------

                  in which code section should be inserted?


                  Thank you,

                  John.

                  Comment


                    #10
                    it is a separate function, so put it below the OnBarUpdate event handler

                    Comment


                      #11
                      Hi Laserdan,

                      thank you for your reply,

                      I have put the following code:

                      Code:
                      ---------
                      private bool TimeToTrade
                      {
                      get
                      {
                      if (_tradeTimeBegin == 0 || _tradeTimeEnd == 0)
                      {
                      return true;
                      }
                      else
                      {
                      if (_tradeTimeBegin > _tradeTimeEnd)// sessions that begin previous day and end next day
                      {
                      return ToTime(Time[0]) >= _tradeTimeBegin * 100 || ToTime(Time[0]) <= _tradeTimeEnd * 100;
                      }
                      else
                      {
                      return ToTime(Time[0]) >= _tradeTimeBegin * 100 && ToTime(Time[0]) <= _tradeTimeEnd * 100;
                      }
                      }
                      }
                      }
                      ---------

                      under

                      protected override void OnBarUpdate()



                      but I get a serie of error messages..

                      Should I simply cut and paste it?

                      Comment


                        #12
                        I thought you knew basic C# and functions and variables. You should really learn this stuff before you start writing/modifying Ninjascript. I can help you no more without that basic level of understanding...sorry.

                        Comment


                          #13
                          New question - same topic.

                          I am using a time parameter as part of the strategy. I would like to optimize the time but cannot seem to figure out how to set it as a parameter that can be set. If I use Int it returns "Right expression Int32" does not match. String says "String does not match."

                          The input in wizard is 11:30 AM and in the code it is 11, 30, 00.

                          Double and Bool would not make sense. Please provide an answer.

                          Comment


                            #14
                            JMont1, for optimizing the time you would need to unfortunately leave the wizard interface - as you would need to split the time up into a hour and minute part represented by two integers that the optimizer could iterate through.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Are you able to provide a sample of how to set these hour and minute times up as integers? It would be a great help.

                              I would be trying to create my strategies in wizard (since I am not a coder) and then insert the replacement code for these time parameters so I could run optimizer against it. Then I would place the best times into the wizard to be able to continue testing other strategy elements.

                              HOPEFULLY, thanks for your answer.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              10 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              242 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              385 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Working...
                              X