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

Exploring TrendChannel values per each parallel line

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

    Exploring TrendChannel values per each parallel line

    Hi
    I'm trying to get the current value of each line.
    It seems that I use wrong values for the GetPrice method.
    What should I use as StartPrice, TotalPriceRangs, and IsInverted?

    The relevant part of my script is below, but results in wrong values:

    myTrendChannel = Draw.TrendChannel(this, "MyTrendChannelDown", false, StartBarsAgoD, High[StartBarsAgoD], EndBarsAgoD, High[EndBarsAgoD], MinSwingD, Low[MinSwingD] );

    ClearOutputWindow();

    foreach (PriceLevel priceLevel in myTrendChannel.PriceLevels)
    {
    //priceLevel.Stroke = new Stroke(Brushes.Transparent);
    double totalPriceRange = myTrendChannel.TrendEndAnchor.Price - myTrendChannel.TrendStartAnchor.Price;
    double price = priceLevel.GetPrice( myTrendChannel.TrendEndAnchor.Price, totalPriceRange, false);
    Print(price);
    Print (priceLevel.Value);
    }

    #2
    Hello shlosh7,

    Thank you for your post.

    I am looking into this on my end and I will follow up when I have further details.

    Comment


      #3
      Hello shlosh7,

      (edit)
      So I went about this without looking into the GetPrice() method...
      The code I have works, but, GetPrice() should be doing the job on its own and I'll look into this.

      (2nd edit)
      I've also had to modify my custom calculation.

      My original statement is below:

      The price levels would need to be calculated with logic similar to how these are calculated in the TrendChannel code.
      Code:
      foreach (DrawingTool tool in DrawObjects)
      {
      	if (tool is TrendChannel)
      	{
      		TrendChannel channel = tool as TrendChannel;
      												
      		foreach (PriceLevel priceLevel in channel.PriceLevels)
      		{
      			// skip the first two price levels which are the start and end prices
      			if (channel.PriceLevels.IndexOf(priceLevel) < 2)
      				continue;
      
      			double price = Math.Abs(channel.TrendStartAnchor.Price - channel.ParallelStartAnchor.Price) * (priceLevel.Value / 100);
      
      			price = (channel.ParallelStartAnchor.Price < channel.TrendStartAnchor.Price) ? channel.TrendStartAnchor.Price - calculatedPrice : channel.TrendStartAnchor.Price + calculatedPrice;
      
      			Print(string.Format("Level {0}: {1}", priceLevel.Value, price ));
      		}						
      	}
      }
      Last edited by NinjaTrader_ChelseaB; 01-03-2018, 01:25 PM.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hi shlosh7,

        I think I've got it.

        Code:
        priceLevel.GetPrice(channel.ParallelStartAnchor.Price, (channel.TrendStartAnchor.Price - channel.ParallelStartAnchor.Price), (channel.TrendStartAnchor.Price > channel.ParallelStartAnchor.Price));
        The psuedo code would be:
        GetPrice(endPrice, range, isNotInverted)
        Last edited by NinjaTrader_ChelseaB; 01-07-2018, 12:44 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello shlosh7,

          (edit)
          So I went about this without looking into the GetPrice() method...
          The code I have works, but, GetPrice() should be doing the job on its own and I'll look into this.

          (2nd edit)
          I've also had to modify my custom calculation.

          My original statement is below:

          The price levels would need to be calculated with logic similar to how these are calculated in the TrendChannel code.
          Code:
          foreach (DrawingTool tool in DrawObjects)
          {
          	if (tool is TrendChannel)
          	{
          		TrendChannel channel = tool as TrendChannel;
          												
          		foreach (PriceLevel priceLevel in channel.PriceLevels)
          		{
          			// skip the first two price levels which are the start and end prices
          			if (channel.PriceLevels.IndexOf(priceLevel) < 2)
          				continue;
          
          			double price = Math.Abs(channel.TrendStartAnchor.Price - channel.ParallelStartAnchor.Price) * (priceLevel.Value / 100);
          
          			price = (channel.ParallelStartAnchor.Price < channel.TrendStartAnchor.Price) ? channel.TrendStartAnchor.Price - calculatedPrice : channel.TrendStartAnchor.Price + calculatedPrice;
          
          			Print(string.Format("Level {0}: {1}", priceLevel.Value, price ));
          		}						
          	}
          }
          Thanks ChelseaB
          Thanks !
          I made small update in your code order to make it working, as calculatedPrice was not declared, so the updated two lines looks like this:
          double calculatedPrice = Math.Abs(channel.TrendStartAnchor.Price - channel.ParallelStartAnchor.Price) * (priceLevel.Value / 100);

          double price = (channel.ParallelStartAnchor.Price < channel.TrendStartAnchor.Price) ? channel.TrendStartAnchor.Price - calculatedPrice : channel.TrendStartAnchor.Price + calculatedPrice;

          Hopefully that is the logic you meant to implement.
          It works,But, the output prints the Y coordination of each parallel line START , vs. its current value, at last bar update.[0] .
          My goal is to detect current price crossing any of the parallel lines, so I have to have their CURRENT values.
          What changes should be made?
          Thanks again
          Will look at your other solution (getprice) now
          Shlomi

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hi shlosh7,

            I think I've got it.

            priceLevel.GetPrice(channel.ParallelStartAnchor.Pr ice, (channel.TrendStartAnchor.Price - channel.ParallelStartAnchor.Price), (channel.TrendStartAnchor.Price > channel.ParallelStartAnchor.Price));

            The psuedo code would be:
            GetPrice(endPrice, range, isNotInverted)
            Hi
            Thanks for your reply.
            If I got it right, this option will also print the STARTING point of each parallel line.
            How do I get the their CURRENT value?
            (If possible, please send me your tested code)
            Best,
            Shlomi

            Comment


              #7
              Hello shlosh7,

              For the end points, use the channel.ParallelEndAnchor.Price in place of the channel.ParallelStartAnchor.Price and channel.TrendEndAnchor.Price in place of channel.TrendStartAnchor.Price.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Guys,

                I am working with the Channel tool and do not see the ParallelEndAnchor as an item in the object. I do see it in the help file, and am using version 8.0.13.1

                Please advise.

                Thanks
                mrlogik
                NinjaTrader Ecosystem Vendor - Purelogik Trading

                Comment


                  #9
                  Hello mrlogik,

                  I am able to reproduce this behavior and I have reported this to our development.

                  Once I have a tracking ID for this behavior I will post in this thread.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Great thank you
                    mrlogik
                    NinjaTrader Ecosystem Vendor - Purelogik Trading

                    Comment


                      #11
                      will it provide the Parralel Lines CURRENT values?

                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello mrlogik,

                      I am able to reproduce this behavior and I have reported this to our development.

                      Once I have a tracking ID for this behavior I will post in this thread.
                      Thanks
                      Shlomi

                      Comment


                        #12
                        Hi NT,

                        In the meantime I believe a work around is to access the Anchors collection of the channel object. Of course I have to do a little simple math (compute slope and y intercept) in order to determine the intersect price, but that's not a problem.
                        mrlogik
                        NinjaTrader Ecosystem Vendor - Purelogik Trading

                        Comment


                          #13
                          Hi again,

                          I went a bit further into this and am finding that the BarsAgo value for the anchors collection is undefined.

                          Simple block of code to replicate

                          Code:
                          			foreach (var obj in ChartControl.ChartObjects)
                          			{		
                          				if(obj.Name ==  "Trend channel") 
                          				{
                          					TrendChannel channel = (TrendChannel)obj;
                          				
                          					// Left most point
                          					double p0 = channel.Anchors.ElementAt(0).Price;					
                          					// Right most point.
                          					double p1 = channel.Anchors.ElementAt(1).Price;				
                          					
                          					int numBars0 = (int)channel.Anchors.ElementAt(0).BarsAgo;
                          					int numBars1 = (int)channel.Anchors.ElementAt(1).BarsAgo;
                          					
                          					double slope0 = Math.Abs(p0 - p1) / Math.Abs(numBars0 - numBars1);
                          					
                          					Print("numBars0 = " + numBars0.ToString());
                          					Print("numBars1 = " + numBars1.ToString());		
                          
                                                    }
                                           }
                          My print gives

                          numBars0 = -2147483648
                          numBars1 = -2147483648

                          Please advise.
                          mrlogik
                          NinjaTrader Ecosystem Vendor - Purelogik Trading

                          Comment


                            #14
                            Hi guys,

                            Any thoughts / movement on this?
                            mrlogik
                            NinjaTrader Ecosystem Vendor - Purelogik Trading

                            Comment


                              #15
                              Hello mrlogik,

                              Thank you for your patience.

                              I would not have an update at this time but this item is being looked into for the Trend Channel.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by gravdigaz6, Today, 11:40 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by MarianApalaghiei, Today, 10:49 PM
                              3 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by XXtrader, Today, 11:30 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post XXtrader  
                              Started by love2code2trade, Yesterday, 01:45 PM
                              4 responses
                              28 views
                              0 likes
                              Last Post love2code2trade  
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post funk10101  
                              Working...
                              X