Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Market Position to draw Horizontal Line - Line not Plotting

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

    Using Market Position to draw Horizontal Line - Line not Plotting

    I am trying to build a strategy that first checks if I am long, and then as soon as I am in a trade takes the current bar low, adds the current ATR value, and then plots this line as a horizontal line. I have tried to do all the calculations within the drawing section of the strategy builder but it did not work. Then I tried to save the value I wanted to plot in a variable and then use the variable as my Y coordinate for the Horizontal line. Still nothing.

    I have a suspicion that my code is not executing when my market position is long. Which is my criteria for the code to execute. Is it the case that simply checking my current market position is not enough to trigger the code? If that is the case is there another way to only execute the code once my market position is no longer flat?

    I also have it set to calculate on each tick

    Any help is much appreciated!!
    Attached Files

    #2
    Hello Jonasdvs12,

    Thanks for your post.

    In the screenshot you shared, the Draw.HorizontalLine() method would be triggered when your strategy is in a long position to draw a horizontal line on the chart.

    Are you calling EnterLong() in your strategy to enter a long position?

    Note that NinjaScript strategies can only see orders placed by that specific instance of the strategy. They cannot see orders placed by other strategies or see manually placed orders.

    Ultimately, to understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121​​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi Brandon, Thank you for the quick reply. I realize I wasn't very clear in my original post so I apologize about that. My ultimate goal is to just have an indicator that plots these ATR levels when I am in a trade. I was using the strategy builder to create the outline for my code that I would turn into an indicator. That is why I am not interested in the strategy entering positions, only in the drawing being plotted. And I think I understand the problem why the drawing wasn't being plotted in my tests. In my tests, I was simply entering by the market and not by any strategy logic which probably tripped up the code.
      My question then is: how can I plot the horizontal lines only when I am in a trade that was entered by me on limit or market orders? Or is that not possible?

      Comment


        #4
        Hello Jonasdvs12,

        Thanks for your notes.

        The Position.MarketPosition condition would only be usable in a NinjaScript strategy, not a NinjaScript indicator, to check if the strategy position is Long, Short, or Flat.

        As we can see in the help guide link below, the Position.MarketPosition documentation is located in the Strategy section of the help guide.

        Position.MarketPosition: https://ninjatrader.com/support/help...etposition.htm

        Since the Position class is only for NinjaScript strategies, you would first need to create the framework of your NinjaScript indicator script.

        To create a NinjaScript indicator, open a New > NinjaScript Editor window, select the '+' tab at the bottom of the Editor window, select 'New Indicator'. Then, you could set up as much of the indicator as possible in the Indicator Builder. This will create the framework of the indicator or strategy

        If you need Account related information in an indicator you must set up the Account object within the indicator like in the example here:
        https://ninjatrader.com/support/help...ount_class.htm

        Once the account object is initialized, you can access the account positions through the Positions collection that the Account object has.

        I also found this full example for NinjaTrader 8 which you might find helpful:
        https://ninjatraderecosystem.com/use...lay-indicator/
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        62 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        134 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X