Announcement

Collapse
No announcement yet.

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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        88 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        134 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