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

Multiple Target profits

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

    #31
    Hello Pladijske,

    Thank you for your reply.

    I'd like to do some testing with your strategy on my end, but it references an indicator I don't have, LongDax1HoogsteRendement0602. I could make something up to give similar signals, but would you be able to provide that indicator? That would certainly assist in my testing.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #32
      Hello Kate,

      I appologize, but I find it too difficult to send you my indicator on which I have been working so hard for 2 years.
      The thing is that I just want to know wether I can adjust the average price when 2 of the 5 futures have been sold as I explained above. Or is there another way to adjust this?

      Second: I don't understand how the realtime data really works.
      I have an Internet Brokers account, because here in Belgium there is no other opportunity.
      First I start up my IB account and check, by opening charts, that all data feeds are ok

      Then I start up the ninjatrader 8, connect to the IB datastream and then open the charts I need.
      Sometimes it opens up immediately and sometimes I have to wait. But the last 2 weeks I encounter trouble starting up FDAX 03-20.
      In the log it today stated : "eurex.... is not enabled to receive real time data. Please....." But I checked with IB and everything was ok and for the YM there is no problem and when I open superDOM I get the live ticks for the FDAX 03-20???
      So what is wrong and how can I prevent this in the future?

      Because before I want to go live and buy the license, I want to be sure that everything works and understand how it works.

      As always, many thanks for your time and effort!

      Kind regards,

      Ladis Click image for larger version

