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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        21 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        10 views
        0 likes
        Last Post cre8able  
        Working...
        X