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

Strategy keeps looping and does not enter at next entry

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

    Strategy keeps looping and does not enter at next entry

    When I'm using multiple indicator or strategies it keeps looping even after I set profit target. I am trying to hit a profit target and after that trend is over I want the strategy to enter at the next entry. Below is one of the example. I wish there was a if and then statement in C# it would be alot easier to say if trend was -1 then +1 then entry 1.

    // Set 1
    if (AuSuperTrendU111.Trend[0] == -1)
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if (AuSuperTrendU111.Trend[0] == 1)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }


    Thanks,
    Taylor

    #2
    Hello Taylor,

    Welcome to the NinjaTrader forums!

    C# does have an 'else' and an 'else if'.

    Below are links to educational sites.
    http://www.dotnetperls.com/if
    https://www.w3schools.com/cs/cs_conditions.asp


    You can also require in the condition that the position must be flat.
    https://ninjatrader.com/support/help...etposition.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      Thanks for the response, but seem like if we use else it might not be the same as then. Since the next bar will also be trend == 1 and the order will fill again as a long position. Do you have an example where we can say if previous trend is -1 and current trend is +1 then entry long? That way it wont cause entry everytime we start the strategy at unwanted position?

      Comment


        #4
        Hello Taylor,

        Are you asking how to find the value from the previous bar?

        Use 1 as the bars Ago index.

        For example:
        if (AuSuperTrendU111.Trend[1] == -1 && AuSuperTrendU111.Trend[0] ==1)
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kempotrader, Today, 08:56 AM
        0 responses
        6 views
        0 likes
        Last Post kempotrader  
        Started by kempotrader, Today, 08:54 AM
        0 responses
        4 views
        0 likes
        Last Post kempotrader  
        Started by mmenigma, Today, 08:54 AM
        0 responses
        2 views
        0 likes
        Last Post mmenigma  
        Started by halgo_boulder, Today, 08:44 AM
        0 responses
        1 view
        0 likes
        Last Post halgo_boulder  
        Started by drewski1980, Today, 08:24 AM
        0 responses
        4 views
        0 likes
        Last Post drewski1980  
        Working...
        X