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

Exiting long and entering short with different quantity in the same bar

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

    Exiting long and entering short with different quantity in the same bar

    Hi,

    I am trying to develop a strategy where I may have to exit a previous long/short position with a certain quantity and enter
    in the other direction with a different quantity (the difference in quantities is because of position sizing).


    Currently I am doing something like this:
    quantity = get_quantity(); // for position sizing for both long and short
    if (enterLong) {
    EnterLong(quantity, "long");
    }
    else if (enterShort) {
    Entershort(quantity, "short");
    }
    else if (exitLong) {
    ExitLong("long");
    }
    else if (exitShort) {
    ExitShort("short");
    }

    Will this work when the long and short quantities are different ?

    Can you please provide me an example to do this correctly.

    Thanks.



    #2
    Hello ausgaef,

    Thank you for your post.

    Yes, that would work even if the value of your quantity variable changes. I've attached a quick Strategy Builder strategy I made that illustrates changing the quantity between short and long entries. I'd suggest unlocking the code and taking a look at how it works.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate, thank you so much. Will try it out.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmtjoancolmenero, 04-25-2024, 03:58 PM
      14 responses
      59 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by raffu, Yesterday, 11:41 AM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by cmtjoancolmenero, Yesterday, 11:56 AM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by reynoldsn, 04-21-2024, 07:53 PM
      3 responses
      25 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by cmtjoancolmenero, Yesterday, 03:40 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X