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

NinjaScript Indicator Behavior

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

    #16
    Hello i2w8am9ii2,

    Thank you for your patience.

    You could also look to simplify the conditions by checking the bar direction inside the conditions themselves. If nothing applies to the scenario then you could remove the object or set it to transparent.

    In the code below you could replace the calls to Draw.HoriztonalLine() as Brushes.Transparent to RemoveDrawObject if you preferred.

    Code:
    if ((RSI1.Avg[0] >= 55)
    && (EMA1[0] > EMA2[0])
    && (High[0] > ParabolicSAR1[0]))
    {[INDENT]if (High[0] > Open[0])[INDENT]Draw.HorizontalLine(this, "soTag002", Close[0] - 4 * TickSize, Brushes.LimeGreen, DashStyleHelper.Solid, 3);[/INDENT]
    else if (Low[0] < Open[0])[INDENT]Draw.HorizontalLine(this, "soTag002", Close[0] - 4 * TickSize, Brushes.Transparent, DashStyleHelper.Solid, 3);[/INDENT][/INDENT]
    }
    else if ((RSI1.Avg[0] <= 45)
    && (EMA1[0] < EMA2[0])
    && (Low[0] < ParabolicSAR1[0]))
    {[INDENT]if (Low[0] < Open[0])[INDENT]Draw.HorizontalLine(this, "soTag002", Close[0] + 4 * TickSize, Brushes.DeepPink, DashStyleHelper.Solid, 3);[/INDENT]
    else if (High[0] > Open[0])[INDENT]Draw.HorizontalLine(this, "soTag002", Close[0] - 4 * TickSize, Brushes.Transparent, DashStyleHelper.Solid, 3);[/INDENT][/INDENT]
    }
    else[INDENT]Draw.HorizontalLine(this, "soTag002", Close[0] - 4 * TickSize, Brushes.Transparent, DashStyleHelper.Solid, 3);[/INDENT]
    Please let me know if you have any questions.
    Last edited by NinjaTrader_PatrickH; 09-06-2018, 07:40 AM.
    Josh G.NinjaTrader Customer Service

    Comment


      #17
      Hi Josh,

      Now the horizontal lines are being drawn on both the long and short sides, and they are becoming transparent when the price action begins to reverse or consolidate.

      :-)

      This is just in my initial testing, but I'm sure you know exactly what you're doing and that this should be the final code needed.

      Thanks so much for your help, Josh. I do appreciate it very much.

      Comment


        #18
        Hello i2w8am9ii2,

        Thank you for your response.

        This was an example to show how to use the conditions to create the necessary results. Please make sure to review your conditions so that you can break them apart or simplify them where needed.

        Comment


          #19
          Hi Patrick,

          Thanks for your reply.

          Yes, this was a great education on NinjaScript coding and troubleshooting.

          Thanks for the support and encouragement during my learning process.

          Comment


            #20
            Hi Josh,

            I've been testing my new indicator, and the code you gave for it to resolve the issue I was having with the drawing of the horizontal lines does make all the difference. Thanks again so much for your help.

            While looking at the code although, I saw a couple of things that I thought might be typo errors.

            Again, I'm just learning and I don't know enough NinjaScript or C# to know code much, and the indicator does work well, I'm just wondering if there could be performance issues later or something if there was a typo error made if in a rush when fixing the code, etc.

            The first possible typo I see is in the if else if statements. They are ordered as follows:

            if
            if
            else if
            else if

            if
            else if
            else


            I'm just wondering if the 'if' inbetween the else if statements was a typo or not. Screenshot attached.

            The other possible typo is with the arithmetic operators. All of them are using the minus sign arithmetic operator, except for one of the lines of code, which uses a plus sign arithmetic operator.

            The attached screenshot has arrows pointing to the arithmetic operators that I'm referring to.

            Thanks again for your help,
            Attached Files

            Comment


              #21
              Hello i2w8am9ii2,

              You are correct. that is a typo. The mistake is actually an extra subtraction operator though. I swapped it out for the correct addition operator to match your original code snippet.

              In the snippet below I'd like you to take a look at the way I have my code formatted for readability. Generally it is good practice to indent things on the inside of each "if-statement" so you can easily read through your own logic. In your screenshot it looks like you are missing the indentations that I have, so you have to mentally separate each of the conditions to read it.

              Code:
              protected override void OnBarUpdate()
              {
              	if ((RSI1.Avg[0] >= 55)
              	&& (EMA1[0] > EMA2[0])
              	&& (High[0] > ParabolicSAR1[0]))
              	{
              		if (High[0] > Open[0])
              			Draw.HorizontalLine(this, "soTag002", Close[0] - 4 * TickSize, Brushes.LimeGreen, DashStyleHelper.Solid, 3);
              		else if (Low[0] < Open[0])
              			Draw.HorizontalLine(this, "soTag002", Close[0] - 4 * TickSize, Brushes.Transparent, DashStyleHelper.Solid, 3);
              	}
              	else if ((RSI1.Avg[0] <= 45)
              	&& (EMA1[0] < EMA2[0])
              	&& (Low[0] < ParabolicSAR1[0]))
              	{
              		if (Low[0] < Open[0])
              			Draw.HorizontalLine(this, "soTag002", Close[0] + 4 * TickSize, Brushes.DeepPink, DashStyleHelper.Solid, 3);
              		else if (High[0] > Open[0])
              			Draw.HorizontalLine(this, "soTag002", Close[0] + 4 * TickSize, Brushes.Transparent, DashStyleHelper.Solid, 3);
              	}
              	else
              		Draw.HorizontalLine(this, "soTag002", Close[0] - 4 * TickSize, Brushes.Transparent, DashStyleHelper.Solid, 3);
              }
              Josh G.NinjaTrader Customer Service

              Comment


                #22
                Hi Josh,

                Thanks for the info and for the updated code.

                I appreciate all your help very much.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by llanqui, Yesterday, 10:29 AM
                4 responses
                22 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by TAJTrades, Today, 11:03 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by Dziu-Dziu, 02-04-2018, 07:46 AM
                26 responses
                1,767 views
                0 likes
                Last Post mochibocchi  
                Started by DawnTreader, 05-08-2024, 05:58 PM
                19 responses
                78 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cshox, Today, 11:11 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X