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

SharpDX Bar[0] Remove Not True Object

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

    SharpDX Bar[0] Remove Not True Object

    Hello,
    I'm trying to get a dot to plot when the statement is true on Bar[0], but I don't understand how to remove the plot when the statement becomes NOT true on Bar[0].
    I've tried a few different ways and it comes close sometimes (85-90% of the bars are correct).

    Could someone explain in simple terms (I'm not a programmer but more of a copy-and-paste programmer) how to remove an object when on Bar[0] becomes NOT true?

    Thank you for your time and expertise.
    James

    #2
    Hello James,

    Thanks for your post

    Could you please clarify exactly what you are trying to accomplish so we may accurately assist.

    Are you trying to only custom render an ellipse on the chart when a certain condition is true?
    .
    You could consider calling the RenderTarget.DrawEllipse() method within your condition so it is only custom rendered when the condition is true.

    That way when the condition is not true, the ellipse would not be custom-rendered on the chart.

    RenderTarget.DrawEllipse(): https://ninjatrader.com/support/help...rawellipse.htm

    Using SharpDX for Custom Chart Rendering: https://ninjatrader.com/support/help..._rendering.htm

    Please share the code in question so we may see how you are custom rendering the object on the chart.

    To export a script, go to Tools > Export > NinjaScript AddOn.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Brandon for your quick reply.
      I guess where I'm confused is when on bar zero the statement might become true and then turn false many times. So, the object would plot and then be removed multiple times during the same bar. I used the remove object with regular objects but I am not sure how this is done with SharpDX or if it is even needed.
      Thanks again for your help.
      James


      if ( ( Gom1.NbBuyImbalances.GetValueAt( Gom1.NbBuyImbalances.Count - 1 ) >= NbAbsImb )
      && (! ( Gom1.NbBuyImbalances.GetValueAt( Gom1.NbBuyImbalances.Count - 1 ) < NbAbsImb )) )

      {
      SharpDX.Vector2 []tr= new SharpDX.Vector2[ 3];

      float xCoord1 = chartControl.GetXByBarIndex( ChartBars, totalBars - 1 );
      float yCoord1 = chartScale.GetYByValue( ( ChartBars.Bars.GetHigh( totalBars-1) + ChartBars.Bars.GetLow( totalBars - 1)) / 2);

      tr[ 0] = new SharpDX.Vector2( xCoord1 - absSize, yCoord1 + absSize);
      tr[ 1] = new SharpDX.Vector2( xCoord1 + absSize, yCoord1 + absSize);
      tr[ 2] = new SharpDX.Vector2( xCoord1, yCoord1);

      DXH.FillGeometry(RenderTarget, tr, "OfabColor");
      DXH.DrawGeometry(RenderTarget, tr, "OfabsBColor", 1, DashStyleHelper.Solid);​

      Comment


        #4
        Hello James,

        Thanks for your notes.

        You could consider using a bool to only render the object on the chart when the bool is true. That way when the bool is false the object is not rendered on the chart.

        OnRender() runs on every render pass and draws what the logic says to draw on that pass. This means that if the bool is false on a render pass, the object would not be rendered on the chart.

        Are you setting a value from OnBarUpdate() and doing all logic in OnBarUpdate()? If so, are you using Calculate.OnEachTick in your script?

        If so, this could cause the logic to change back and forth from true to false depending on whether the condition is true on one incoming tick but false on the next incoming tick.

        You could consider updating the bool on IsFirstTickOfBar so that the bool is only set once at the first tick of a new bar.

        IsFirstTickOfBar: https://ninjatrader.com/support/help...ttickofbar.htm

        If the logic is not behaving as expected you could add debugging prints to the script to understand exactly how your logic is behaving in the script.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.


        OnRender(): https://ninjatrader.com/support/help...8/onrender.htm
        Using SharpDX for Custom Chart Rendering: https://ninjatrader.com/support/help...ing.htm​
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Good morning Brandon.
          Thanks again for the clarification. I am setting the value OnBarUpdate and doing all logic OnBarUpdate. I am running the indicator OnEachTick.
          I am looking for the object to plot if the incoming tick is true and not plot on the next incoming tick if is false.
          So, if I'm understanding you correctly with each tick the object is rendered or not. So, there is no need to remove like with regular objects.
          I will try implementing a bool like you suggested to narrow things down.
          Thank you very much for your time.
          James

          Comment


            #6
            Good morning Brandon.
            Thanks again for your suggestions. Even if I use the bool, there is still something off. I took the bool back out for the moment.
            The objects plot all correctly when you reload the data, but on the Bar[0] it is often correct, but then it will not be correct. It seems random. I looked over the use of prints to debug but I'm having trouble understanding how to do that on a tick-by-tick basis. Do you have any suggestions for debugging bar[0]? I will post the code file if you are willing to look.
            Attached Files

            Comment


              #7
              Hello laoshr,

              If there is a lot of output, you can write to a text file instead using a C# StreamWriter.

              Below is a link to the reference sample which demonstrates.



              You will want to print the value being assigned in OnBarUpdate(), and print the values in the condition that calls the draw methods in OnRender().
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello,
                I have been trying to get a rectangle to plot on the POC of the current bar in progress. The code below works but the value doesn't update correctly sometimes on bar[0]. I've read that the bar[0] isn't the same as the index bars. So, I'm trying to use bar[0] in the second code below but can't seem to get anything to plot. Am I missing something?

                This code plots but is sometimes incorrect, especially if the price moves fast.

                for( int i = ChartBars.FromIndex ; i <= ChartBars.ToIndex; i++){
                if ( showPOC == true )

                {
                DXH.FillRectangle( RenderTarget, chartControl.GetXByBarIndex( ChartBars, i ), chartScale.GetYByValue(Gom1.POCPrice.GetValueAt( i) + (0.3 * TickSize)), tickLength, 2 * chartScale.GetPixelsForDistance( 0.3 * TickSize), "HvPocColor");
                DXH.DrawRectangle( RenderTarget, chartControl.GetXByBarIndex( ChartBars, i ), chartScale.GetYByValue(Gom1.POCPrice.GetValueAt( i) + (0.3 * TickSize)), tickLength, 2 * chartScale.GetPixelsForDistance( 0.3 * TickSize), "HvPocBColor", 1, DashStyleHelper.Solid);

                }
                }

                This is what I'm trying to get to plot:

                for( int i = ChartBars.FromIndex ; i <= ChartBars.ToIndex; i++){


                if( showPOC == true)

                //Gom1.PocVolume[0] >= ( ofhv) )

                {
                //Draw.Rectangle(this, "poc", false, 0, (Gom1.POCPrice[0] + (0.3 * TickSize)), 0, (Gom1.POCPrice[0] - (0.3 * TickSize)), pocborderColor, hvpocColor, hvpopacity);
                DXH.FillRectangle( RenderTarget, chartControl.GetXByBarIndex( ChartBars, totalBars ), chartScale.GetYByValue( curPOC + (0.3 * TickSize)), chartScale.GetYByValue( curPOC - (0.3 * TickSize)), 2 * chartScale.GetPixelsForDistance( 0.3 * TickSize), "HvPocColor");
                DXH.DrawRectangle( RenderTarget, chartControl.GetXByBarIndex( ChartBars, totalBars ), chartScale.GetYByValue( curPOC + (0.3 * TickSize)), chartScale.GetYByValue( curPOC - (0.3 * TickSize)), 2 * chartScale.GetPixelsForDistance( 0.3 * TickSize), "PocBColor", 1, DashStyleHelper.Solid);
                }
                }

                Any help would be greatly appreciated. Thank you for your time.
                James​​

                Comment


                  #9
                  Hello James,

                  Thanks for your notes.

                  When you mention "bar[0]" are you referring to the current bar on the chart?

                  Note that bar indexes should be used when custom rendering objects on a chart. Bar indexes are not the same as BarsAgo.

                  Bars.GetBar() could be used to get the bar index matching the time stamp of the "time" parameter provided.

                  For example, Bars.GetBar(Time[0]) would return the bar index of the current bar on the chart.

                  Bars.GetBar(): https://ninjatrader.com/support/help...nt8/getbar.htm

                  CharBars.ToIndex could be used to get the bar index of the last bar rendered on the chart.

                  ChartBars.ToIndex: https://ninjatrader.com/support/help...rs_toindex.htm

                  Further, it is necessary to add debugging prints to the script that prints out all the logic being used to render the object on the chart to understand exactly how the logic in the script is behaving.

                  Did you add debugging prints to the script to see how exactly the logic is behaving?

                  What line of code is behaving incorrectly in the prints you observed?

                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    Brandon,
                    Thank you for your reply. Yes, I'm referring to the current bar. I've been working on the debugging prints. They are a bit messy because the value changes quite a bit on bar[0]. Once I have observed the prints I'll try and figure out what is going on.
                    Thank you again for all your time.
                    James

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by fx.practic, 10-15-2013, 12:53 AM
                    5 responses
                    5,406 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by Shai Samuel, 07-02-2022, 02:46 PM
                    4 responses
                    98 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by DJ888, Yesterday, 10:57 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by MacDad, 02-25-2024, 11:48 PM
                    7 responses
                    160 views
                    0 likes
                    Last Post loganjarosz123  
                    Started by Belfortbucks, Yesterday, 09:29 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post Belfortbucks  
                    Working...
                    X