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

Strategy to place market order

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

    Strategy to place market order

    Hi Friends,

    I am trying to come up with a very simple NinjaScript strategy which places a market order at a specific time in the day ( User specified) regardless of what the price is. The time can be specified as to hours, minutes and seconds EST.

    The order can be specified to go Long or Short and will activate an ATM strategy which contains the exit orders bracket.

    Do you know of any such simple, probably one or two lines strategy available? No other conditions or features.

    If not can anyone help program one for me? I am not sure how to do this?

    Thank you in advance,
    Kailash

    #2
    Hellosourcem,

    Yes, this is possible. After you create the ATM strategy you want. You can use the Strategy wizard for a simplified approach.


    Open the Strategy wizard by going to Tools > New NinjaScript > Strategy. Give your Strategy a name and then click next to skip the input parameter window.
    In the Conditions and Actions page, you can click ADD and create a condition for when a specific time value is equal to the current time. Use the Time Series option to keep track of the current time. Then set the operateor to the "==" sign, this ensures that the strategy is only submitted at the exact time we set. Set the Time Value on the right side to the time you want your Strategy execute. Click Ok. Leave the "Do the following" area blank, as you will add what happens when your conditions are true later. I have included an image to show you what the Conditions window should look like after you set your conditions.


    Click Unlock to view your code so that you can add your AtmStrategyCreate() method. I have included the AtmStrategyCreate() Help guide to assist you further with the syntax of the AtmStrategyCreate() method.
    AtmStrategyCreate()


    Here is what your code should look like under OnBarUpdate(). This example is submitting an ATM strategy at when the time is equal 1:28:02 pm.
    protected override void OnBarUpdate()
    Code:
    [SIZE=2][SIZE=2]     
    {[/SIZE][/SIZE][COLOR=#000000][FONT=Tahoma][LEFT][SIZE=2]            if (ToTime(Time[0]) == ToTime( 13, 28, 2))[/SIZE][LEFT][/LEFT][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][SIZE=2]            {[/SIZE][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][SIZE=2]            AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0 ,[/SIZE][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][SIZE=2]            TimeInForce.Day, GetAtmStrategyUniqueId(), "YourATMTemplateName" ,[/SIZE][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][SIZE=2]            GetAtmStrategyUniqueId());[/SIZE][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][SIZE=2]            }[/SIZE][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][SIZE=2]        }[/SIZE][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [SIZE=2][/SIZE]
    [/LEFT][/FONT][/COLOR]

    Here is our help guide article on using ATM strategies with Automated Strategies in NinjaTrader.
    Using ATM Strategies


    For further assistance, you could also open the code of the SampleATMStrategy built into NinjaTrader. Go to Tools > Edit NinjaScript > Strategy > Choose SampleATMStrategy.
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, Shawn.

      In the Conditions Builder window, I put in the left side Time Series as 0 Bars ago ( I assume this would mean the current time) (Also I unchecked Calculate on Bar close in the beginning of Strategy Wizard) and in the right side, I tried to put in Time value as 9:29:50 AM but it would not accept it and says Property value not valid. It will accept 9:29 AM

      So how do I get in the seconds there and is the current time on the left side correct the way I did it?

      Thanks
      sourcem

      P.S. Since I wrote the above, I was able to get the seconds in the code by manually editing the Code after unlocking it. I added to the Code the ATM strategy create section as you showed but when I tried to compile it, it gave 2 error messages.

      Here is the screen shot of the code and the error messages. Can you guide me on how to fix this? Thank you for your help!
      Attached Files
      Last edited by sourcem; 10-03-2015, 12:39 PM.

      Comment


        #4
        Hello sourcem,

        It looks like you have 1 more closed curly bracket "}" than is needed under OnBarUpdate()
        If you remove one, that should alleviate one or both of the errors.
        Shawn B.NinjaTrader Customer Service

        Comment


          #5
          Thank you, Shawn.

          I removed the extra curly bracket and the error messages went away!

          Appreciate that.

          I was able to compile, no problem.

          sourcem

          Comment


            #6
            Still not placing orders

            Hi Shawn,

            After compiling the above strategy, I applied to a chart with a sim account and enabled the strategy in the Strategies tab but still no order was placed.

            Did I miss a step?

            Thanks,
            kailash

            Comment


              #7
              Originally posted by sourcem View Post
              Hi Shawn,

              After compiling the above strategy, I applied to a chart with a sim account and enabled the strategy in the Strategies tab but still no order was placed.

              Did I miss a step?

              Thanks,
              kailash
              What kind of bars were you using?

              Hopefully 1 second or tick bars.

              Time [0] returns the time stamp of the bar.
              So a 5 minute bar returns only 09:30:00, 09:35:00, 09:40:00,etc. Never anything between

              Do a Print (ToTime (Time [0])); to see this. Open up the output window.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by algospoke, Yesterday, 06:40 PM
              2 responses
              19 views
              0 likes
              Last Post algospoke  
              Started by ghoul, Today, 06:02 PM
              3 responses
              14 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              45 views
              0 likes
              Last Post jeronymite  
              Started by Barry Milan, Yesterday, 10:35 PM
              7 responses
              20 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by AttiM, 02-14-2024, 05:20 PM
              10 responses
              180 views
              0 likes
              Last Post jeronymite  
              Working...
              X