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

Exit Short and Entry Long and vv

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

    Exit Short and Entry Long and vv

    Hello,

    I had a short and a long script for trades each direction but now I want to have both in one script as entry conditons can be exit conditons of other trade as well. But I dont know what I´m doing wrong because eg when closing last position short I have then 4 longs (instead of 3). In the code I have ..

    if(conditions for long ...)
    {ExitShort();
    entryOrderL1=EnterLong(1,"L1");
    entryOrderL2=EnterLong(1,"L2");
    entryOrderL3=EnterLong(1,"L3");


    Why are there 4 longs now as you can see in the attached screenshot?


    And then with a new short entry with all longs running I have 6 shorts instead of 3 (please see screenshot "ExitEntry_2")


    // I have "normal" SetStopLoss and SetProfitTarget in the code (but using iOrders for things like counting...)



    Thank you!
    Tony
    Attached Files
    Last edited by tonynt; 07-20-2018, 01:10 AM. Reason: Adding information

    #2
    Hello tonynt,

    Thank you for your note.

    If you are short 1 and call EnterLong for 1 contract, NinjaTrader is going to buy you 1 to close your short position and buy you another one to get you long. Basically EnterLong will first flatten your position before putting you long the quantity you pass to it.

    Calling ExitShort and EnterLong in the same block is going to double up on the closing order, in this case Buying 1 contract two times.

    From the time your ExitShort call is made to the time your EnterLong call is made, Ninjatrader has not received your fill for the ExitShort call and thus submits another close order.

    If you remove your ExitShort call, do you get the results you desire?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello Alan,


      thank you for your reply. I thought one has to close with ExitShort or ExitLong the current trade before entering a trade in opposite direction to avoid trading against and issues with order.


      Thank you
      Tony
      Last edited by tonynt; 07-20-2018, 10:56 AM. Reason: Typing error

      Comment


        #4
        Hello tonynt,

        If you are short and call EnterLong it will buy you two contracts.

        You do not need to close your position first under the managed approach.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by adeelshahzad, Today, 03:54 AM
        5 responses
        32 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        7 responses
        32 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        21 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Working...
        X