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

trying to learn SharpDX but having problems with doubles in itterations

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

    trying to learn SharpDX but having problems with doubles in itterations

    i'm attempting to add SharpDX labels to the margin for the 4 plots of the PriorOHLC.cs indicator
    i think i've got the drawing part down but for some reason i can't get my iterative doubles in place for use to convert to Y pixel level for the plotLabels positioning during OnBarClose calculations... it works fine with OnPriceChange calcs but i want to use less processor cycles and am trying to make an indicator that works with OnBarClose calcs...

    and i've tried Values[i].IsValidDataPointAt(Count-1)
    but it seems after adding all the Print() calls that Values[i] just isn't carrying a double number during Calculations.OnBarClose. i don't, yet, understand sessionIterator. commands yet and am wondering if that somehow effects bar indexing but don't see how it would.

    (DXplottingTroubles2.cs attached)
    thx
    Attached Files
    Last edited by stafe; 09-10-2023, 03:48 PM.

    #2
    Hello stafe,

    Thanks for your post.

    On line 153 in your script, you should print out the value to the Output window so you can see the actual value being printed. For example, change Values[i] to Values[i][0].

    Code:
    for (int i = 0; i < Values.Length; i++)
    { Print("Values[i] are    " + Values[i][0]); }    /// needs to return currentOpen,High,Low,Close Values
    ​
    ​​

    To have the script work while using Calculate.OnBarClose, you could use CurrentBar - 1 instead of Count - 1 on lines 190, 192, and 194. For example, see below.

    Code:
    for (int i = 0; i < Values.Length; i++)     /// this loop is working
    {
    
        Print("Values[i] is        " + Values[i].GetValueAt(CurrentBar - 1) );      /// this call is not
    
        if (Values[i].IsValidDataPointAt(CurrentBar - 1) && firstLoop && ShowLabels)    /// nor is this call
        {
            double plotValue = Values[i].GetValueAt(CurrentBar - 1);
            float chartScaleYValue = chartScale.GetYByValue(plotValue);
            plotLabels[i]             = Plots[i].Name;
            brushesDX[i]                 = Plots[i].BrushDX;
    
                Print("Current Bar is        " + CurrentBar);                    
                Print(" plotValue is        " + plotValue);
                Print(" startX is            " + startX);
                Print(" endX is                " + endX );
                Print(" chartScaleYValue is    " + chartScaleYValue );    
    
             textStartDX = new SharpDX.Vector2( (float)startX, (float)(chartScaleYValue - textFontSize/2) );
    
                 Print("textStartDX is        " + textStartDX);
                 Print("plot name is            " + plotLabels[i]);
                 Print("plots brush is        " + brushesDX[i]);
    
             TextLayout textLayout = new TextLayout(Globals.DirectWriteFactory, plotLabels[i], textFormat, (float)ChartPanel.W - startX, textFontSize);
                        RenderTarget.DrawTextLayout(textStartDX, textLayout , brushesDX[i]);
    
             textLayout.Dispose();
    
        }
    }
    ​When making these changes I am seeing the plot labels drawn on the chart when using either Calculate.OnBarClose or Calculate.OnPriceChange.
    Last edited by NinjaTrader_BrandonH; 09-10-2023, 05:40 PM.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      thanks for getting back Brandon, i'll make those changes later this evening... while you were writing i was trying to check out VisualStudio for editing and debugging but when i open this file i get all kinds of crazy errors even after attaching to the NT process... there's a warning at the top of the edit window that says to make adjustments in configuration manager and a box to click to open the manager but button doesn't open it and i can't seem to find the icon MS is talking about to open it... do i need to do anything further to settle all the errors ?

      Comment


        #4
        Hello stafe,

        Thanks for your notes.

        To start off visual studio is used only as a text editor when using it with NinjaTrader, that means it cannot be used to compile or build as you will see errors. NinjaTrader needs to do the build from the NinjaScript editor, the same goes for any changes like adding files or adding references, those need to be done in the NinjaScript editor. Visual studio will ask you to update when changes occur, always press reload project.

        The following page contains the steps to attach the debugger, that is a complete guide and would be how to use visual studio for debugging NinjaScript files. https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?visual_studio_debugg ing.htm

        You would always need to compile with the NinjaScript editor, visual studio is just used for debugging/editing purposes in this use case. If you compile from visual studio that will generate errors. Further, you can't build from VS. VS will also show a lot of warnings which are not relevant, you can turn off warnings

        If no compile errors appear in the NinjaScript Editor then your script does not have compilation errors.​​
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          i've really hit my limit here...
          i made the changes from Count-1 to CurrentBar-1 and got the plot names working... But then, because of the indicator i'm trying to rebuild, i opened up an output window to look at things more closely in regards to wasted processor cycles. What appears to be happening, please correct me if i'm wrong, is that the OnRender section loops continuously regardless. I've tried everything i can think of to stop it but that is interfering with the "constancy" of the plot names in the margin. The plot names appear at the FirstTickOfBar and then disappear on the 2nd tick. (i'm using a 1min chart in this instance)
          so, 2 questions
          1) how can i get the OnRender section to not continuously loop (note the output window)
          2) how to get the plot names to be constant in the margin and is SharpDX the only way to plot text in the chart margin at an AddPlot level (x/y or price) ?

          i've used IsFirstTickOfBar liberally in the current version but was using it more sparingly with little success in prior versions to get some control on unnecessary repetitive calculation cycles and that's what's uncovered, for me, the idea that OnRender constantly refreshes or something. I'm counting upwards of 70 cycles in a 1min bar when the "everything" is set to OnBarClose and IsFirstTickOfBar is spread like mustard over the whole sandwich... yep, i'm pulling my hair out... /w

          totally forgot to address my hopes with this indicator: for it to process the prior day open, high, low, close values like it does and run a text plot to print the plot labels in the margin at their respective price levels - i'll be adding multiples of other levels based on CurrentBar-1 logic and making them disappear based on the same logic but still only using the prior days OHLC but because of the added levels i'm hoping to keep the processor overhead to a minimum.
          Attached Files
          Last edited by stafe; 09-11-2023, 11:17 PM.

          Comment


            #6
            Hello stafe,

            Thanks for your notes.

            The OnRender() method used to render custom drawing to a chart from various chart objects frequently runs once the State has reached State.Realtime in response to market data updates or a user interacting with the chart (e.g., clicking, resizing, rescaling, etc.)

            This means that anytime the chart is clicked, resized, rescaled, or market data updates on the chart the OnRender() method will trigger. There are no means for preventing OnRender() from being triggered.

            See this help guide page for more information about OnRender(): https://ninjatrader.com/support/help...8/onrender.htm

            After making the changes to the indicator mentioned on post 2 to the code you shared in post # 1, I am seeing the plots on the chart and the custom rendered SharpDX labels consistently placed on the chart. When a new bar is formed, the plots and custom rendered labels remain on the chart.

            See this demonstration video: https://brandonh-ninjatrader.tinytak...NV8yMjA2MTQ1Mw

            I attached the script to this post so you could review it.

            Attached Files
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              i'm glad i wasn't imagining things due to some code issue on my end - thanks for clarifying OnRender updates on market data events and user chart manipulations. That explains why the indicator i was using previously to plot levels based on the prior day was using so many processor clicks - it's level's lines were plotted using SharpDX as well as its labels. I'll build it out using base.OnRender for the lines and DX for the labels and see what my resource savings are at that point - i run a copy on 7 charts... LOL thanks for your assistance with this !!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by JoMoon2024, Today, 06:56 AM
              0 responses
              6 views
              0 likes
              Last Post JoMoon2024  
              Started by Haiasi, 04-25-2024, 06:53 PM
              2 responses
              17 views
              0 likes
              Last Post Massinisa  
              Started by Creamers, Today, 05:32 AM
              0 responses
              5 views
              0 likes
              Last Post Creamers  
              Started by Segwin, 05-07-2018, 02:15 PM
              12 responses
              1,786 views
              0 likes
              Last Post Leafcutter  
              Started by poplagelu, Today, 05:00 AM
              0 responses
              3 views
              0 likes
              Last Post poplagelu  
              Working...
              X