Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with strategy

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

    Help with strategy

    Hi,
    I have put together these codes after borrowing from codes available here. And ofcourse it does not work.

    The objective of the strategy is to

    1) Look back the desired number of bars.
    2) a) If high of the highest bar minus Low of the lowest bar is greater than specified number of ticks
    2 b) and the previous bar closes higher than its prior bar; place buy limit order
    2 c) the previous bar closes lower than its prior bar: place sell limit order.
    3) Cancel the Limit orders if it does not trigger within a specified number of bar.


    It is required that the trade is managed through the dome.

    Appreciate if you could highlight the errors which is nor allowing to trade.

    Regards
    Arshad
    Attached Files

    #2
    Hello Arshad,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Please detail what is not occurring. Are each of the numbered and lettered items not occurring? What steps have you taken to debug this script?

    You wish to manage the trade manually on the SuperDOM? This would not be recommended as automated strategies are not intended for manual interference.
    Are you instead looking for an indicator to signal an entry that you would place manually and manage the exit(s) manually as well?

    If a script is not performing as you wish we would recommend debugging the script. Please visit the following link for information on debugging your NinjaScript code: http://ninjatrader.com/support/forum...ead.php?t=3418

    Comment


      #3
      Thanks Patrick for your reply.

      I do not have enough understanding to code any complicated procedure. With the help of strategy wizard and some personal intuition, I have been able to code a simple strategy which works for my limited requirement. However complications arise when market moves very fast and my codes are unable to handle the fast move, leaving behind orders which do not close and then I see unwanted trades appearing.

      Other thing that creates an issue is the fact that stops and profit targets placed by the strategy cannot be changed as we move along in a trade. When I move the stop or profit target, it comes back to the settings in the strategy.

      Handling this within the main strategy is beyond my knowledge of programming. Based on some readings in the forum, I understand that, if I use the main strategy to send trades through AtmStrategyCreate(), I can change the stop and profit target through the dome.

      I found this SampleAtmCancelStrategy submitted by Mr Ticks and used it in the code that I attached earlier. See the following link for Mr. Ticks' code http://ninjatrader.com/support/forum...N&pp=15&page=3

      I assumed that Mr Ticks' code is a working code, but placed on my charts has not taken any trade for sometime now. If this code can be tested and confirmed to be working, the code that i have developed will probably also work.

      Arshad
      Last edited by Trader-; 11-15-2016, 09:38 PM.

      Comment


        #4
        Hello,

        Thank you for the reply.

        With the script provided it seems there is a long and short side with separate atm's. Without knowing what problem you are running into that is causing it to not trade it is hard to say what may be happening. To know why it is not placing trades you would need to debug the script, one way would be to use prints.

        First I would suggest to find where the script is being held up before it places an order. You have various conditions in the scriptl :

        Code:
        if (	orderIdL.Length == 0  
                                        && atmStrategyIdL.Length == 0
        ......
        You could use Print statements before the conditions to print out the variables and conditions used.
        For example:

        Code:
        Print(orderIdL.Length);
        Print(atmStrategyIdL.Length);
        This would output the information to the Tools -> Output window and allow you to address what variable used is not within the range to allow the condition.

        If you are getting orders left over it would be best to address which side is having that problem or if both are. If one side is having that problem, I could suggest to comment out the other sides code and just work with 1 atm strategy to better see what may be occurring.

        I would be unsure if SampleAtmCancelStrategy works as I have not tested that specifically, Instead I could suggest to review the sample that comes with the platform. The sample is called SampleATMStrategy.

        You would need to view the code of this strategy and review the comments, it notes that you have to create an atm strategy named AtmStrategyTemplate before running it. This sample would demonstrate the required syntax for making a NinjaScript strategy that uses an ATM template. If needed you could also use the sample as a starting point.

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

        Comment


          #5
          Hello Jesse, Patrick

          Thanks for your replies.I took help from the sample code that you mention. After comparing the various lines I changed the following line:

          AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, 0, Close[1] - GetTradeBetterBy * TickSize, TimeInForce.Day, orderIdL,aTMStrategyTemplate , atmStrategyIdL);

          To:

          AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, Close[1] - GetTradeBetterBy * TickSize,0, TimeInForce.Day, orderIdL , ATMStrategyTemplate, atmStrategyIdL);



          And similarly for the "Sell" side I changed:

          AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Limit, 0, Close[1] + GetTradeBetterBy * TickSize, TimeInForce.Day, orderIdS, aTMStrategyTemplate, atmStrategyIdS);


          To:

          AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Limit,Close[1] + GetTradeBetterBy * TickSize, 0,TimeInForce.Day, orderIdS, ATMStrategyTemplate, atmStrategyIdS);


          I am using the variable ATMStrategyTemplate to refer the template I have created and named "MyHiLo".

          I seem to have moved a step forward and now when the conditions are met, the strategy tries to place a pending order. However as soon as the pending order is placed, it also cancels the order.

          When, in another strategy, I used the EnterLongLimit() I was faced with somewhat same issue. I was able to figure out that I had to use "true" as one of the elements inside the bracket. "EnterLongLimit(0,true,quantity, , , )"

          Do i have to use something similar to correct the problem I am facing? Please review the above changes I have made and suggest what I should do so that the pending orders are not closed immediately.

          Once we settle this issue, I can proceed to identify other issues with the code.

          Thanks
          Arshad
          Last edited by Trader-; 11-17-2016, 02:56 PM.

          Comment


            #6
            Hello,

            Thank you for the reply.

            I am glad the sample was able to help you get further with the code.

            I wanted to check, is the pending order placed and then a bar elapses and it is cancelled? Or does it immediately get canceled and only briefly passes a pending state?

            Could you provide the revised script and the instrument/settings used for testing? I would like to run the script now and see the same result you are getting.

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

            Comment


              #7
              Hi Jesse,

              The order cancels instantly, within the second. Uploading the requested file. Please create the ATM template "NQ1" .

              Arshad
              Attached Files

              Comment


                #8
                Hi Jesse,

                I think I have figured out the reason for orders being cancelled. i had commented out two lines with the following codes

                orderBarL = CurrentBar; Line #106
                orderBarS = CurrentBar; Line #133

                Thanks to both of you for helping out. Wonder if you could review rest of the code and suggest improvements.

                In the meanwhile I will test out the strategy for errors and come back for any further help from you.

                Arshad

                Comment


                  #9
                  Hello,

                  Thank you for the reply.

                  Looking at the logic, it appears this currently works because the orderBarS and orderBarL is essentially now removed from the conditions they were used in. Some called for a value of the (CurrentBar - orderBarS), so effectively the value is now just the CurrentBar - 0 being used.

                  Aside from that observation I couldn't really suggest improvements, but I could say if the SampleATMstrategyCANCEL works how you want, you may need to look further at your added conditions if you are seeing problems. The scripts are very similar, so if the results are not expected you could reduce the additions you have made to return to a state closer to the original.

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

                  Comment


                    #10
                    Hi Jesse,

                    Whereas it is now placing the pending orders, when price is hovering around the condition, it tends to keep placing pending orders, at times with as many as four pending orders. all of them then gets executed once price reaches the limit. Any thoughts.

                    Arshad

                    Comment


                      #11
                      Hello,

                      Thank you for the reply.

                      The problems you are having seem to be coming from combining the two scripts, to better understand the ATM process I would suggest to use the sample that comes with the platform as a starting point as we know that works and then continue from that point.

                      The logic in this script after the change allows the entry to always be cancelled so it will never actually continue to work as expected.

                      in the script we can see:

                      Code:
                       //add in by kz
                                                      if ((CurrentBar - orderBarL) >= cancelPendingAfterBars)
                      Previously I had noted that the logic was changed when you modifed how orderBarL was being set. Because CurrentBar - 0 is just the current bar, this will always be true to cancel the order.

                      I would suggest to remove the items you have added marked by //add in by kz or revert to the sample that comes with the platform. Either of these directions should assist in resolving the problems. When you combine two different sets of logic, in some cases it will not make sense and can cause problems. In this case by modifying how the cancel scripts logic works, it has prevented the script from trading at all.


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

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by mgco4you, Today, 09:46 PM
                      1 response
                      3 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by wzgy0920, Today, 09:53 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post wzgy0920  
                      Started by Rapine Heihei, Today, 08:19 PM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by Rapine Heihei, Today, 08:25 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post Rapine Heihei  
                      Started by f.saeidi, Today, 08:01 PM
                      1 response
                      9 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Working...
                      X