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

Draw Text-Price

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

    Draw Text-Price

    I am trying to create an indicator that will draw the price at the time of an action, for example a MACD cross. I am stuck with the price that is being drawn the bar close price, vs the price of the actual cross. Is this doable?

    Here is what I came up with:

    Code:
    if (MACD1.Default[0] > 0)
                    {
                    
    
                    Draw.Text(this,"test"+CurrentBar , Close[0].ToString(), 0,Low[0]- 2);
                }

    #2
    Hello lenmat,

    Thank you for your note.

    So I may best answer your question, would you please provide more detail on what you mean by the price of the cross? Are you looking for the indicator values?

    Are you looking for the price at the exact moment of a cross, rather than the close?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Good Morning Alan,

      Yes, I am looking to draw the price of the ES at the exact moment of a cross, and stay on the chart at that price.

      Right now it will draw that price when the cross happens, but it will change throughout the bar until it closes, leaving the bar close price.

      Thanks for the help!

      Comment


        #4
        Hello lenmat,

        You would run the indicator with calculate set to OnEachTick or OnPriceChange. This will cause the indicator to update in real time, and the moment the condition becomes true, Close[0], will equal that price at that time.

        To prevent Close[0] from changing, you would want a bool which only ran once per bar and was triggered the moment the condition became true.

        An example of this,

        Code:
        bool doOncePerBar=false;
        		
        protected override void OnBarUpdate()
        {
        		
        	if (IsFirstTickOfBar)
        	{
        		doOncePerBar=false;
        	}
        		
        	if (MACD(10,20,5).Default[0] > 0 && doOncePerBar== false)
                {
                        
        		doOncePerBar=true;
                        Draw.Text(this,"test"+CurrentBar , Close[0].ToString(), 0,Low[0]- 2);
                }
        			
        }
        You should consider, that on the same bar when your condition becomes true, price reverses, the condition is no longer true on bar close, but you'll have text on the chart.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Alan,

          This is working in real time. Do you know a way to get it to work on history? Lets say I load a new chart with 30 days of data, all the prices that are drawn are at the bar close. Thoughts?

          Comment


            #6
            Hello lenmat,

            This works in real time because it has incoming tick data, and the tick the condition it becomes true, the bool and value is saved. To have this work historically you would have to add a secondary tick series.

            Below is an example of how you could accomplish this.
            You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by PhillT, Today, 02:16 PM
            2 responses
            6 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Started by Kaledus, Today, 01:29 PM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frankthearm, Yesterday, 09:08 AM
            14 responses
            47 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by gentlebenthebear, Today, 01:30 AM
            2 responses
            14 views
            0 likes
            Last Post gentlebenthebear  
            Started by PaulMohn, Today, 12:36 PM
            2 responses
            17 views
            0 likes
            Last Post PaulMohn  
            Working...
            X