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

How to get the yesterstay close of an instrument on onMarketChange ?

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

    How to get the yesterstay close of an instrument on onMarketChange ?

    Hi all ,
    I am trying to determine the daily variation of and instrument while in onMarketData , is that possible ?
    I tried to use MarketDataType.LastClose to calculate it but it only gives the underlying instrument, I have more instruments added.

    Basically onStateChange in Configure State I am adding DataSeries to receive onMarketData and I want to calculate their daily change like "this stock is 2% and this other one is 1.5%"

    Best,
    Cyrus



    #2
    Hello Cyrus,

    Thank you for your post.

    Yes, you may get the daily variation from OnMarketData(). This has already been done in the indicator "Net Change Display" that comes with NinjaTrader by default. I suggest reviewing the source code for this indicator in the NinjaScript Editor to get a look at how that is achieved. As for a multi-series script, please see the following note from the help guide page for OnMarketData():I suggest adding print statements or checking the Instrument from the MarketDataEventArgs to get a better understanding of which instrument the market data updates are coming through for. Here is a snippet that shows how you would print out the instrument's name the update is for:
    Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {​
    Print("Instrument: " + marketDataUpdate.Instrument.MasterInstrument.Name);
    }
    You could add a condition that checks if the update is for a particular instrument and if marketDataUpdate.MarketDataType == MarketDataType.LastClose and then save the desired value for that particular instrument.

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hi Emily , thanks for the support . That example you suggested had exacly what I was looking for .
      Thank you very much.

      BR

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rhyminkevin, Today, 04:58 PM
      0 responses
      17 views
      0 likes
      Last Post rhyminkevin  
      Started by lightsun47, Today, 03:51 PM
      0 responses
      6 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      14 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      49 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      15 views
      0 likes
      Last Post bltdavid  
      Working...
      X