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 helpwanted, Today, 03:06 AM
        1 response
        11 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        9 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        387 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X