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

Need HELP to fix issues. I am making strategy which trades with buttons

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

    Need HELP to fix issues. I am making strategy which trades with buttons

    Hello there,

    I have several issues and need your help.
    1) I have copied part of code from SampleWPFModifications.cs(link: https://ninjatrader.com/support/foru...rations/page10) to my code to have buttons and textboxes in ChartTrader but it still draws it on chart and I don't know why.
    2) I have created TextBoxes and I want to allow user to input there only numbers and use those numbers in algorithm. for example Difference textbox text is 10 then I want to place pending orders from price 10 pips above/below.
    3) I am using ATM Strategy and with Buy and Sell buttons its works fine and opens Buy and Sell trades but I need also to be able to open BuyStop, SellStop, BuyLimit, SellLimit orders and I couldn't make it to work.
    4) I need to be able to delete Pending orders with CancelPendingOrders button what I have created and also close all opened trades with CloseAnyOpenTrades button. I couldn't make it to work.
    5) last thing is that I need BreakEven. BreakEven will set stoploss to PositionOpenPrice + ProfitLock for buy example.

    I know I am asking many things but unfortunately I couldn't figure out those things and need your help.
    will attach my full source code file.

    waiting for your reply and thank you very much in advanced.
    Attached Files

    #2
    Hello Revazi123,

    Thank you for your post.

    We noted you posted a duplicate of this post on a different thread, so we've removed that and will reply here.

    For the first issue, really the best suggestion we could have here would be to start over. The grid you've added is different than in the example so we'd suggest basically making a copy of the ChartTraderCustomButtonsExample I've attached below and then modify that and make sure it works with each change. It appears to be an issue with setting the rows and columns in your code. Specifically it looks like you're missing the code from lines 141 - 150 from ChartTraderCustomButtonsExample - in your code you didn't replicate that and instead used UserControlCollection.Add(myGrid). The UserControlCollection is specifically a WPF control on the chart, so that's a different WPF concept.

    As for inputs, we would suggest using a QuantityUpDown control rather than a text box, an example of which may be found here: https://ninjatrader.com/support/foru...rd#post1054226

    For submitting entry orders for your ATMs, can you detail what's not working exactly? Does it try to submit an order but return an error, or does it not submit at all?

    AtmStrategyClose() would close any currently running ATM: https://ninjatrader.com/support/help...ategyclose.htm

    If you're wanting to cancel a working ATM entry order, you would want to use AtmStrategyCancelEntryOrder(): https://ninjatrader.com/support/help...entryorder.htm

    To modify the stop order price set by the ATM (such as changing it to breakeven), you'd need to use AtmStrategyChangeStopTarget(): https://ninjatrader.com/support/help...stoptarget.htm

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello Revazi123,

      Thank you for your post.

      We noted you posted a duplicate of this post on a different thread, so we've removed that and will reply here.

      For the first issue, really the best suggestion we could have here would be to start over. The grid you've added is different than in the example so we'd suggest basically making a copy of the ChartTraderCustomButtonsExample I've attached below and then modify that and make sure it works with each change. It appears to be an issue with setting the rows and columns in your code. Specifically it looks like you're missing the code from lines 141 - 150 from ChartTraderCustomButtonsExample - in your code you didn't replicate that and instead used UserControlCollection.Add(myGrid). The UserControlCollection is specifically a WPF control on the chart, so that's a different WPF concept.

      As for inputs, we would suggest using a QuantityUpDown control rather than a text box, an example of which may be found here: https://ninjatrader.com/support/foru...rd#post1054226

      For submitting entry orders for your ATMs, can you detail what's not working exactly? Does it try to submit an order but return an error, or does it not submit at all?

      AtmStrategyClose() would close any currently running ATM: https://ninjatrader.com/support/help...ategyclose.htm

      If you're wanting to cancel a working ATM entry order, you would want to use AtmStrategyCancelEntryOrder(): https://ninjatrader.com/support/help...entryorder.htm

      To modify the stop order price set by the ATM (such as changing it to breakeven), you'd need to use AtmStrategyChangeStopTarget(): https://ninjatrader.com/support/help...stoptarget.htm

      Please let us know if we may be of further assistance to you.
      Hi there,

      Thanks for your reply.
      for 1st question I will attach screenshot. I think I have copied grid correctly.
      what about order submitting I don't know exactly how to code it. I mean I tried this(Screenshot_19) and I am getting this error(Screenshot_20) when I click BuyStop, SellStop or SellLimit buttons but when I click on BuyLimit nothing happens.

      Thank you
      Attached Files

      Comment


        #4
        Also 1 thing, How should I filter position which was opened by ATM. I mean I want something like this:
        Code:
        if (AtmStrategyOrderType == OrderAction.Buy)
        {
        AtmStrategyChangeStopTarget(0, High[1] + 10 * TickSize, "Stop1", atmStrategyId);
        }
        else if (AtmStrategyOrderType == OrderAction.Sell)
        {
        AtmStrategyChangeStopTarget(0, Low[1] - 10 * TickSize, "Stop1", atmStrategyId);
        }

        Comment


          #5
          Hi,

          I have fixed all issues. Only one thing what is missing is pending orders algorithm. Can you please give me simple example of placing of any pending order algorithm?

          Thanks in advanced

          Comment


            #6
            Use AtmStrategyCreate()
            https://ninjatrader.com/support/help...tegycreate.htm

            Comment


              #7
              Originally posted by Leeroy_Jenkins View Post
              Thanks for your reply but I have checked that already when I started working on this project and couldn't make it work.

              Comment


                #8
                Also Pending order delete function not works. I mean AtmStrategyCancelEntryOrder() - https://ninjatrader.com/support/help...tegycreate.htm

                So if you can help please make very simple example code which will open for example buy stop order and sell stop orders and when 1 will execute delete another one. I need just example so it doens't matters for me where will be those orders placed(I mean distances)

                Comment


                  #9
                  ATM strategy uses orderId and atmStrategyId identifiers.
                  if you set right orderId like this orderId = GetAtmStrategyUniqueId()
                  AtmStrategyCancelEntryOrder(orderId) will work.

                  Here is official example by NT support. This is only for one order. If you wanna have 2 orders at the same time you need to use different orderId and atmStrategyId.
                  Attached Files

                  Comment


                    #10
                    Hello Revazi123,

                    Thank you for your replies.

                    Leeroy_Jenkins is on the money here and has supplied an example I would have suggested myself. He's correct that if you want to have two simultaneous entry orders You would need to have different order IDs and atmStrategyId and you'd need to save those in differently named variables so they can be correctly tracked, and so you can give the correct order ID to AtmStrategyCancelEntryOrder() to cancel the one that did not fill.

                    Please let us know if we may be of further assistance to you.
                    Kate W.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Kate View Post
                      Hello Revazi123,

                      Thank you for your replies.

                      Leeroy_Jenkins is on the money here and has supplied an example I would have suggested myself. He's correct that if you want to have two simultaneous entry orders You would need to have different order IDs and atmStrategyId and you'd need to save those in differently named variables so they can be correctly tracked, and so you can give the correct order ID to AtmStrategyCancelEntryOrder() to cancel the one that did not fill.

                      Please let us know if we may be of further assistance to you.
                      I am using List of strings and I have not problem with that my problem is that I can Delete and Close all positions same time with AtmStrategyClose() but coudn't make AtmStrategyCancelEntryOrder() function work. So if you can give me simple example I will be glad. Thank you in advanced.

                      Comment


                        #12
                        Hello Revazi123,

                        Thank you for your reply.

                        I'm attaching an example strategy that is a modified version of the Sample ATM Strategy that comes built into NinjaTrader that demonstrates how an entry order may be cancelled with AtmStrategyCancelEntryOrder(). This requires an existing ATM Strategy Template called "AtmStrategyTemplate" in order for it to function. If the entry order is not filled within 3 bars, it will be cancelled.

                        Please let us know if we may be of further assistance to you.
                        Attached Files
                        Kate W.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Kate View Post
                          Hello Revazi123,

                          Thank you for your reply.

                          I'm attaching an example strategy that is a modified version of the Sample ATM Strategy that comes built into NinjaTrader that demonstrates how an entry order may be cancelled with AtmStrategyCancelEntryOrder(). This requires an existing ATM Strategy Template called "AtmStrategyTemplate" in order for it to function. If the entry order is not filled within 3 bars, it will be cancelled.

                          Please let us know if we may be of further assistance to you.
                          Thank you for your reply.

                          I have recorded small video and please check it. link: https://drive.google.com/file/d/1DzN...ew?usp=sharing

                          Thanks.

                          Comment


                            #14
                            Found issues. it was very simple copy-past error. Thanks for your help Kate.

                            Comment


                              #15
                              Hello Kate,

                              Can you please edit your example code like this:
                              after opening for example buy positions place 2 pending orders for example Buy stop and Sell stop. When 1 of those stop orders will be executed for example buy stop then delete sell stop and also close previous buy order. Can you please make this simple script?

                              Then I will read and understand your code and then fix mine.

                              Thank you in advanced. Waiting for your reply.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tkaboris, Today, 11:09 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by marco231, 03-20-2024, 03:56 PM
                              5 responses
                              155 views
                              0 likes
                              Last Post bnoisette  
                              Started by tonynt, Today, 08:05 AM
                              2 responses
                              17 views
                              0 likes
                              Last Post tonynt
                              by tonynt
                               
                              Started by victor68133, Today, 07:50 AM
                              4 responses
                              26 views
                              0 likes
                              Last Post backtester831  
                              Started by marcus2300, Yesterday, 07:37 AM
                              4 responses
                              37 views
                              0 likes
                              Last Post marcus2300  
                              Working...
                              X