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

Having an issue extracting atm strategy name from chart trader.

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

    Having an issue extracting atm strategy name from chart trader.

    I am having an issue extracting the atm strategy name from the chart trader. I know I can make my own listbox in the parameter listing, but I want to extract it from the chart trader instead of opening it everytime. How od Iget the contract quantity and the strategy name in order to create my order?



    int nContractQuantity = 0;
    string AtmStrategyName1 = "";
    ChartControl.Dispatcher.InvokeAsync((Action)(() =>
    {
    NinjaTrader.Gui.Tools.QuantityUpDown
    quantitySelector = (Window.GetWindow(ChartControl.Parent).FindFirst(" ChartTraderControlQuantitySelector") as NinjaTrader.Gui.Tools.QuantityUpDown);
    nContractQuantity = quantitySelector.Value;
    Print("Contract quantity is : "+ nContractQuantity.ToString());
    }));

    ChartControl.Dispatcher.InvokeAsync((Action)(() =>
    {
    NinjaTrader.Gui.NinjaScript.AtmStrategy.AtmStrateg ySelector selector = (Window.GetWindow(ChartControl.Parent).FindFirst(" ChartTraderControlATMStrategySelector") as NinjaTrader.Gui.NinjaScript.AtmStrategy.AtmStrateg ySelector);
    AtmStrategyName1 = selector.SelectedAtmStrategy.ToString();
    Print("ATMStrategyName is : "+ selector.SelectedAtmStrategy.ToString());
    }));

    ChartControl.InvalidateVisual();


    TriggerCustomEvent(o =>
    {
    Order stopOrder = null;

    stopOrder = myAccount.CreateOrder(Instrument,
    OrderAction.Buy,
    OrderType.StopMarket,
    TimeInForce.Day,
    nContractQuantity,
    0,
    0,
    string.Empty,
    "Entry",
    null);

    // Submits our entry order with the ATM strategy named "myAtmStrategyName"
    NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(AtmStrategyName1, stopOrder);
    myAccount.Submit(new[] { stopOrder });
    }, null);

    nTradeType = 2;
    Draw.TextFixed(this, "TradeType", "Buy Activated", TextPosition.BottomLeft);
    }

    #2
    Hello ballboy11,

    Thanks for your post.

    This isn't documented, but I think it would be easiest to access it from ChartControl.OwnerChart.ChartTrader.

    I.E.

    Code:
    ChartControl.Dispatcher.InvokeAsync((Action)(() =>
    {
        Print(ChartControl.OwnerChart.ChartTrader.AtmStrategy.Template);
        Print(ChartControl.OwnerChart.ChartTrader.Quantity);
    }));
    Let us know if there is anything else we can do to help.
    JimNinjaTrader Customer Service

    Comment


      #3
      That worked but I am still getting an error this is the code:
      The error is the following Indicator'myTextIndicator': Error on calling 'onBarUpDate' method on bar 16000. The calling thread cannot acces this object because a different thread owns it.

      int nContractQuantity = 0;
      string AtmStrategyName1 = "";



      ChartControl.Dispatcher.InvokeAsync((Action)(() =>
      {

      nContractQuantity = ChartControl.OwnerChart.ChartTrader.Quantity;
      AtmStrategyName1 = ChartControl.OwnerChart.ChartTrader.AtmStrategy.Te mplate;

      Print(ChartControl.OwnerChart.ChartTrader.AtmStrat egy.Template);
      Print(ChartControl.OwnerChart.ChartTrader.Quantity );
      }));







      ChartControl.InvalidateVisual();


      TriggerCustomEvent(o =>
      {
      Order stopOrder = null;

      stopOrder = myAccount.CreateOrder(Instrument,
      OrderAction.Buy,
      OrderType.StopMarket,
      TimeInForce.Day,
      nContractQuantity,
      0,
      0,
      string.Empty,
      "Entry",
      null);

      // Submits our entry order with the ATM strategy named "myAtmStrategyName"
      NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(AtmStrategyName1, stopOrder);
      myAccount.Submit(new[] { stopOrder });
      }, null);

      nTradeType = 2;
      Draw.TextFixed(this, "TradeType", "Buy Activated", TextPosition.BottomLeft);
      }

      //#############

      Comment


        #4
        Hello ballboy11,

        When I wire this up, I'm not hitting such an error. Please test what I have attached and compare with what you are doing. Debugging prints can be used to see where exactly the error is getting thrown.

        If you have questions on the error received, please modify my example so it demonstrates the issue in clear and simple terms, and I will be happy to comment. Please ensure you export the modification to this example so it can be imported and tested.

        Exporting as Source Code - https://ninjatrader.com/support/help...tAsSourceFiles

        I look forward to assisting.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks. I tested and it worked. I found out that wasn't the issue the issue is one of my objects and I don't understand why I would get this error.


          lblTextBlockOutput.Text = "Trade Activated";

          This is a
          private System.Windows.Controls.TextBlock lblTextBlockOutput;

          The funny thing is if I use my button click handlers I can change the lblTextBlockOutput.Text
          This textBlockOutput is in my ChartTrader.

          If I have logic and want to enter the trade above, I wanted to change the label to trade submitted. but this is the error I get.

          2020-12-16 18:52:20:178|3|4|Indicator 'MyIndicator': Error on calling 'OnBarUpdate' method on bar 16337: The calling thread cannot access this object because a different thread owns it.

          When that happes I actually have to repair the database in order for the indicator to work again. If I take out the line

          //lblTextBlockOutput.Text = "Trade Activated"; My indicator works no problem.

          //This actually works.
          private void BuyButton_Click(object sender, RoutedEventArgs e)
          {
          if(sTradeType == "Buy Logic Trade")
          {
          sTradeType = "Trade Activated";
          lblTextBlockOutput.Text = "Trade Activated";
          nTradeType = 99;

          }
          }


          //this does not work and it is in onbarupdate
          if(Close[0]> dChosenPrice)
          {

          sEntryType = "Enter Long Market";
          // lblObjectSelected.Text = "Enter Long Market"; having this added will make the indicator crash

          nTradeType = 0;
          CallStrategy();


          Any Solutions?

          Comment


            #6
            Hell ballboy11,

            I will need a simplified example that is in a compliable state in order to test and comment. Otherwise I am left to guess. The only thing I may point out here is that UI elements will exist on a UI thread. OnBarUpdate runs from an instrument thread, so if you want to modify a UI element, you will need to use a dispatcher.

            Multi Threading Considerations - https://ninjatrader.com/support/help...-threading.htm

            If you are still stuck, please modify the script in post #4 so it demonstrates the issue and attach it here so I may comment further.

            We look forward to assisting.
            Last edited by NinjaTrader_Jim; 12-17-2020, 06:52 AM.
            JimNinjaTrader Customer Service

            Comment


              #7
              I realize that this thread hasn't been active for about 3 years--but I have a question that piggybacks off some of the conversation in this thread. I realize too that this is an unsupported method. But is there a similar way to get the primary and secondary data series info from the ChartTrader object or something similar? What am seeking is if the chart has 2 dataseries' on it "A" and "B" can i use this approach and print out the data series parameters -- Like "ES 12-23 277 Tick" and "ES 12-23 455 Tick"?

              Comment


                #8
                Hello PacCoastTrader,

                The chart trader does not have any specific series, it applies to the instrument that is selected by the instrument selector. You could access the instrument selector in the chart series to get the instrument name but there is not series which you can get because that just uses live data.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by PaulMohn, Today, 12:36 PM
                0 responses
                1 view
                0 likes
                Last Post PaulMohn  
                Started by love2code2trade, 04-17-2024, 01:45 PM
                4 responses
                37 views
                0 likes
                Last Post love2code2trade  
                Started by alifarahani, Today, 09:40 AM
                2 responses
                13 views
                0 likes
                Last Post alifarahani  
                Started by junkone, Today, 11:37 AM
                3 responses
                20 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by frankthearm, Yesterday, 09:08 AM
                12 responses
                44 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Working...
                X