Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trendline Indicator Plots

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

    Trendline Indicator Plots

    hello, was going to use trendline indicators values to identify areas to avoid taking a trade, if Close[0] < xNumber of ticks before trendline
    I noticed there is no plots, and was wondering the reason for it. Can plots be created? for this indicator?

    #2
    Hello tkaboris,

    Thank you for your post.

    There is an indicator method available to return the Trend Lines value for the referenced bar:


    What values are you trying to use in your script? If you add print statements while referencing the indicator value, are you able to get the information you need from Trend Lines? Otherwise, the indicator uses Draw.Ray() to draw the actual trend lines rather than plots. You may be able to loop through DrawObjects to get information about the drawn rays or you may be able to modify the indicator to add the desired plots depending on what your needs are. The source code for TrendLines is available in the NinjaScript Editor.

    Please let me know if I may be of further assistance.

    Comment


      #3
      Thank you thats what i needed
      ​​

      Comment


        #4
        Hi; I am evaluating current trendline value to the previous to determine if its up or down, Strategy works but sometimes, as in this case, new trendline begins to form, from down to up, as you see in prints, however no trendline chaged from low to high. and going forward several bars, trendline never changed from low to high, see second image. Something is wrong. What can i do to fix it?
        Strategy is based on tickschange
        Code:
        double curTrendLineValue = TrendLines(4, 1, 25, false)[0];
        double prevTrendLineValue = TrendLines(4, 1, 25, false)[1];​
        
        
        && (curTrendLineValue > prevTrendLineValue)    // long order
        && (curTrendLineValue < prevTrendLineValue)     // short order
        Click image for larger version  Name:	image.png Views:	0 Size:	967.4 KB ID:	1252920
        Click image for larger version  Name:	image.png Views:	0 Size:	867.1 KB ID:	1252921
        On this image trendvalues print wrong values, At the time of short order Bounce Short, actual chart trendline is at 13654, however trenline value prints 13650...
        Click image for larger version

Name:	image.png
Views:	356
Size:	148.9 KB
ID:	1252922
        Last edited by tkaboris; 05-25-2023, 05:12 AM.

        Comment


          #5
          Hello tkaboris,

          Thank you for your reply.

          Are you printing the value of curTrendLineValue/prevTrendLineValue or are you actually printing TrendLines(4, 1, 25, false)[0] and TrendLines(4, 1, 25, false)[1]? Do you notice a difference if you add both the variable and the actual TrendLines() indicator method in your print statement? Maybe one is updated even though the other is not and you can use the prints to compare and better understand what might be occurring.

          I look forward to hearing the results.​​

          Comment


            #6
            I was printing
            Print("cur trendLineValue: " + curTrendLineValue);
            Print("prev trendLineValue: " + prevTrendLineValue);​

            The thing is it never updated to higher trendline
            It keeps on doing it in more market replay testing
            Last edited by tkaboris; 05-25-2023, 10:36 AM.

            Comment


              #7
              Hello tkaboris,

              Thank you for your reply.

              What are the results if you print the following?

              Print("TrendLines for current bar: " + TrendLines(4, 1, 25, false)[0]);
              Print("TrendLines for previous bar: " + TrendLines(4, 1, 25, false)[0]);

              I am curious if you would get the updated values. Please let me know the results.

              Comment


                #8
                Hi, i tried to print other values and its the same thing
                As you see in second image, it took 2 more bars before upper trendline was formed and got the valid short trade....


                Print("Entering TrendLine Bounce Short: " + " " + Time[1] + "- " + CurrentBar);
                Print("trendLineValue: " + curTrendLineValue);
                Print("prev trendLineValue: " + prevTrendLineValue);
                Print("TrendLines for current bar: " + TrendLines(4, 1, 25, false)[0]);
                Print("TrendLines for previous bar: " + TrendLines(4, 1, 25, false)[1]);​



                Click image for larger version

Name:	image.png
Views:	382
Size:	925.9 KB
ID:	1253118
                Click image for larger version

