Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry and Exit

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

    Entry and Exit

    Hello,

    I use the following code for entry and exit. However, it takes the long trade only and not the short trade.

    if (Position.MarketPosition==MarketPosition.Flat)
    {
    if (CrossAbove(EMA(Fast), EMA(Slow), 1))
    {
    EnterLong(1);
    SetStopLoss(CalculationMode.Ticks,SL);
    }
    if (CrossBelow(EMA(Fast), EMA(Slow), 1))
    {
    EnterShort(1);
    SetStopLoss(CalculationMode.Ticks,SL);
    }
    }
    else if (Position.MarketPosition==MarketPosition.Long)
    {
    if (Close[0]<EMA(Slow)[0])
    ExitLong(1);

    }
    else
    {
    if (Close[0]>EMA(Slow)[0])
    ExitShort(1);
    }
    I would like to enter the short trade when the condition is met.

    Please advise.

    Rajesh

    #2
    Hello RajeshT,

    Thank you for the post.

    Is the condition becoming true? From what you provided that seems to be correct, I woudld likely suggest to use a Print here to see if the condition is ever true. You could also enable TraceOrders to see if other errors are happening.

    Code:
    if (CrossBelow(EMA(Fast), EMA(Slow), 1))
    {
    [B]Print("Here");[/B]
    EnterShort(1);
    SetStopLoss(CalculationMode.Ticks,SL);
    }


    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse,

      Looks like it has to do with the StartBehavior and Market condition statements that are causing the discrepancy in putting the long and short entry. What are the appropriate statements for a typical short and long entry. Please advise.

      Thanks

      Rajesh

      Comment


        #4
        Hello RajeshT,

        Thank you for the added details.

        Are you asking what the typical syntax is for market type orders? I would otherwise not be certain of a typical entry, that would relate to the condition you build and what your goals are.

        If the condition or start behavior are related to what you are seeing you may need to review those items in the help guide to gain more perspective about the options being used in contrast to the conditions you made. https://ninjatrader.com/support/help..._positions.htm

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        89 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        135 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        119 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        69 views
        0 likes
        Last Post PaulMohn  
        Working...
        X