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

newbie questions ........ printing tick data to outputbox

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

    newbie questions ........ printing tick data to outputbox

    I'm trying to print tick data on outputbox, in format {Date/Time,Bid,Ask,Last,Volume}

    there are no errors when compiling, but the ouputbox show nothing when i run it,

    here is the code,


    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    int i = 0 ;
    if( BarsInProgress == i )
    {
    DateTime currentDateTime = Time[i];
    //if( CheckRecordDateTime( currentDateTime ))
    //{
    Print( Time[i].ToString("yyyy-MM-dd HH:mm:ss") + " " +
    "[" + i + "-Bid] " + MarketDataType.Bid + " , " +
    "[" + i + "-Ask] " + MarketDataType.Ask + " , " +
    "[" + i + "-Last] " + MarketDataType.Last + " , " +
    "[" + i + "-Volume] " + Volume );
    //}
    }

    }




    thanks in advance

    #2
    Hello Adam181527,
    Thanks for writing in and I am happy to assist you.

    OnMarketData is a real-time data stream and to exploit it to its best please use the MarketDataEventArgs. The MarketDataEventArgs contains all the price information.
    For example e.Time will return you the time value, e.Price will return you the price etc.
    A basic snippet will be like

    Code:
    if (e.MarketDataType == MarketDataType.Bid)
    	Print(e.Time.ToString() + " Bid price " + e.Price.ToString() + " Bid volume " + e.Volume.ToString());	
    else if (e.MarketDataType == MarketDataType.Ask)
    	Print(e.Time.ToString() + " Ask price " + e.Price.ToString() + " Ask volume " + e.Volume.ToString());
    else if (e.MarketDataType == MarketDataType.Last)
    	Print(e.Time.ToString() + " Last price " + e.Price.ToString() + " Last volume " + e.Volume.ToString());
    For better understating on how OnMarketData works please refer here http://www.ninjatrader.com/support/h...marketdata.htm

    You can also use the code to get the information you are trying to get
    Code:
    Print("Date " + Time[0].ToString("yyyyMMdd HH:mm:ss") + " Bid: " + GetCurrentBid().ToString() + " Ask: " + GetCurrentAsk().ToString() + " Last: " + Close[0].ToString() + " Volume: " + Volume[0].ToString());
    The above code can be accessed from OnBarUpdate.

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      hi Joy,

      i tried the latter of your advice, but still nth in output box windows,
      but it show

      "**NT** Enabling NinjaScript strategy 'TickSaver/96b1c3adb4124ca0afa2ec3c19998ec4' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes"

      I have to admit I'm very new to programming......

      thanks,

      ad

      Comment


        #4
        Hello adam081527,
        The message is just to let you know that the strategy is being enabled.

        The output will have the print outs when you enable and disable a strategy.

        Please go through the help file tutorials to get the basic ideas on NinjaScript http://www.ninjatrader.com/support/h..._resources.htm
        Also please do see this video tutorial on Strategy development via the strategy wizard http://www.youtube.com/watch?v=fVFqw...G0IuPM3sjVBRyC

        Please let me know if I can assist you any further.

        Originally posted by adam081527 View Post
        hi Joy,

        i tried the latter of your advice, but still nth in output box windows,
        but it show

        "**NT** Enabling NinjaScript strategy 'TickSaver/96b1c3adb4124ca0afa2ec3c19998ec4' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes"

        I have to admit I'm very new to programming......

        thanks,

        ad
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Joydeep View Post
          Hello adam081527,
          The message is just to let you know that the strategy is being enabled.

          The output will have the print outs when you enable and disable a strategy.

          Please go through the help file tutorials to get the basic ideas on NinjaScript http://www.ninjatrader.com/support/h..._resources.htm
          Also please do see this video tutorial on Strategy development via the strategy wizard http://www.youtube.com/watch?v=fVFqw...G0IuPM3sjVBRyC

          Please let me know if I can assist you any further.
          hi Joydeep,

          much appreciate for your help, i finally solve it, but just one more thing,

          with OnBarUpdate,
          Print("Date " + Time[0].ToString("yyyyMMdd HH:mm:ss") + " Bid: " + GetCurrentBid().ToString() + " Ask: " + GetCurrentAsk().ToString() + " Last: " + Close[0].ToString() + " Volume: " + Volume[0].ToString());

          above code will print data to the output windows only when there is a new trade, how should i change the code if i want to print also bid and ask changes (but no trade)??

          Comment


            #6
            Hello adam081527,
            You can call the OnMarketData event to get the bid ask changes.

            Please refer to here for more details


            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by funk10101, Yesterday, 09:43 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by TheWhiteDragon, 01-21-2019, 12:44 PM
            5 responses
            551 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by rtwave, 04-12-2024, 09:30 AM
            5 responses
            37 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by funk10101, Today, 12:02 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by GLFX005, Today, 03:23 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X