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

Problems coding trades with Renko bars

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

    Problems coding trades with Renko bars

    Hi everyone

    Renko bars are very easy to work with, hence the logic of this strategy is simple:

    1) Open long (2)

    2) If the first bar into the trade is UP, sell (1)

    3) If the second bar into the trade is UP, sell (1)

    4) On any DOWN bar, exit trade.

    This is the code:

    Code:
    CalculateOnBarClose = true;
    
    ...
    
    if([I]Conditions…[/I])
                    
    EnterLong(2); 
    
    if (
            Position.MarketPosition == MarketPosition.Long
            && Close[0] > Open[0]
            && BarsSinceEntry() == 0
        )
         
            ExitLong(1);
    
    if (
           Position.MarketPosition == MarketPosition.Long
           && Close[0] > Open[0]
           && BarsSinceEntry() == 1
        )
                
        {
            ExitLong(1);
            BarColor = Color.Blue;
          }
    
    if (
           Position.MarketPosition == MarketPosition.Long 
           && Close[0] < Open[0]    
        )
    
            ExitLong();
    However, the trades on the chart don't always match what I've coded.

    Please see image. The trade on the left (2 up bars) is OK but the one on the right (up then down) is wrong - the first 'sell' price is a bar too low!

    NT seems to have a problem placing trades on Renko charts in the right place.

    I think the fundamental problem may be that two trades can't be entered on the same Renko bar!!!

    Could my coding be wrong anywhere?

    Any advice will be greatly appreciated.
    Attached Files

    #2
    Hello arbuthnot,

    Thank you for your note.

    Your strategy performed correctly here. You are setting CalculateOnBarClose to true as well.

    What occurred here is that the bar before the buy execution was where the signal happened for the EnterLong(), since that bar closed the execution was placed on the next bars' open price

    Then once that bar closed it submitted the exit order for one contract which is then place at the open price on the next bar.

    The last exit was taken cause the previous bar caused the Close[0] < Open[0] condition to become true and placed the execution at the open price of that bar.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Cal, thanks very much for your reply, which I’ve read carefully.

      Forgive the length of this post, but I'm trying to demonstrate a situation to both the Forum and myself, and I want to make sure my logic is sound but it does seem to me that Renko bars as implemented by NT aren’t capable of being traded with.

      Believe me, I did a great deal of experimentation with this code before posting and there is definitely something that doesn’t work.

      Let me illustrate: in the image from my first post below, there are two trades: one on the left, which goes up two Renko bars (Open-UP-UP) and yields the desired profit, and the one on the right which goes up one then down one (Open-UP-DOWN): in this one the trades aren’t entered correctly.

      In both trades, which are both opened by buying two contracts, the coding is specific: after the first UP bar, one contract is to be sold at the close of this UP bar (or the open of the next bar: it makes no matter, it’s the same price). This happens in the left-side trade but not in the right-side one.

      This is the analysis of the situation:

      1st Trade (Profit in blue)

      Open --------(1st UP bar) ------(2nd UP bar)

      16509.97 0 | 16519.97 +10 | 16529.97 +10

      2nd Trade

      Open -------(1st UP bar) ----(DOWN bar)

      16519.97 0 | 16519.97 0 | 16509.97 -10

      So the profit on each stage of the 2nd trade is:


      0 | 0 | -10

      but it should be:


      0
      | +10 | -10

      In real-time trading, the system doesn’t know whether the next bar with be ‘up’ or ‘down’ but as it’s depicted on the chart, it does! Because with an identical situation after one UP bar, the first trade sells one contract 10 points up, but in the second case, one contract is sold at the same price as the open – with no profit!

      As the system reacts differently with the same code in an identical situation, the only difference being what happens in the future, the system must be at fault.

      If I'm wrong, please kindly point out where my logic is at fault.

      This must be a systemic fault because identical situations are handled differently depending on what happens in the future.

      I think the lesson to be learnt as that NT can’t handle trading situations like this based on Renko bars. I was hoping to use Renkos in this way as it would be so much simpler but it looks as if I'll have to use a more conventional approach, which would be far more complex.

      Comment


        #4
        arbuthnot,

        There is not a logic issue but rather this is an order of events that is occurring.

        Remember, we are running COBC set to true in backtest. Which means all our executions are going to show on the next bar from the signal bar that is being met in the code.

        Additionally, market orders are going to be filled at the Open price of the next bar.

        If would like a more granular fill then you would need to look at using an Intrabar Granularity or run the strategy using Market Replay feature with NinjaTrader

        Here is a link on how to use IntraBar Granularity -
        http://www.ninjatrader.com/support/f...ead.php?t=6652
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Thanks very much for your further information and for the link (very helpful).

          Given that I can't use the approach I was using, could you confirm that there are at least two ways of proceeding:

          1) to set up up multi-time frame chart, with:
          a) one part being the Renkos bars with the entry conditions

          b) the other part being a small-scale time chart (such as 5- or 10 seconds) or a small-scale tick chart to manage the trades
          or

          2) to use an ATM strategy launched from within my main 'entry' strategy, and is it the case that this would process the trade on a 'tick by tick' basis?

          Thanks for letting me know about these and whether there may be any other approaches.

          (I get the impression that the above have a big learning curve and I was obviously trying to circumvent these options.)

          Comment


            #6
            arbuthnot,

            Yes, these are both possible to do. However, please note that ATM in your automated strategy are not backtestable as these only work on live data.

            If you use this method you would need to test this with either live data, market replay, or simulated data feed.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by arbuthnot View Post
              Cal, thanks very much for your reply, which I’ve read carefully.

              Forgive the length of this post, but I'm trying to demonstrate a situation to both the Forum and myself, and I want to make sure my logic is sound but it does seem to me that Renko bars as implemented by NT aren’t capable of being traded with.

              Believe me, I did a great deal of experimentation with this code before posting and there is definitely something that doesn’t work.

              Let me illustrate: in the image from my first post below, there are two trades: one on the left, which goes up two Renko bars (Open-UP-UP) and yields the desired profit, and the one on the right which goes up one then down one (Open-UP-DOWN): in this one the trades aren’t entered correctly.

              In both trades, which are both opened by buying two contracts, the coding is specific: after the first UP bar, one contract is to be sold at the close of this UP bar (or the open of the next bar: it makes no matter, it’s the same price). This happens in the left-side trade but not in the right-side one.

              This is the analysis of the situation:

              1st Trade (Profit in blue)

              Open --------(1st UP bar) ------(2nd UP bar)

              16509.97 0 | 16519.97 +10 | 16529.97 +10

              2nd Trade

              Open -------(1st UP bar) ----(DOWN bar)

              16519.97 0 | 16519.97 0 | 16509.97 -10

              So the profit on each stage of the 2nd trade is:


              0 | 0 | -10

              but it should be:


              0
              | +10 | -10

              In real-time trading, the system doesn’t know whether the next bar with be ‘up’ or ‘down’ but as it’s depicted on the chart, it does! Because with an identical situation after one UP bar, the first trade sells one contract 10 points up, but in the second case, one contract is sold at the same price as the open – with no profit!

              As the system reacts differently with the same code in an identical situation, the only difference being what happens in the future, the system must be at fault.

              If I'm wrong, please kindly point out where my logic is at fault.

              This must be a systemic fault because identical situations are handled differently depending on what happens in the future.

              I think the lesson to be learnt as that NT can’t handle trading situations like this based on Renko bars. I was hoping to use Renkos in this way as it would be so much simpler but it looks as if I'll have to use a more conventional approach, which would be far more complex.
              That second trade. The first exit is showing execution on the Open of the next bar. You happen to be looking at it as the low of the entry bar. That is one of the vagaries of Renko at reversal. Regardless the posture of the bar, at a reversal, the Open of the next bar is the other extreme of the previous bar.
              Last edited by koganam; 08-20-2014, 10:40 AM.

              Comment


                #8
                arbuthnot,

                Yes, these are both possible to do. However, please note that ATM in your automated strategy are not backtestable as these only work on live data.

                If you use this method you would need to test this with either live data, market replay, or simulated data feed.
                Much obliged, Cal.

                Either way, this is where the coding gets difficult and there's a lot to learn...
                Last edited by arbuthnot; 08-20-2014, 10:46 AM. Reason: Omitted something

                Comment


                  #9
                  That second trade. The first exit is showing execution on the Open of the next bar. You happen to be looking at it as the low of the entry bar. That is one of the vagaries of Renko at reversal. Regardless the posture of the bar, at a reversal, the Open of the next bar is the other extreme of the previous bar.
                  Thanks as always, Koganam, for pointing out important aspects.

                  I think the morale of this story is: Renko is great for getting into trades ... but lousy at working them!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by helpwanted, Today, 03:06 AM
                  1 response
                  8 views
                  0 likes
                  Last Post sarafuenonly123  
                  Started by Brevo, Today, 01:45 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post Brevo
                  by Brevo
                   
                  Started by aussugardefender, Today, 01:07 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post aussugardefender  
                  Started by pvincent, 06-23-2022, 12:53 PM
                  14 responses
                  242 views
                  0 likes
                  Last Post Nyman
                  by Nyman
                   
                  Started by TraderG23, 12-08-2023, 07:56 AM
                  9 responses
                  385 views
                  1 like
                  Last Post Gavini
                  by Gavini
                   
                  Working...
                  X