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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    60 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    145 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    161 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    97 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    283 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X