Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

No Positions Being created

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

    No Positions Being created

    Hello,

    I have a spread which I have created as an indicator. Within the indicator I have also specified bollinger bands (Upper, Middle and Lower). The indicator is called SpreadBollinger.
    What I want my strategy to do is enter short positon for 10 lots whenever the Upper bollinger band is broken with a stop of 12 ticks.
    But at the moment no positions are being created and so my strategy analyzer comes back with 0 for the p&l.
    Ideally I also want the strategy to take profit when the spread croses the middle bollinger band.
    I have attached my code;

    Any suggestions would be most welcome!

    Kind Regards,

    Ravi
    Attached Files

    #2
    Ravi,

    I am happy to assist you.

    What sort of time frame are you running this on? Did you ensure that you have historical data available for each of the two instruments you are plotting the spread for?

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi Adam,

      In the strategy tutorial the strategies are applied to the insturments, do I have to create my spread as an instrument and then apply a bollinger type strategy to the spread?

      Comment


        #4
        Ravi,

        You can just use an indicator. The issue is that you cannot trade spreads in NinjaTrader without trading them synthetically. In other words, you would need to buy X shares of one stock and sell Y shares of another or something like that to trade a spread.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Adam,
          • Running on daily time frame
          • The spread information (one instrument – second instrument) is in an indicator, which is referenced in the strategy.
          • How do I reference the spread that is in the indicator;
            • Do I have to put it in as a variable?
            • Do I have to Add () it to Initialize ()?
            • Can I just reference it by its name?
          • How do I ensure a graph of the synthetic spread is drawn within
          • the strategy when I click on the graph tab?
          I want an idea of the structure so I can takle it piece by peice if you know what I mean.

          Thank you!

          Kind Regards,

          Ravi

          Comment


            #6
            Ravi,

            You should be able to access it like any plot, like for Stochastic it is Stochastic(period1,period2,period3).D[x] to access the D plot.

            Here is also a reference sample for accessing things that are not plots.

            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Hi Adam,

              Thanks for the link, that is a really helpful doc and the example as well.
              I have a few issues still though, I have a spread with a bollinger indicator in the same indicator as the Spread indicator. When I try and reference the spread and the bollinger bands in the CrossAbove method it does not recognise it. So I decided to rebuild the Spread and the bollinger bands within the spread,
              It is my understanding that for the spread to have indicators imposed upon it, the indicator must be coded in the sythetic spread.
              So I tried to copy the first spread I had with bollinger bands but I am getting an issue with respect to the SMA (used to calculate the bollinger bands)
              here is the code I have;

              double smaValue = SMA(Spread, Period)[0];
              double stdDevValue = StdDev(Spread,Period)[0];
              BollingerUpper.Set(smaValue + NumStdDev * stdDevValue);
              BollingerMiddle.Set(smaValue);
              BollingerLower.Set(smaValue - NumStdDev * stdDevValue);

              but I am getting errors back saying
              'NinjaTrader.Data.Period' is a 'type' but is used like a 'variable'
              The best overloaded method match for 'NinjaTrader.Indicator.Indicator.SMA(NinjaTrader.D ata.IDataSeries, int)' has some invalid arguments
              Argument '2': cannot convert from 'NinjaTrader.Data.Period' to 'int'
              'NinjaTrader.Data.Period' is a 'type' but is used like a 'variable'
              The best overloaded method match for 'NinjaTrader.Indicator.Indicator.StdDev(NinjaTrade r.Data.IDataSeries, int)' has some invalid arguments
              Argument '2': cannot convert from 'NinjaTrader.Data.Period' to 'int'

              Any ideas why this isn't working, I think it is related to having Spread in the code, but this worked previously.

              Kind Regards,

              Ravi

              Comment


                #8
                Ravi,

                How are you defining the Period variable? I suspect this is the issue.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Genius, I hadn't defined the Period in the region properties, it was driving me mad!
                  Thanks!

                  Comment


                    #10
                    Hi Adam,

                    I am still getting the same error as when I first created the synthetic spread with Bollinger bands.
                    When I try to refer to them in CrossAbove like so;
                    if (CrossAbove(Spread3("NQ 03-12", 2, 2, 14, "FDAX 03-12", 1).Spread, Spread3("NQ 03-12", 2, 2, 14, "FDAX 03-12", 1).BollingerUpper))

                    I get an error back saying;
                    'No overload for method 'CrossAbove' takes '2' arguments

                    It does not seem to be reading the Spread3 indicator I just created.

                    (Could this have anythign to do with the (+3 overloads) in the definition of the indicator?

                    Kind Regards,

                    Ravi

                    Comment


                      #11
                      Ravi,

                      Yes, CrossAbove( dataseries1, dataseries2, lookback) is the correct form. A lookback = 1 is normally used unless you want to check over more past bars for a crossing condition.
                      Adam P.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Adam,

                        Thanks again the 1 at the end seemed to solve the issue.

                        I have managed to re-create the strategy similar to the one in the example you gave (SampleBoolSeries). But the issue I am having is that the strategy only creates a p&l on one of the instruments, FDAX 12-11. Which is strange because I have defined the spread as 2 * NQ 03-12 - 1 * FDAX 03-12.

                        I beleive the reason for this is becasue I do not have the instruments NQ 02-12 or FDAX 03-12 in the strategy analyzer. I have tried to add NQ 03-12 to the instrument list in the strategy analyzer list but when I right click on it, the back test option is greyed out. I have managed to add the instruments in the dataseries on a graph as you can jsut type them in but it doesn't seem to be the same process for the strategy analyzer.
                        Do you have any documentation on this or know the best practice in adding instruments, or have any other idea why I am not getting any postiions?

                        Kind Regards,

                        Ravi

                        Comment


                          #13
                          Ravi,

                          Are you attempting to trade a synthetic spread? I.e. buy one future and sell another within the same strategy?
                          Adam P.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Adam,

                            Yes that is correct it is a sythetic spread where I am looking to buy one instrument and sell another.

                            Kind Regards,

                            Ravi

                            Comment


                              #15
                              Hello Ravi,
                              Thanks for writing in and I writing for Adam.

                              While back-testing a multi-instrument strategy, the strategy analyzer will show the combined performance report for both the stock.

                              Unfortunately we do not have any best practices manual specifically for backtesting multi-series instruments.

                              Please let me know if I can assist you any further.
                              JoydeepNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GLFX005, Today, 03:23 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post GLFX005
                              by GLFX005
                               
                              Started by XXtrader, Yesterday, 11:30 PM
                              2 responses
                              11 views
                              0 likes
                              Last Post XXtrader  
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              14 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Working...
                              X