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 Pattontje, Yesterday, 02:10 PM
      2 responses
      14 views
      0 likes
      Last Post Pattontje  
      Started by flybuzz, 04-21-2024, 04:07 PM
      17 responses
      229 views
      0 likes
      Last Post TradingLoss  
      Started by agclub, 04-21-2024, 08:57 PM
      3 responses
      17 views
      0 likes
      Last Post TradingLoss  
      Started by TradingLoss, 04-21-2024, 04:32 PM
      4 responses
      43 views
      2 likes
      Last Post TradingLoss  
      Started by cre8able, 04-17-2024, 04:16 PM
      6 responses
      56 views
      0 likes
      Last Post cre8able  
      Working...
      X