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 andrewtrades, Today, 04:57 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        5 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X