• 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

Reloading Ninjascript

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

    Reloading Ninjascript

    When I have a strategy running sometimes I notice that there are no trades executed when the crossover of 2 lines happen as set by the strategy, however when I refresh the chart, the trades plot on the chart in the correct locations or instances of crossover but not in a live environment, only after I refresh they show up and if the last execution was a sell as per the plot on the chart, the position will reverse if the existing position did not match - how do I fix this?

    The photo shows a chart where I hit tyhe refresh button (as you can see the sell order was places as I hit the reset button and is not where it should be as per the strategy.

    #2
    Hello TrendFollowingCapital,

    Thanks for your post.

    There are a couple of possibilities that you can check on this.

    1) Was the strategy status (as shown by the color of the name in the strategy tab) at the time Green or Orange? If Orange, that would indicate that the strategy was in the process of waiting for the latest historical trade to complete before placing live orders and when refreshed perhaps the timing was such that it showed that trade. Please see, "Understanding the strategies tab" https://ninjatrader.com/support/help...tegies_tab.htm

    2) It is possible that with Renko type bars that backtest/historical trades are performed where in real time they would not because of the false data provided by the bar. Historical Renko bars do not show the actual movement of the price that occurred during the bar so the simulation engine only works with the presented bars OHLC values. Renko bars are used to present price in a different way and use a false opening price and often the movement between open and close does not occur so in real time it might appear that the bar moves a number of ticks when in reality it does not.
    To resolve this, you would need to debug the trades using print statements in your code to understand why the trades (print out the entry conditions/values) were made where/when they were,

    Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul

      Thank you for you rrespose.

      1) Definitely Green and running, so I know that is not it.

      2) I understand the renko bars may not be the norm for setting up strategies but there must be a way for them to work. Please watch this very short video on what is happening:
      https://1drv.ms/v/s!AhSWHH-cXiUgie94ytPE7btJh6mDCg

      My action to enter a long position is:
      Enter long position by a limit order/Price/close/Bars ago 1
      Surely this should work without being refreshed?
      It is set to enter a long position after a crossover of 2 lines and the entry is a limit order at the price of the close of the previous bar - what am I missing here?

      I have refreshed the chart again and the order reversed.

      Comment


        #4
        Hello TrendFollowingCapital,

        Thanks for your reply and appreciate the video.

        What is happening is that in real time the actual price does not retrace back to the level of the limit order. As I mentioned these type bars present false price movement. When you reload the strategy the historical order is filled because the historical bar goes below the limit price. The historical fill process does not know that the bars present false data and only know of the bars finished Open, High, Low and Close values and based on that the historical bar went below the limit price and filled the order.

        An option to consider would be to use a BuyStopMarket order above the price of the bar (in that direction) where the price would actually have to move up. Or simply use an EnterLong() which is a market order.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for you reply Paul, what I have noticed is that a Buy stop limit appears and if the price does not retrace to that level it dissapears after a while, however if the price does retrace it gets filled at my preferred entry point which is good because there are often a few ticks saved by it doing so instead of it just opening at the top or bottom of the next bar at the worst possible fill.
          Is there a way to have that Buy Stop Limit trail the price until it does get filled instead of just changing it to a standard buy market/sell market?
          There is a HUGE difference in probability of success between a buy stop limit and market order, especially on 20 - 30 entries per day, which will be the difference between a profitable or losing strategy.

          Comment


            #6
            Hello TrendFollowingCapital,

            Thanks for your reply.

            A BuyStoplimit/market order would need to would be placed above the current price and the market would need to continue moving in that direction to fill whereas a market order would fill immediately. In this regard, a market order might be a better choice and I suggest you test with live data on your sim101 account to see what work best.

            Regarding, "it dissapears after a while", This could be caused two separate things, please check the "Log" tab of the control center for any error messages when this occurs. More likely though, in the managed approach when you place an order and it is not filled in the bar, it will be automatically canceled. You would need to have your code continue to submit the order on each bar until it fills or the condition is no longer valid. The same would true with your buy limit orders as well.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thank you Paul, you mentioned "You would need to have your code continue to submit the order on each bar until it fills or the condition is no longer valid. The same would true with your buy limit orders as well."

              Please could you provide the code for this, I am not able to find it?
              Kind regards, Jason

              Comment


                #8
                Hello TrendFollowingCapital,

                Thanks for your reply.

                Existing condition/assumptions: Strategy is using Calculate.OnBarClose. In your code, you would have a condition that when true the action would be to submit the order. On the next bar, if the order is not filled it will be automatically canceled and if the condition to place the order is no longer true, then the order would not be resubmitted.

                To work around this, you can create/use a bool variable. In the condition where you place the order, instead of placing the order you would set the bool true. After that, you would have a condition where if the bool is true and Position.MarketPosition == MarketPosition.Flat, to submit the order and as long as the bool is true the order will be resubmitted on each bar. As soon as the order is filled and the position is updated then the entry condition of the position being flat will no longer be true and no further orders will be submitted.

                Note: You would need to create a condition that would allow you to reset the bool so that it does not keep resubmitting or submitting when you are flat. As a suggestion, when the market position is long (or short) to reset the bool.

                You would use a different bool for each direction.

                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Oceans, Today, 02:22 AM
                1 response
                17 views
                0 likes
                Last Post NinjaTrader_PatrickG  
                Started by sisenberg, Yesterday, 08:06 PM
                1 response
                14 views
                0 likes
                Last Post sisenberg  
                Started by PLeary, Today, 06:25 AM
                0 responses
                4 views
                0 likes
                Last Post PLeary
                by PLeary
                 
                Started by sergey_z, Today, 06:17 AM
                0 responses
                1 view
                0 likes
                Last Post sergey_z  
                Started by nikkk, Today, 06:14 AM
                1 response
                2 views
                0 likes
                Last Post NinjaTrader_PatrickG  
                Working...
                X