• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry Order in OnMarketData?

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

    Entry Order in OnMarketData?

    Hi everyone, first of all to congratulate the team of nt8 developers by the great software developed

    The other day try to develop a strategy with ATM entries inside the OnMarketData function,

    Can I entry order with ATM for example at 8:30:30 seconds in last price with compare ask?

    I have had problems to executing this command and I think that error is because I can´t enter different time frames... only when barclose? Probably i need change my CalculateOnBarClose to false?

    Is this a configuration general variable for my strategy?

    Is it possible to make entry order ATM tick a tick and control this order in OnMarketData LastPrice?

    On the other hand I have detected that the ondatadataprocess is executed 2 times, does anyone know why it can be?

    Thank you very much greetings
    Last edited by Alvarheras; 08-29-2017, 02:34 AM.

    #2
    Hello Alvarheras,

    Thanks for opening the thread.

    There wouldn't be anything stopping you from entering an ATM strategy with AtmStrategyCreate() in OnMarketData(). As we can observe with a print for marketDataUpdate.ToString(), we have prints with the following information updated in realtime:

    instrument='ES 09-17 Globex' type=Last price=2577.5 volume=77 time='8/29/2017 7:20:19 AM' bid=2577.5 ask=2577.75 isReset=False
    Bid Ask and Last prices are updated in realtime, and could drive your logic for comparing the last to the ask price.

    If you are having issues with the entry, I would suggest to break the strategy done so it 1st immediately enters the ATM strategy, and then to place your entry logic around this code. If you then encounter issues with entering, we will know that there is a certain aspect of the logic that is preventing entry.

    For example, using ToTime() and a Times object will yield the time of that bar close.

    You can use this piece of code from SampleAtmStrategy to test immediate entries in OnMarketData():
    Code:
    isAtmStrategyCreated = false;  // reset atm strategy created check to false
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low.GetValueAt(0), 0, TimeInForce.Day, orderId, "ATM 1", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => { 
    	//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
    	if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId) 
    		isAtmStrategyCreated = true;
    });
    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim
      As you say the use of toTime allows me to manage the time to filter.

      What I want is to enter when a condition such as:

      If (e.MarketDataType == MarketDataType.Last)
      {
      If (e.Price> = e.Ask)
      {
      }
      }
      Thus giving the condition that I am entering a certain tick

      Right now I throw a bar error that I can solve by removing my entry from there to a fragment of time like 9:00 or 9:01
      Entering it inside

      if (BarsInProgress == 0)
      It may have to do with the configuration of variables of my system? specifying with this?

      Calculate = Calculate.OnBarClose;
      Thanks greetings

      Comment


        #4
        Hello Alvarheras,

        BarsInProgress and Calculate.OnBarClose are specific for OnBarUpdate() and would not have an effect on how OnMarketData() updates. Are you trying to use OnMarketData for order submission or OnBarUpdate?

        What is the error you are receiving?

        Without the code I cannot provide more detail on the issue is you are running into.

        I have created a demonstration video showing how I copied the code from the SampleAtmStrategy example, and placed it in OnMarketData() to see fills on the Simulated Data Feed. I do not see any errors when doing this. I would suggest to perform the same test I have and then add additional logic to control the entry. This way you can have a good starting point to troubleshoot and debug your logic further.

        Demo: https://www.screencast.com/t/4taxlb1lVbCd

        I've included a link on debugging as well: http://ninjatrader.com/support/forum...ead.php?t=3418

        Please let me know if you see any error when performing the same test I have linked above.
        JimNinjaTrader Customer Service

        Comment


          #5
          I am trying to use OnMarketData for order submission. For example :

          Code:
          If (e.MarketDataType == MarketDataType.Last)
          {
              If (e.Price> = e.Ask)
              {
                    if(e.Price == 3000){
                  isAtmStrategyCreated = false;  // reset atm strategy created check to false
          atmStrategyId = GetAtmStrategyUniqueId();
          orderId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low.GetValueAt(0), 0, TimeInForce.Day, orderId, "ATM 1", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => { 
          	//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
          	if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId) 
          		isAtmStrategyCreated = true;
          });
          
                   }
              }
          }
          This Code Print error relacioned withs bars.


          Solution the error this code:

          Code:
          If (e.MarketDataType == MarketDataType.Last)
          {
              If (e.Price> = e.Ask)
              {
                   if(e.Price == 3000){
                          varibleBool = true
                    }
              }
          }
          
          if(ToTime[0] == 10000 && varibleBool == true)
          {
          
            isAtmStrategyCreated = false;  // reset atm strategy created check to false
          atmStrategyId = GetAtmStrategyUniqueId();
          orderId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low.GetValueAt(0), 0, TimeInForce.Day, orderId, "ATM 1", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => { 
          	//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
          	if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId) {
          		isAtmStrategyCreated = true;
                          varibleBool = false;
                 }
          });
          
          
          }

          When order submission is in Time when finish minute i can entry but when the submission is in the middle of Onmarketdata this return me error.

          If you have more doubt you tell me

          Thax
          Last edited by Alvarheras; 08-29-2017, 10:24 PM.

          Comment


            #6
            Hello Alvarheras,

            Thanks for writing back and providing additional detail.

            I still have some confusion surrounding your inquiry.

            When I test the first code snippet where you mention you get an error, I do not receive an error and my ATM strategy "ATM 1" is created on each incoming tick as expected. What is the error you are receiving?

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

            Comment


              #7
              Hello
              Yes it's correct. I was able to enter ATM into onmarketdata

              Right now I'm experiencing another problem

              I have detected that when I execute a code inside the if of the following code, it is running 2 times.

              If I make a Print to show the result I always get double results of 2 in 2

              What can be caused this? I am in MarketReplay with Playback Connection and my code onmarketdata is for example:

              If (e.MarketDataType == MarketDataType.Last)
              {
              If (e.Price> = e.Ask)
              {
              Print("example");
              }
              }
              My configuration:


              IsFillLimitOnTouch = false;
              MaximumBarsLookBack =MaximumBarsLookBack.TwoHundredFiftySix;
              OrderFillResolution = OrderFillResolution.Standard;
              Slippage = 0;
              StartBehavior = StartBehavior.WaitUntilFlat;
              TimeInForce = TimeInForce.Gtc;
              TraceOrders = false;
              RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
              StopTargetHandling = StopTargetHandling.PerEntryExecution;
              BarsRequiredToTrade = 20;
              Thax for your help jim

              Comment


                #8
                Hello Alvarheras,

                It would simply be that there were multiple ticks within a short period of time in which those conditions became true.

                Attached is a demo running the code on Market Replay data with prints placed within the if statement and outside the if statement and counting how many times those prints occur.

                Demo: https://www.screencast.com/t/vkVb3i9Wpm

                Please let me know if I can be of further assistance.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ralett, Today, 11:52 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_PatrickG  
                Started by rtwave, Yesterday, 07:06 PM
                1 response
                22 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Started by DTSSTS, Today, 11:27 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by siroya, Today, 10:02 AM
                2 responses
                9 views
                0 likes
                Last Post DTSSTS
                by DTSSTS
                 
                Started by pjsmith, Today, 10:50 AM
                0 responses
                9 views
                0 likes
                Last Post pjsmith
                by pjsmith
                 
                Working...
                X