Name:	image.png
Views:	352
Size:	74.5 KB
ID:	1253119

                Comment


                  #9
                  Hello tkaboris,

                  Thank you for your reply.

                  I am only seeing the prints for "TrendLines for current/previous bar" once in your screenshot and the "cur/prev tendLineValue" prints are appearing multiple times. It seems possible that your variables for curTrendLineValue and prevTrendLineValue are not updating as frequently as you are expecting them to. I suggest adding additional prints when the value is updated; you could have a print before of the previous value, then update the variable, then print afterward with the new value.

                  Please let us know if we may be of further assistance.

                  Comment


                    #10
                    I had a wrong screenshot but it was the same values.

                    I dont understand how prints can help because its indicator that plotting lately or earlier

                    Is there a way to specify in strategy that trendlines on tick? not on bar close?
                    double curTrendLineValue = TrendLines( 5, 1, 25, false)[0];

                    Comment


                      #11
                      Hello tkaboris,

                      Thank you for your reply.

                      What is the calculate setting for your strategy set to? Ultimately, the parent script (the strategy in this case) determines how frequently OnBarUpdate() calculates. If you want the indicator calculated on each tick or on price change, you will need to set your strategy's calculate property to that value. If you have any logic that still needs to be calculated on bar close, you can separate that logic into conditions that check if IsFirstTickOfBar is true. For an example of separating logic to calculate on bar close or on every tick, please see the following reference sample:


                      Please let us know if we may be of further assistance.

                      Comment


                        #12
                        Here is an updated screenshot. Strategy is set on each Tick
                        Click image for larger version  Name:	image.png Views:	0 Size:	1.04 MB ID:	1253201
                        Last edited by tkaboris; 05-26-2023, 10:02 AM.

                        Comment


                          #13
                          Strategy is on EachTick.

                          Comment


                            #14
                            Hello tkaboris,

                            Thank you for your reply.

                            If you review the source code for TrendLines and how it calculates Values[0][0], it is apparent that the value of the indicator won't necessarily change on a tick-by-tick basis. It is not expected to see the value from TrendLines(4, 1, 25, false)[0] or TrendLines( 5, 1, 25, false)[0] constantly changing on every tick. I even made a quick indicator that will print the TrendLines value on each tick and it shows that the value does not always have an update. If you comment that out and only print the value when it changes, you can see how frequently it is updated:

                            Code:
                                    private TrendLines myTrendLines;
                                    private double trendLinesValue;
                                    protected override void OnStateChange()
                                    {
                                        if (State == State.SetDefaults)
                                        {
                            
                                            Calculate                                    = Calculate.OnEachTick;
                                        }
                                        else if (State == State.DataLoaded)
                                        {
                                            myTrendLines = TrendLines(4, 1, 25, false);
                                            trendLinesValue = 0;
                                        }
                                    }
                            
                                    protected override void OnBarUpdate()
                                    {
                                        if (State == State.Historical)
                                            return;
                            //            Print(Time[0] + "TrendLines: " + myTrendLines[0]);
                                        if (myTrendLines[0] != trendLinesValue)
                                        {
                                            trendLinesValue = myTrendLines[0];
                                            Print("New trendLinesValue: " + trendLinesValue);
                                        }
                                    }​
                            Thank you for your time and patience.

                            Comment


                              #15


                              Hi again. I am calculating half of a bar and make sure, half of a bar is closing above trendline. If entry condition is not selected, it opens trade from trendline as suppose to. however as soon as i add condition for longs it doesnt open, similarly for shorts. I cant figure out why. My prints are printing half of bar is higher then trendline. Is there anything specific that needs to be done here? && (halfOfABarLong > curTrendLineValue)

                              double halfOfABarShort = (((Math.Abs(Open[1] - Close[1])) / 2) + Close[1]) + 4 * TickSize;
                              double halfOfABarLong = (((Math.Abs(Close[1] - Open[1])) / 2) - Close[1]) - 4 * TickSize;​

                              and in entry logic
                              && (halfOfABarLong > curTrendLineValue)

                              Entering TrendLine Long: 6/2/2023 2:43:03 PM- 4890
                              riskLong: 8- 4890
                              curTrendLineValue: 14584.225- 6/2/2023 2:43:03 PM
                              halfOfABarLong:-14585.5​

                              My strategy is based on ticks with firstickofbar

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              576 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              334 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X