Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Interacting with drawings in SBuilder

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

    Interacting with drawings in SBuilder

    Good afternoon, I am creating a strategy in startegy builder and I would need to be able to interact with drawings (horizontal lines) for example: make a long entry when the price crosses a horizontal line above.
    I understand that it is impossible to create this condition from sbuilder and I should do it from Ninjascrpt, right? if so, could you guide me on how to create this code in ninja script to add it to my existing strategy already created in builder? thank you very much in advance for your kind reply.​

    #2
    Hello micaeliglesias,

    Unfortunately, this would not be something that can be created with the Strategy Builder as there would not be access to the prices of drawing object anchors.

    It would be necessary to unlock the script and code by hand.

    If the strategy is drawing the objects, you could assign those to variables and then access the objects anchors at a later bar.

    private HorizontalLine myLine;

    if (/* conditions to draw the object here */)
    {
    HorizontalLine = Draw.HorizontalLine(this, "tag1"+CurrentBar, High[0], Brushes.Black);
    }

    if (myLine != null && CrossABove(Close, myLine.StartAnchor.Price, 1))
    {
    Print(Time[0].ToString() + " price crossed above horizontal line");
    }

    Below is a link to the help guide on HorizontalLine.


    If the line is being manually drawn, you can find the object in the DrawObjects collection.


    I am also including a link to support article with helpful resources on getting started with NinjaScript and C#. Be sure to start by watching the 'NinjaScript Editor 401' training video.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thank you very much for the answer, I will try the way you recommend.

      Comment


        #4
        Hi Chelsea, I have seen your 401 video and now I understand a little more what you recommend me in the previous answer, my intention is not that the strategy draws horizontal lines, but that it interacts with the horizontal lines that I draw every day on the chart, I will explain better.
        I have already created a strategy with sbuilder, but I have the disadvantage that the entry conditions are against the areas, therefore I would like to be able to draw each day the areas manually (since I can not find any indicator that draws precise areas with plots) so that the entry conditions are NOT given if they are going to face them.​

        Comment


          #5
          Attached Files

          Comment


            #6
            Hello micaeliglesias,

            If the line is being manually drawn, you can find the object in the DrawObjects collection.


            In the screenshot you have HorizontalLine[0] which appears to be a custom Series<double> object that is using the same name as the HorizontalLine class.
            You will need to choose a different name for your custom Series<double> object.
            If you are not declaring a custom series... note drawing objects are not series objects and are not used with indexes..
            You will need the drawing object anchors to get the price as shown in post # 2.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Search for user ‘trendisyourfriend’ on nexusfi dot com for his thread: “ tiyfeasyordering-strategy-helping-bot-enter-manage-trade’’…

              ''This thread is for discussing a strategy i created a while ago, to familiarize myself with Ninjascript, and a few commands to open and manage a trade. In that sense, it is a helping bot. '’

              May have to be a member to view it, I’m not allowed to share from it. And he’s not updated that thread in a long time so don’t know if it was workable or not, just thought his process steps might be helpful.

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello micaeliglesias,

                If the line is being manually drawn, you can find the object in the DrawObjects collection.


                In the screenshot you have HorizontalLine[0] which appears to be a custom Series<double> object that is using the same name as the HorizontalLine class.
                You will need to choose a different name for your custom Series<double> object.
                If you are not declaring a custom series... note drawing objects are not series objects and are not used with indexes..
                You will need the drawing object anchors to get the price as shown in post # 2.
                Hi Chelse B. After your recommendation I have tried everything I can to do what you are telling me but I can't figure out how to do it. I have started to study a C# course, to try to understand something since I have no experience in coding, but I still have quite a few chapters to get to the collections. do you think you could guide me a little more on how to get what I ask at the beginning of this thread ? thank you very much.

                the idea is to draw the horizontal lines myself and have my conditions interact with these lines.
                in the screenshot i sent before you can see the way swing interacts as keltner as i expect ( which is possible because it is a plot ) and what i am looking for is to replace the swim indicator with the horizontal lines that i draw daily on the chart.

                thank you very much for your help and patience.

                Translated with DeepL.com (free version)​

                Comment


                  #9
                  Hello micaeliglesias,

                  Attached is an example of looping the DrawObjects collection.
                  DrawObjectsHelpGuideTest_NT8.zip

                  As well as a link to an example where the objects are casted as dynamic to work with assemblies.


                  If you have lines at a slope, you would need to calculate the y-intercept. Below is a link to an example of this.
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  50 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  126 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  69 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  42 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  46 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X