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 on the market

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

    Entry on the market

    Hi,

    I would like to know what I have to use between IPosition, Iexecution and the rest for finding a position on the market.

    I already built a part of my strategy but what I need is this

    I want to use my strategy if I'm trigger on a certain time I want to close my position and reverse it

    Ex:
    I got filled long by the market at 9:59:58 so I want my new strategy close that position and enter short

    Thanks to all

    #2
    Hello Dervakon,

    Thanks for your note.

    You can detect the position of your strategy using Position.MarketPosition.

    For example:
    Code:
    private IOrder myLong = null;
    private IOrder myShort = null;
    
    protected override void OnBarUpdate()
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    myLong = EnterLong(1);
    }
    
    protected override void OnPositionUpdate(IPosition position)
    {
    	if (myLong != null && myLong.OrderState == OrderState.Filled && ToTime(DateTime.Now) > 175958)
    		EnterShort();
    }
    What this code will do is after a long position is submitted it will check to see if the time of that bar is greater than 9:59:58 PM. If it is, it will submit an EnterShort.


    Please let me know if this does not resolve your inquiry.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply Chelsea B.

      What I need is to detect un entrie, even a market order. I don't want to enter long or short with my strategy but I want my strategie to detect a entry and after that if it is higher of 9:59:58 close my position and reverse it

      If I don't have a entry and the strategy engage for the amount of time a need it exemple 3 sec, the strategy is disable...

      Thanks
      Last edited by Dervakon; 05-30-2013, 02:38 PM.

      Comment


        #4
        Hi Dervakon,

        Thanks for the reply.

        In this case you can check to see what position the order is and then submit the opposite. This will automatically close the position and reverse to the opposite.

        For example:

        Code:
        protected override void OnPositionUpdate(IPosition position)
        {
        	if (ToTime(DateTime.Now) > 175958)
        	{
        		if (position.MarketPosition == MarketPosition.Long)
        			EnterShort();
        		else
        			EnterLong();
        	}
        }

        Please let me know if this is not what you are looking for.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          What is the function of position.MarketPosition == MarketPosition.Long

          Thanks

          Comment


            #6
            Hi Dervakon,

            Checking position.MarketPosition == MarketPosition.Long is how you can find the direction of the order that has been placed. If the order was an EnterLong this will be MarketPosition.Long. If the order was an EnterShort, this will be MarketPosition.Short.

            The code will see if the time is past 175958. If the current time is past that, the strategy will submit an order in the opposite direction.


            Let me know if I can be of further assistance.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks for the reply,

              What append if an order is filled at 175959 so the strategy must cancel the entry right a way and after reverse to the opposite direction ?

              Thanks

              Comment


                #8
                Hello Dervakon,

                Yes that would be correct.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  After testing it not working, seem the position.market stay flat all the time on my output windows, I need someting who can track my order. Because, if I use a strategy on 1min for the CL and get another 1min CL Chart with Chart trader, I can't track the order If I use the chart trader...

                  I think Position market it not what I need

                  finally what I need is a strategy who can track my order already on the market. I don't want my strategy to enter the marker just tracking existing position on the market...

                  Can you help me please

                  Thanks
                  Last edited by Dervakon; 05-31-2013, 07:02 AM.

                  Comment


                    #10
                    Hi Dervakon,

                    I do not think I have fully understood the goal you are trying to achieve.

                    The code I provided was intended to be a check at the time of order entry. If when an order is placed the local time is past 9:59:58, the order will be reversed.

                    Can you clarify for me the steps you would like your strategy to make?


                    Also, regarding tracking an order that rests with the broker that was not submitted by the strategy is unsupported. However, it is possible to find the position and quantity of your account.

                    Below is a link to a thread that discusses this method.
                    http://www.ninjatrader.com/support/f....php?t=28306#6
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Jimmyk, 01-26-2018, 05:19 AM
                    6 responses
                    835 views
                    0 likes
                    Last Post emuns
                    by emuns
                     
                    Started by jxs_xrj, 01-12-2020, 09:49 AM
                    6 responses
                    3,291 views
                    1 like
                    Last Post jgualdronc  
                    Started by Touch-Ups, Today, 10:36 AM
                    0 responses
                    11 views
                    0 likes
                    Last Post Touch-Ups  
                    Started by geddyisodin, 04-25-2024, 05:20 AM
                    11 responses
                    62 views
                    0 likes
                    Last Post halgo_boulder  
                    Started by Option Whisperer, Today, 09:55 AM
                    0 responses
                    9 views
                    0 likes
                    Last Post Option Whisperer  
                    Working...
                    X