Name:	2020-02-17 (4).png
Views:	225
Size:	437.2 KB
ID:	1087412

      Comment


        #33
        Hello Pladijske,

        Thank you for your reply.

        Can you confirm what the possible values returned by your indicator are so I may create something similar? My testing won't be as accurate but that way I can at least approximate.

        The first thing to check when having issues with IB data is that you are running the correct version of either TWS or IB Gateway to work with NinjaTrader. NinjaTrader 8 requires that you use one of the following:You can find the version number of the one you're using on the splash screen displays when it starts up (sometimes called the Build Number). If the Version/Build number is different from what's listed above, you'll need to first uninstall the existing TWS or IB Gateway and install the one linked above.

        The problem with other versions is that while they may work, they aren't guaranteed to do so, and can definitely cause issues with receiving data.

        If you've got the correct version, the next thing to try is starting in Safe Mode.

        Safe Mode will prevent NinjaTrader from:
        • Loading workspaces.
        • Connecting on start-up.
        • Loading custom assemblies.
        • Getting instrument updates from the server.
        To enable safe mode, please use the following steps:
        • Exit NinjaTrader.
        • Hold the CONTROL key and double click the NinjaTrader icon.
        • Keep the CONTROL key held down until you see the Control Center.
        • You can verify you are in safe mode by going to Help -> About.
        Once in Safe Mode, you'll initially just see you'll need to manually connect to your IB connection, then open a few charts to test. If you open up an FDAX 03-20 chart in Safe Mode, do you see data moving as you'd expect?

        If so, we're likely looking at a problem with your workspace. As a further test, please take the following steps to force NinjaTrader to start without your saved workspace. You will have the option to reopen these after our tests.
        • Shut down NinjaTrader
        • Navigate to (My) Documents\NinjaTrader 8\workspaces
        • Move all of the files in this folder to a new location. For example, you can drag them to the desktop temporarily.
        • Restart NinjaTrader 8 which should start up with a blank workspace
        • Once NinjaTrader has started with just the Control Center, please open a new chart with no custom bar types/indicators/templates and test for issues.
        • *Please note this new blank workspace will be named Untitled1.
        If there are no issues on this new workspace, please shut down NinjaTrader, and then drag your previous workspace files from their temporary location back to the Documents\NinjaTrader 8\workspaces folder. Then, relaunch NinjaTrader 8, and from the Control Center, click Workspaces, and re open your existing workspace(s).

        If this reintroduces issues, I would suggest rebuilding your workspace(s), adding 1 instrument/indicator/drawing tool at a time. Please keep track of what instruments/indicators you add back in so that we can narrow down what is causing the issue if the issue returns. I also suggest making a backup of your workspace so we can restore a backup if the issue returns.

        Here is a link showing how to make a backup in NinjaTrader 8: https://ninjatrader.com/support/help...up_archive.htm

        Thanks in advance; I look forward to assisting you further.


        Kate W.NinjaTrader Customer Service

        Comment


          #34
          Dear Kate,

          When I started in safe mode as you suggested. It works ok. It takes +/- 1 min before the bars arrive on the chart but that is normal I guess.
          I also did step 2. But again when I exited safe mode and restarted without the workspaces the same problem reoccured.

          Is it possible that there are issues with the chart template (I have 2 indicator that load automaticly when opening a new chart) and if so, why didn't I have any issues with it the past 3 weeks?
          And why is there only a problem with the FDAX and NOT with the YM even it loads the same indicators perfectly???

          Kind regards,
          Ladis

          Comment


            #35
            Hello Pladijske,

            Thank you for your reply.

            Did you also confirm that your version of either TWS or IB Gateway is the correct version?

            If so, let's have you try running a repair on the installation. To do so, go to the Uninstall a Program section of the Windows Control Panel. Once there, find NInjaTrader in the list, right click on it and select Repair. Does the repair complete successfully, or do you encounter an error? Usually if it does error, it will tell you it can't find a .tmp file.

            Also, I didn't see that you answered this question so I may test your strategy:

            Can you confirm what the possible values returned by your indicator are so I may create something similar? My testing won't be as accurate but that way I can at least approximate.
            Thanks in advance; I look forward to assisting you further.
            Kate W.NinjaTrader Customer Service

            Comment


              #36
              Dear Kate,

              The possible values are 2 or 3. If 2 then target profit is 20 pips if 3 then target profit is 30 pips. But as the index sometimes goes down first you can just try a strategie that buys a future at let's say 1000 and call it "first", then 980 "second , 970 "thirth" and 960 "last" and then sell last and thirth and then see what the average price is.

              About the data: The TWS is up to date. i also did the repair with no improvement a full uninstall and reinstall and now I am testing everything on an other PC. I downloaded NT8 and TWS. And everything seems to work fine on this one (also windows10).
              I will now transfer my workspaces and see what happens.

              Do you have any suggestions on how to prevent such strange behavior?

              Kind regards,

              Ladis

              Comment


                #37
                Hello Pladijske,

                Thank you for your reply.

                Great, I will work on testing.

                As far as the data issue, could be a number of things, really. If it's working fine on another PC on the same network, I'd say it's more likely to be a problem within Windows, possibly a firewall issue. Does the other computer you're using have the same anti-virus/firewall software as the one you were having the issue on?

                Are you using the same internet connection for both PCs? Is it a wired or WiFi connection?

                Thanks in advance; I look forward to assisting you further.
                Kate W.NinjaTrader Customer Service

                Comment


                  #38
                  Dear Kate,

                  Concerning the data issue. Could it be possible that the problem originates due to the fact that I close down at 22:30 local Brussels Time and reboot at 07:00?
                  When I leave my pc in "sleeping" mode and restart the next day, log in to IB ,the chart starts with the new data at 07:00 and leaves a gap between 22:30 and 07:00.

                  I normally do the following: Close the chart and reopen one with different data series>days to load or I do reload all historical data (which can take a very long time.

                  What do you suggest is the best way? Because, when I go live and buy the platform, what happens when I (am forced to by IB to) log off?
                  What would be the best "routine" to have the least problems with the data flow?

                  Kind regards,

                  Ladis

                  Comment


                    #39
                    Hello Pladijske,

                    Thank you for your reply.

                    First, this definitely sounds like Windows is disabling your internet connection when it goes to sleep. You can set it to not do that. Here's a publicly available link that goes over a number of steps you can take to keep Windows from shutting off your internet connection (and with it, your IB connection) when the PC sleeps:



                    It is a known situation where TWS will force a disconnection once per day. Many users report that IB Gateway does not exhibit this behavior, so we may suggest using IB Gateway instead to keep the connection running.

                    NinjaTrader currently cannot automatically reconnect in the event of a broker side disconnection and also would not be able to automatically re-enable strategies. We are tracking interest in providing that sort of functionality in the feature request ticket ID SFT-2395. I have added a vote on your behalf. Note that these are internal tracking numbers and we cannot offer an ETA for implementation. You may check the Release Notes page of the Help Guide to see if a feature has been added in a new release of NinjaTrader:

                    Release Notes - https://ninjatrader.com/support/help...ease_notes.htm

                    I will do some further testing with your script and get back to you on that.

                    Thanks in advance; I look forward to assisting you further.
                    Kate W.NinjaTrader Customer Service

                    Comment


                      #40
                      Hello Pladijske,

                      Thanks for your patience.

                      I realized after some testing that I was focused on the wrong thing - I was focused on the strategy but what this really depends on is your setting under Tools > Options > Trading for "Use FIFO for position average price calculations", a setting I had completely forgotten existed, to be quite honest. When this is checked, instead of maintaining the average price until the position is fully flat again, when you scale out, it will match your first entry with your first exit, and then second entry with second exit, and recalculate the Average Price accordingly, so when you access the position average price the next day it should have recalculated. There's not an option to match them LIFO (Last in, first out) for that which is more how you were describing, however.

                      Try it with that checked - I think you'll find it'll recalculate closer to the way you're expecting.

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

                      Comment


                        #41
                        Dear Kate,

                        Many thanks for your answer. I have been ill so couldn't reply.
                        I tried the FIFO but it worsened the effect because, when I first buy and then it goes down, and at the end of the day I have to sell 1 future it will be the "most expensive" one :-)
                        Perhaps that in the future there will be an "LIFO" :-)

                        Another question: When I buy a license. Can I use it simultanously on 2 pc's at home?
                        Kind regards,
                        Ladis

                        Comment


                          #42
                          Hello Pladijske,

                          Thank you for your reply.

                          I have added a vote for you to a current feature request to be able to use LIFO for the Average Price. This request is being tracked under the number SFT-3795.

                          As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

                          Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

                          As far as the license, you are only able to use your license on one PC at a time. You would need an additional license or to use a Simulation key to use NinjaTrader on 2 different PCs simultaneously.

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

                          Comment


                            #43
                            Dear Kate,

                            I don't know how to put the code in a box so that it is easier for you to read so sorry for that.
                            I hereby send a strategy.
                            I today, after reading trough the forum and watching video's, added an extra buy condition.
                            My strategy "runs" on the 1 min dax.
                            I now want to add as a condition: That the close of the 30 min candle/timeframe of the FDAX 06-20 must be greater than the SMA(200) of the 30 min candle/timeframe of the FDAX 06-20
                            So I added it as a extra dataseries but the results are not ok.
                            It looks as if it doesn't work with the extra condition.
                            What do I do wrong?

                            Kind regards,
                            Ladis

                            namespace NinjaTrader.NinjaScript.Strategies
                            {
                            public class LongDaxStrategyTest020420 : Strategy
                            {
                            double indicator,target2,target3;

                            private LongDax1HoogsteRendement0602 LongDax1HoogsteRendement06021;
                            private SMA SMA1;

                            protected override void OnStateChange()
                            {
                            if (State == State.SetDefaults)
                            {
                            Description = @"Geeft een kooporder als de indicator 2 of meer is";
                            Name = "LongDaxStrategyTest020420";
                            Calculate = Calculate.OnBarClose;
                            EntriesPerDirection = 5;
                            EntryHandling = EntryHandling.AllEntries;
                            IsExitOnSessionCloseStrategy = false;
                            ExitOnSessionCloseSeconds = 30;
                            IsFillLimitOnTouch = false;
                            MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                            OrderFillResolution = OrderFillResolution.Standard;
                            Slippage = 2;
                            StartBehavior = StartBehavior.WaitUntilFlat;
                            TimeInForce = TimeInForce.Gtc;
                            TraceOrders = true;
                            RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                            StopTargetHandling = StopTargetHandling.ByStrategyPosition;
                            BarsRequiredToTrade = 20;
                            // Disable this property for performance gains in Strategy Analyzer optimizations
                            // See the Help Guide for additional information
                            IsInstantiatedOnEachOptimizationIteration = true;
                            }
                            else if (State == State.Configure)
                            {
                            AddDataSeries("FDAX 06-20", Data.BarsPeriodType.Minute, 30, Data.MarketDataType.Last);
                            }
                            else if (State == State.DataLoaded)
                            {

                            LongDax1HoogsteRendement06021 = LongDax1HoogsteRendement0602(Close, 28, 35, 19, 14);
                            SMA1 = SMA(Closes[1], 200);
                            }
                            }

                            protected override void OnBarUpdate()
                            {
                            if (BarsInProgress != 0)
                            return;

                            if (CurrentBars[0] <1 || Currentbars[1] <0)
                            return;

                            // Set 1
                            if ((Times[0][0].TimeOfDay > new TimeSpan(8, 10, 0))
                            &amp;amp;&amp;amp; (Times[0][0].TimeOfDay &lt; new TimeSpan(17, 00, 0))
                            &amp;amp;&amp;amp; (Position.Quantity == 0)
                            &amp;amp;&amp;amp; (SMA1[0] > Closes[1][0]))
                            {
                            if ((LongDax1HoogsteRendement06021[0] == 2))
                            {
                            SendMail(@"[email protected]", @"DAX1 HR=1", @"Signaal Dax1min Hoogste Rendement = 1");
                            }
                            if ((LongDax1HoogsteRendement06021[0] == 2))
                            {
                            //Draw.VerticalLine(this, @"DaxLong1min Vertical line_1", 0, Brushes.Red, DashStyleHelper.Solid, 2);
                            EnterLong(2, @"EERSTE2");
                            indicator=2;
                            target2=High[1]*0.002076;
                            SendMail(@"[email protected]", @"DAX1 HR=2", @"Signaal Dax1min Hoogste Rendement = 2");
                            }
                            else if ((LongDax1HoogsteRendement06021[0] == 3))
                            {
                            //Draw.VerticalLine(this, @"DaxLong1min Vertical line_1", 0, Brushes.Green, DashStyleHelper.Solid, 2);
                            EnterLong(2, @"EERSTE3");
                            indicator=3;
                            target3=High[1]*0.003;
                            SendMail(@"[email protected]", @"DAX1 HR=3", @"Signaal Dax1min Hoogste Rendement = 3");
                            }
                            }

                            // Set 2
                            if ((Close[0] &amp;lt; (Position.AveragePrice - 30) )
                            &amp;amp;&amp;amp; (Position.Quantity == 2))
                            {
                            EnterLong(1, @"TWEEDE");
                            SendMail(@"[email protected]", @"DAX1 HR TWEEDE", @"Signaal Dax1min Hoogste Rendement TWEEDE");
                            }

                            // Set 3
                            if ((Close[0] &amp;lt; (Position.AveragePrice - 50) )
                            &amp;amp;&amp;amp; (Position.Quantity == 3)
                            &amp;amp;&amp;amp; (Times[0][0].TimeOfDay &amp;lt; new TimeSpan(17, 25, 0))
                            &amp;amp;&amp;amp; (Times[0][0].TimeOfDay &amp;gt; new TimeSpan(9, 01, 0)))
                            {
                            EnterLong(1, @"DERDE");
                            SendMail(@"[email protected]", @"DAX1 HR DERDE", @"Signaal Dax1min Hoogste Rendement DERDE");
                            }

                            // Set 4
                            if ((Position.Quantity == 4)
                            &amp;amp;&amp;amp; (Close[0] &amp;lt; (Position.AveragePrice - 100) )
                            &amp;amp;&amp;amp; (Times[0][0].TimeOfDay &amp;lt; new TimeSpan(17, 25, 0))
                            &amp;amp;&amp;amp; (Times[0][0].TimeOfDay &amp;gt; new TimeSpan(9, 01, 0)))
                            {
                            EnterLong(1, @"LAATSTE");
                            SendMail(@"[email protected]", @"DAX1 HR LAATSTE", @"Signaal Dax1min Hoogste Rendement LAATSTE");
                            }
                            // // Set 5
                            // if ((Times[0][0].TimeOfDay &amp;gt; new TimeSpan(17, 25, 0))
                            // &amp;amp;&amp;amp; (Position.Quantity &amp;gt;=0))
                            // {
                            // ExitLong(Position.Quantity,"","");
                            // ExitLong(1, "", @"LAATSTE");
                            // ExitLong(1, "", @"DERDE");
                            // }
                            // else if ((Times[0][0].TimeOfDay &amp;gt; new TimeSpan(17, 55, 0))
                            // &amp;amp;&amp;amp; (Position.Quantity == 4))
                            // {
                            // ExitLong(1, "", @"DERDE");
                            // }
                            if ((LongDax1HoogsteRendement06021[0] == 2) &amp;amp;&amp;amp; indicator ==2)
                            {
                            SetProfitTarget(CalculationMode.Ticks, target2);
                            }
                            if ((LongDax1HoogsteRendement06021[0] == 3) &amp;amp;&amp;amp; indicator ==3)
                            {
                            SetProfitTarget(CalculationMode.Ticks, target3);
                            }
                            }

                            #region Properties
                            // [NinjaScriptProperty]
                            // [Range(1, int.MaxValue)]
                            // [Display(Name="Profittarget", Description="Number of points from entry", Order=1, GroupName="Parameters")]
                            // public int Profittarget
                            // { get; set; }
                            #endregion

                            }
                            }

                            Comment


                              #44
                              Hello Pladijske,

                              Thank you for your reply.

                              It looks like the copy and paste may have changed some of the code. Can you try again to post it, but use Code tags so the forum doesn't automatically change bits? You can do this by clicking the A icon in the upper right of the reply box, then clicking the # button. This will bring up a set tags that say CODE inside. Paste the strategy between those tags and it should show up in the box like you mentioned.

                              Thanks in advance; I look forward to assisting you further.
                              Kate W.NinjaTrader Customer Service

                              Comment


                                #45
                                Hello Kate,

                                I managed to resolve this problem by trial and error :-)
                                I still have another question:

                                I have a strategy and want the strategy to exitlong everything when the Low of the 1 minute candle crosses below the SMA90 of the 30min candle.
                                I defined the SMA2 in the state.dataloaded (as SMA2 = SMA(Closes[1], 90)

                                But I get errors when formulating the condition:
                                Code:
                                if ((CrossBelow(Low, SMA2, 1))
                                                 && (Position.Quantity >= 4))
                                            {
                                                ExitLong(Position.Quantity, "", "");
                                            }
                                Do you have any idea what I am doing wrong?

                                Many thanks

                                Ladis

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by bortz, 11-06-2023, 08:04 AM
                                47 responses
                                1,602 views
                                0 likes
                                Last Post aligator  
                                Started by jaybedreamin, Today, 05:56 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post jaybedreamin  
                                Started by DJ888, 04-16-2024, 06:09 PM
                                6 responses
                                18 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by Jon17, Today, 04:33 PM
                                0 responses
                                4 views
                                0 likes
                                Last Post Jon17
                                by Jon17
                                 
                                Started by Javierw.ok, Today, 04:12 PM
                                0 responses
                                12 views
                                0 likes
                                Last Post Javierw.ok  
                                Working...
                                X