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

Simple Price and Spead Indicator

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

    Simple Price and Spead Indicator

    Hello everyone, I couldn't find this simple indicator anywhere, so I figured I create it for myself. I just wanted to create a simple indicator that displays price and spread on the chart. I trade forex and my broker is a five digit broker. The price code is quite simple, it's

    double price = GetCurrentBid();

    When I display it on my chart, it displays but for example if price is 1.83700 it will display price as 1.837.

    1. How do I keep the price as a 5 digit number?
    2. On the weekend, the price doesn't display because I guess it can't get a value because the market is closed. Is there a way to display the last price?
    3. I only trade forex, for now, but I can I plan on trading futures. Is the spread on the ES, for example, the same as forex, ask-bid?

    Thank you for taking the time out to read this. Hopefully someone could help me. I haven't really programmed in over 10 years so I'm kind of rusty.

    #2
    Hello Johncolavito,

    Thank you for your post.

    I would try Math.Round(double, int32)

    Code:
    Math.Round(Close[0], 5);
    Unless, there is real time data coming in, Close[0] will bring up the last traded price.

    Yes, this is how spread is calculated.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I apologize for the delay in response. I tried it today after the market opened. It doesn't update until it receives tick data. However, I tried what was recommended and unfortunately, it didn't work. I am a beginner when it comes to c# but here is the code I tried. I'm sure i'm coding it wrong.

      DrawTextFixed("price", (Math.Round(price,5).ToString()),TextPosition.TopR ight, Color.White, new Font("Arial", 18), Color.Transparent, Color.Empty, 3);

      Comment


        #4
        John, thanks for the reply. For the formatting you could force certain formattings through the ToString() method directly - http://www.ninjatrader.com/support/f...ead.php?t=3823

        i.e. for your case try working with -

        DrawTextFixed("price", (Math.Round(price,5).ToString("N5")),TextPosition.TopRight, Color.White, new Font("Arial", 18), Color.Transparent, Color.Empty, 3);
        BertrandNinjaTrader Customer Service

        Comment


          #5
          That worked perfectly! Thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GwFutures1988, Today, 02:48 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by ScottWalsh, 04-16-2024, 04:29 PM
          6 responses
          30 views
          0 likes
          Last Post ScottWalsh  
          Started by frankthearm, Today, 09:08 AM
          10 responses
          36 views
          0 likes
          Last Post frankthearm  
          Started by mmenigma, Today, 02:22 PM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by NRITV, Today, 01:15 PM
          2 responses
          9 views
          0 likes
          Last Post NRITV
          by NRITV
           
          Working...
          X