Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Scaling out of a Position

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

    Scaling out of a Position

    I am having issues with getting the 2nd position to sell when the parameters dictate it to my script looks like this:



    // Sell Half then All in Bull Market
    if (Close[0] < EMA(EMA1st)[0]
    && EMA50vs200(
    200, 50).Plot0[0] >= Ratio50vs200h
    && DM(
    7).DiPlus[0] < DM(7).DiMinus[0]
    && RSI(
    12, 1)[0] < 50)
    {
    ExitLong(
    "Enter Long2");
    }
    elseif (Close[0] < EMA(EMA2nd)[0]
    && EMA50vs200(
    200, 50).Plot0[0] >= Ratio50vs200h
    && DM(
    7).DiPlus[0] < DM(7).DiMinus[0]
    && RSI(
    12, 1)[0] < 50)
    {
    ExitLong(
    "","");
    }


    Entrys are ok and Exits of Long2 are ok, but I cannot get the script to close out the remaining position, when on the chart, all requirements have been fulfilled. Please let me know what I missed if you can. Thanks

    #2
    Hi dunwoodyjr,

    The use of else if is likely causing this. There is overlap in the conditions used in both those checks, and else if only returns true when the preceding block all evaluates false. The else if block will never evaluate true since it has some of the same conditions as the preceding if.

    See if you get better results changing this to only if.

    if (Close[0] < EMA(EMA1st)[0]
    && EMA50vs200(200, 50).Plot0[0] >= Ratio50vs200h
    && DM(7).DiPlus[0] < DM(7).DiMinus[0]
    && RSI(12, 1)[0] < 50)
    {
    ExitLong("Enter Long2");
    }
    if (Close[0] < EMA(EMA2nd)[0]
    && EMA50vs200(200, 50).Plot0[0] >= Ratio50vs200h
    && DM(7).DiPlus[0] < DM(7).DiMinus[0]
    && RSI(12, 1)[0] < 50)
    {
    ExitLong("","");
    }
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    647 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    368 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    571 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X