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

If two conditions true Enter Long but how to made

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

    If two conditions true Enter Long but how to made

    Dear All from NT8 Support,
    i want to make in a 15min time Frame strategy if Rebound Entry comes true (first condition) && P-SAR turns to Long as a confirmation for my Rebound (second condition) the strategy EnterLong. But it dosn't.
    For Support pleasse find attached the Strategy as an snapshot from *.cs from Strategy builder and a picture that decribed this issue.
    --> How can i say in Ninja script if the first conditons comes up 3-4 bars earlier that this signal should be open till the second conditons comes up so too? Because there is a time shift between.
    --> Or have i to say If A= true && B=true then Enter Long? Please remember i'm an absolute beginner in C#.
    Every hint or advice would be appreciated and nice.
    Thank you in every case for your help and support.
    Kind Regards
    Gunter
    Attached Files

    #2
    Hello Gunter,

    Thanks for your post.

    You have the right idea to use "true" conditions. What you can do is to have your conditions set a bool variable for the bollinger and another bool for the Psar and when both bools are true to then place the order and reset the bools to false.

    Here is a short video to further explain the concept of two asynchronous conditions for an entry condition: https://paul-ninjatrader.tinytake.co...OF8xMDYwMjE0OA

    In the video I use dots to help show when a set is true and would advise to use this concept while developing (any) strategy to help you visually debug your strategy.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Dear Paul,
      Thank you very much for this hint and this greate video and this short responce! I will try and do so.
      Kind Regards Gunter

      Comment


        #4
        Originally posted by NinjaTrader_PaulH View Post
        Hello Gunter,

        Thanks for your post.

        You have the right idea to use "true" conditions. What you can do is to have your conditions set a bool variable for the bollinger and another bool for the Psar and when both bools are true to then place the order and reset the bools to false.
        Dear Paul, thanks for the simple way to visualize debug process.

        I have a similar question, so I allow myself to write in this thread.

        The situation is as follows:

        If this condition is met, the long entry is performed, but not on the desired bar.
        I set up a check according to your method, it turned out that separately two conditions "condition1" and "condition2" are executed correctly, but when they are combined into a single "if" condition, it does not work correctly.

        if (((((indicator1[0] > indicator1[1]) && (indicator2[0] >= 30)) == false)) // condition1
        && (((indicator1[1] > indicator1[2]) && (indicator2[1] >= 30)) == true)) // condition2
        { EnterLong(1);}

        Need help to find mistake.

        Thanks in advance.
        Last edited by readerror; 03-18-2021, 02:13 AM.

        Comment


          #5
          Hello readerror,

          Thanks for your post and welcome to the NinjaTrader forums!

          Is this the issue "If this condition is met, the long entry is performed, but not on the desired bar."?

          If so, please clarify how you are testing (live data, historical data, playback with market replay, strategy analyzer).

          What is the Calculate setting of the strategy?

          Can you post a screenshot the illustrates the incorrect entry versus what you expect? (Please include the entire chart so I can see time base, price scale, and instrument used).

          Are you using the Strategy Builder or working directly in Ninjascript coding?

          Paul H.NinjaTrader Customer Service

          Comment


            #6
            The main question is that when debugging separately, the conditions are fulfilled correctly, but when combined into a single condition, oddly enough, there is no result.

            After executing code in NinjaScript on live data (MyContinuum connection), only green and red dots are displayed, but never yellow (example is framed in the screenshot).
            Instrument - MES

            Code sample:

            protected override void OnBarUpdate()
            {
            if ((indicator1 [0]> indicator1 [1]) && (indicator2 [0]> = 30))
            { Long0 = false;
            Draw.Dot(this, "Long0" + CurrentBars[0].ToString(), true, 0, (Low[0] + (10 * TickSize)), Brushes.Red);
            }

            if ((indicator1 [1]> indicator1 [2]) && (indicator2 [1]> = 30))
            {
            Long1 = true;
            Draw.Dot(this, "Long1" + CurrentBars[0].ToString(), true, 0, (Low[0] + (20 * TickSize)), Brushes.Green);
            }

            if ((Long0 = false) && (Long1 = true))
            {
            Draw.Dot(this, "LongAll" + CurrentBars[0].ToString(), true, 0, (Low[0] + (30 * TickSize)), Brushes.Yellow);
            Long0 = false;
            Long1 = false;
            }
            }

            Click image for larger version  Name:	Screenshot1.jpg Views:	0 Size:	146.2 KB ID:	1147234
            Last edited by readerror; 03-18-2021, 11:09 AM.

            Comment


              #7
              Hello readerror,

              Thanks for your reply.

              Based on what you have shown, assuming it compiles, I see no issues and would expect as you do to see the yellow dots 30 ticks above the high.

              In your screenshot though, I do see that you must have other code conditions that are drawing the same colored dots below the low of the bar. Is it possible that the other code is impacting this logic (and vice-versa)?

              What I would suggest at this point would be to use a Print statement just above the line if ((Long0 = false) && (Long1 = true)) to print out the time of the bar and the state of the bools, for example: Print (Time[0]+" Long0 is "+Long0+" Long1 is "+Long1);

              This would confirm what seems obvious that the state of the bools are not as expected. Then it becomes a matter of backing up from there and finding what is setting the bools incorrectly and when.

              Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Paul, I'm sorry, I mixed this up and didn't have time to edit the message before you started responding. In fact, the code conditions include Low. After adding the line Print (Time [0] + "Long0 is" + Long0 + "Long1 is" ​​+ Long1); in NinjaScript Output I get more than 1k messages for each bar with correct values(screenshot below), but there are no yellow dots on the graph.

                Click image for larger version

Name:	Screenshot2.jpg
Views:	312
Size:	195.9 KB
ID:	1147257

                Comment


                  #9
                  Hello readerror,

                  Thanks for your reply.

                  Sounds like you are running with calculate.OnpriceChange or Calculate.OnEachTick and in those cases yes you would be printing a lot of prints. in addition, you will drawing a lot of dots and removing them at the same time.

                  You may want to change to Calculate.OnBarClose for this debugging effort.

                  I would suggest to now add a print statement inside the if action block where you have the Draw.Dot yellow. This would tell us that the logic is accepted if you see prints for that.

                  Note: Please make sure you are compiling and then removing the indicator from the chart and reapplying after compiling just to ensure you are working with the correct version.

                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Dear Paul, i fix the poroblem with Yellow dots. The error was in an incorrectly specified operator '='. When I change this to '==' yellow dots appeared on chart.
                    Correct condition is "if ((Long0 == false) && (Long1 == true))".
                    Thanks a lot for your help.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by wzgy0920, 04-20-2024, 06:09 PM
                    2 responses
                    26 views
                    0 likes
                    Last Post wzgy0920  
                    Started by wzgy0920, 02-22-2024, 01:11 AM
                    5 responses
                    32 views
                    0 likes
                    Last Post wzgy0920  
                    Started by wzgy0920, Yesterday, 09:53 PM
                    2 responses
                    49 views
                    0 likes
                    Last Post wzgy0920  
                    Started by Kensonprib, 04-28-2021, 10:11 AM
                    5 responses
                    191 views
                    0 likes
                    Last Post Hasadafa  
                    Started by GussJ, 03-04-2020, 03:11 PM
                    11 responses
                    3,231 views
                    0 likes
                    Last Post xiinteractive  
                    Working...
                    X