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

Strategy closes all positions instead of just the runner

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

    Strategy closes all positions instead of just the runner

    I have a script that should only close my runner, but it closes all positions at once. Does something look off here? Appreciate your help!


    //Close the runner on 13 and 9 cross
    if (b_4 != null && b_4.OrderState == OrderState.Filled && (b_3 == null || b_3.OrderState != OrderState.Filled))
    {
    if (ema_9[1] < ema_13[1])
    {
    //Print("Close all on 4th runner buy");
    ExitLong();
    b_1 = null;
    b_2 = null;
    b_3 = null;
    b_4 = null;

    take_1 = null;
    take_2 = null;
    take_3 = null;
    take_4 = null;

    }
    }
    if (s_4 != null && s_4.OrderState == OrderState.Filled && (s_3 == null || s_3.OrderState != OrderState.Filled))
    {
    if (ema_9[1] > ema_13[1])
    {
    //Print("Close all on 4th runner sell");
    ExitShort();
    s_1 = null;
    s_2 = null;
    s_3 = null;
    s_4 = null;

    take_1 = null;
    take_2 = null;
    take_3 = null;
    take_4 = null;

    #2
    Hello koop1975,

    Thanks for your post.

    I do not see anything specifically wrong in the code you shared. If a script is not behaving as expected, debugging prints should be added to the script to understand how it is behaving.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121

    Let us know if we may assist further.​​
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,607 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    9 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    19 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    6 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    16 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X