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

Using TickSize in Draw.Text for Offset

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

    Using TickSize in Draw.Text for Offset

    Dear Support,

    I am converting the following NT7 line code for Draw.Text to NT8.

    Code:
    			Draw.Text(this,CurrentBar.ToString()+"GBTriggerL",true,"B\nt",0,TextAnchorL-SignalLabels.SizeInPoints,0,GBColorL,SignalLabels,TextAlignment.Center,Brushes.Transparent,sigBackColor,sigBackOpacity);
    There is no equivalent in NT8 for extension SignalLables.SizeInPoints in Tools.SimpleFont to insert in the above code.

    Can I instead use 1*TickSize and still get the same results? If not, what is the equivalent to
    SignalLables.SizeInPoints for NT8?

    Many thanks.

    #2
    Hello,

    Thank you for posting.

    I wanted to check the NT7 use here to better understand what may need to be used.

    Was this being used in NT7 for the YPixelOffset to position the text by its own height away from a value or was this being subtracted from a Price supplied to the object? It appears this is the NT8 syntax you have provided, could you provide the NT7 syntax for me to see the use?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for posting.

      I wanted to check the NT7 use here to better understand what may need to be used.

      Was this being used in NT7 for the YPixelOffset to position the text by its own height away from a value or was this being subtracted from a Price supplied to the object? It appears this is the NT8 syntax you have provided, could you provide the NT7 syntax for me to see the use?

      I look forward to being of further assistance.
      Thank you Jesse,

      This is a conversion of the CCI_Forecaster_V7_DE indicator posted in downloads on NT forum.

      The Draw.Text statement is used several time in the original NT7 version for the YPixelOffset to position labels for cci patterns on the indicator. So, I do not think the TickSize would work, that is why I wrote to ask.

      I have attached both the NT7 indicator and the NT8 conversion. I have added "mah" to the conversion name so that it is not mistaken for the original NT7 version.

      Please see an example of the draw text statement on lines 1853 (NT7) and corresponding 1882(NT8).

      p.s. I am also getting error #CS0200 on line 4007 of the NT8 conversion. This line is generated by NT and have no clue what the cause is. This is the only remaining error.
      Attached Files

      Comment


        #4
        Hello,

        I just wanted to reply back on this item.

        It seems that this was a little more complicated than it seemed to measure the text size. Due to how the text is measured/placed on the platform this required a little bit of logic to measure the text object in a similar way to how we do it internally.

        To get the size of a Draw.Text object would require the following logic:


        Code:
        string myText = "Test";
        SimpleFont sf = new SimpleFont("Arial", 26);
        SharpDX.DirectWrite.TextFormat textFormat = sf.ToDirectWriteTextFormat();
        SharpDX.DirectWrite.TextLayout cachedTextLayout = new SharpDX.DirectWrite.TextLayout(Core.Globals.DirectWriteFactory, myText, textFormat, 200, textFormat.FontSize);
         
        //We have to account for padding if we are trying to align the TextBox with pixels..This code taken directly from GetPadding() method of Draw.Text
        float? paddingResource = Application.Current.FindResource("FontModalTitleMargin") as float?;
        float outlinePadding = paddingResource.HasValue ? paddingResource.Value : 3f;
         
        Text textObject = Draw.Text(this,"test",true, myText, 0, 2420, 0, Brushes.Red, sf, TextAlignment.Left, Brushes.Gold, Brushes.Gray, 100);
        textObject.YPixelOffset = 0-(int)((cachedTextLayout.Metrics.Height + (textObject.OutlineStroke.Width) + outlinePadding) / 2);
         
        cachedTextLayout.Dispose();
        textFormat.Dispose();
        This is needed to measure the text and also the outline with padding. Once you have the full-text object, you can use TextLayout to get the texts metrics and offset the YPixelOffset as needed. As far as I can tell, the original indicator uses a static price value, and subtracts the text height from that to place the top of the text at the price value.

        Regarding the error you are getting, that seems to be listing the NinjaScript generated code section if the line noted was 4007. Because I don't have all of the items needed to compile the indicator, it would likely be easiest for you to track down the source of this error.

        I would suggest to comment out all the code in the script including your public properties to leave just a shell of an indicator. Compile and ensure you can compile, then work slowly and uncomment some public properties and recompile. Keep doing this until you have all properties uncommented. If there are no errors, move on to OnBarUpdate and so on until you locate the syntax needed to produce the problem. After doing this, if it is not apparent why the error is coming up, we could look at just that syntax to see why.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rdtdale, Today, 01:02 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by alifarahani, Today, 09:40 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by RookieTrader, Today, 09:37 AM
        4 responses
        18 views
        0 likes
        Last Post RookieTrader  
        Started by PaulMohn, Today, 12:36 PM
        0 responses
        9 views
        0 likes
        Last Post PaulMohn  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        41 views
        0 likes
        Last Post love2code2trade  
        Working...
        X