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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    67 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    36 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    59 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X