Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Create lines based on another indicator

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

    Create lines based on another indicator

    Hi,

    I would like to draw horizontal lines of the peak (starting at the peak and up to infinity on right) of the EMA before the crossover happens. Both ways, short and long like in the picture. Can explain how we can do this in strategy builder?
    Attached Files

    #2
    Hello neshnix89,

    Are you wanting to wait until the crossover happens and check the last few bars for the lowest low?

    Otherwise, how are you planning to predict a cross is going to happen in the future?

    HighestBar(), and LowestBar() can be used to check the last few bars and get a bar number
    https://ninjatrader.com/support/help...highestbar.htm
    https://ninjatrader.com/support/help.../lowestbar.htm

    When the cross occurs, you would need to choose how many bars backward you want to find the highest high bar or lowest low bar.

    Once you have that you can save that bar number to a variable.

    And on each new bar draw the start barsAgo from that bar, with the end bars ago at 0, (to keep extending it on each new bar).

    Code:
    private int highestValueBarsAgo;
    private EMA myEMA7, myEMA14;
    
    myEMA7 = EMA(7);
    myEMA14 = EMA(14);
    
    if (CrossBelow(myEMA7, EMA(14), 1))
    highestValueBarsAgo = HighestBar(EMA(7), 10);
    
    Draw.Line(this, "myLine", highestValueBarsAgo, myEMA7[highestValueBarsAgo], 0, myEMA7[highestValueBarsAgo], Brushes.Red);
    Last edited by NinjaTrader_ChelseaB; 12-13-2022, 09:52 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      Is it possible to do it in strategy builder? Im not familiar with the ninja script. Thanks.

      Comment


        #4
        Hello neshnix89,

        Due to a limitation of not being able to set the Start bars ago for a drawing object in the Strategy Builder, it would be necessary to unlock the script and code this by hand.

        Below is a link to a forum post with helpful resources on getting started with C# and NinjaScript.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi ChelseaB,

          Is it possible to use strategy builder if we don't use the start bar ago for drawing objects? Instead, we just draw a horizontal line.

          Comment


            #6
            Hello neshnix89,

            It would be possible to draw a horizontal line on the current bar, at the current bars high (at the time of the cross not the high from before the cross as barsAgo is not available).

            For the Y value select the indicator.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi ChelseaB,

              I am able to draw the line as per your code. However, it only draws for one high cross and one low cross only. The cross previously doesn't have any line. How can I enable this?

              Click image for larger version

Name:	image.png
Views:	114
Size:	38.3 KB
ID:	1228190

              Comment


                #8
                Hello neshnix89,

                Use a unique tag name each time you want to start a new drawing object.


                I recommend you increment an integer as a counter to add to the tag name.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  Thanks for the advice. I'm able to successfully create the script. Can you advise how we are able to "exposed" the lines created so that they can be referenced from the Strategy Builder? I would like to trigger a buy at the green line and sell at the red line. Appreciate your help.

                  Comment


                    #10
                    Hello neshnix89,

                    Only Plots can be exposed for the strategy builder.

                    Below is a link to a forum post that provides the necessary code to add a plot, make it public, and set a value.
                    I'm trying to expose my variables to the strategy builder so everyone can have better use of the WaveTrend indicator (it has a lot of code). Explain this to me like I am 5 because this isnt the first time I've tried to figure it out and hit a wall. What is Series? I know its like an array that stores bars. Why not just call it


                    Add a plot and set the plot value to the price of the line.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    71 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    143 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    76 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    47 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    51 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X