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

Coding a reverse order w/ only enough margin for 2 contracts

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

    Coding a reverse order w/ only enough margin for 2 contracts

    Hello,

    If you read the following post:


    You will see that I am having trouble with a strategy requiring the ability to reverse when a condition is met, but I currently only have enough margin to cover 2 contracts. Apparently a true reversal requires 3 contracts.

    So if I am going long and I need to reverse to go short, I am currently using the EnterShort() command. This works to close the long position and open a new short position, but as I said it requires 3 contracts to do so.

    So it looks like I need to find the most time sensitive way to close the open position, wait until it is actually closed and then submit my new position. The problem I can see right now would be the fact that the OnBarUpdate() only runs once the bar has closed, so if I close a position upon one bar closing, I can't wait until the next bar closes to make sure the position is flat and then open a new reversed position.

    Please keep in mind that I am not a C# programmer, but I can usually understand what the code is doing by reading it.

    I am wondering how I can have my strategy close the position, wait until we receive the "close position filled" response from the broker and then submit the reverse market order. All without waiting for the bar to close. I also want to keep "CalculateOnBarClose" set to true.

    Thank you,
    insomniac

    #2
    This is advanced programming and requires the use of OnOrderUpdate() method in NT 6.5. Adding some more cash to your account would also get rid of the margin limitation
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      This is advanced programming and requires the use of OnOrderUpdate() method in NT 6.5. Adding some more cash to your account would also get rid of the margin limitation
      Ok, I give up Ray. Now you are just busting my balls

      I am currently utilizing the OnOrderUpdate() for many uses in my strategy, but it is my understanding that OnOrderUpdate() is read only. This leads me to believe that it cannot submit new positions. Am I wrong?

      Can someone help me out here, with a suggestion or a sample?

      Thank you,
      insomniac

      Comment


        #4
        The order that goes out to close the position upon a reversal, is it always going to be named "Close position"? If so, will this work?

        if (order.OrderState == OrderState.Filled)
        {
        if (order.Name == "Close position")
        {
        if (order.Action == Action.Sell)
        {
        EnterShort(1, "revShort Entry");
        Print("Reversing & Going Short");
        }
        else if (order.Action == Action.BuyToCover)
        {
        EnterLong(1, "revLong Entry");
        Print("Reversing & Going Long");
        }
        }
        }

        Is there any other time that "Close position" is used and will interfere with the code above?

        Thanks,
        insomniac

        Comment


          #5
          There is more to it than what you have provided. Unfortunately I do not have a sample but in a nutshell. If you are not intimately familiar with OO programming I really would not venture down this road at this time as you will really need to invest to understand.

          I really suggest you increase the size of your account. I understand this is not always possible so maybe ask your broker to reduce the margin requirements?
          RayNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Ray View Post
            There is more to it than what you have provided. Unfortunately I do not have a sample but in a nutshell. If you are not intimately familiar with OO programming I really would not venture down this road at this time as you will really need to invest to understand.

            I really suggest you increase the size of your account. I understand this is not always possible so maybe ask your broker to reduce the margin requirements?
            NT_Ray,

            I have a 'hands on' type of personality. I am a web developer and a novice C++ programmer. I am not an idiot, I am just not a professional C# programmer. It has taken me a while, but I have coded a pretty in-depth strategy via manual coding(no wizard used here). I am not wealthy by any means, and cannot afford to throw money at this issue at this point in time. Even if I did have the money, I would much rather find a solution and fix the issue myself instead of throwing money at it. This is how I learn. I am not asking for a fix, I am asking for some ideas or guidance.

            insomniac

            Comment


              #7
              I did not imply you are an idiot and if it came across this way, I apologize. Short of coding it for you, there really is no reference sample available specific to what you want to do.

              In a nutshell -

              - You must hold IOrder variable for the order you submit to close the position via ExitLong() or ExitShort()
              - You must then monitor OnOrderUpdate() for confirmation of a fill of this order at which time you can submit your entry order for the opposite direction
              - Please review all of the advanced sections for order management and event driven programming
              - Review any reference samples we have in the resource section of our forum
              RayNinjaTrader Customer Service

              Comment


                #8
                Thank you for your time.

                I didn't mean to imply that you had called me an idiot, but I know that sometimes people need to know that you are a capable individual before they will offer their help. Otherwise they may assume that they will end up dealing with a newbie and doing the work for them.

                I really just needed some direction. Thankfully, because of your advice, I was able to recode the reversal portion of my strategy to work exactly as needed.

                Thanks again,
                insomniac

                Comment


                  #9
                  Excellent!
                  RayNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Stanfillirenfro, Today, 07:23 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by cmtjoancolmenero, Yesterday, 03:58 PM
                  2 responses
                  20 views
                  0 likes
                  Last Post cmtjoancolmenero  
                  Started by olisav57, Yesterday, 07:39 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by cocoescala, 10-12-2018, 11:02 PM
                  7 responses
                  944 views
                  0 likes
                  Last Post Jquiroz1975  
                  Started by oviejo, Today, 12:28 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Working...
                  X