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 Nyman, Today, 02:27 PM
        0 responses
        9 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by qewcool, Today, 10:26 AM
        2 responses
        24 views
        0 likes
        Last Post qewcool
        by qewcool
         
        Started by RISKYBUSINEZZ, Today, 09:07 AM
        4 responses
        33 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by tkaboris, Today, 08:30 AM
        3 responses
        19 views
        0 likes
        Last Post tkaboris  
        Started by DerkWehler, 07-15-2024, 11:35 AM
        19 responses
        57 views
        0 likes
        Last Post DerkWehler  
        Working...
        X