Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

indicator goes off in strategy and messes up chart

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

    indicator goes off in strategy and messes up chart

    I have a strategy that adds indicators but it meses up chart. From this screen it shows one of the ema reaches 0 point on the chart and it messses it up. How can i fix it? i think i configured it correctly.. Its while using market repaly...

    private EMA fastEMA, slowEMA;

    inset defaults:
    FastEMAPeriod = 8;
    SlowEMAPeriod = 34;

    in dataloaded:
    fastEMA = EMA(Close,FastEMAPeriod);
    slowEMA = EMA(Close,SlowEMAPeriod);​
    fastEMA.Plots[0].Brush = Brushes.Blue;
    slowEMA.Plots[0].Brush = Brushes.Cyan;​
    fastEMA.Plots[0].Width = 2;
    slowEMA.Plots[0].Width = 3;​
    AddChartIndicator(fastEMA);
    AddChartIndicator(slowEMA);​​

    in the condition
    fastEMA[0] > sloeEMA[0]

    Click image for larger version

Name:	image.png
Views:	171
Size:	57.4 KB
ID:	1279671

    #2
    Hello tkaboris,

    From the given details I don't see what would be the problem. I would suggest to delete this script and start over by using the strategy builder, That will ensure that valid code is being used to add the indicators and pass data to the instances. To recreate what you have shown you would need to add two user inputs and then create a condition comparing the two indicators. After doing that you can test the strategy to see if you get the same result, if not you can unlock the code and work from there.

    Comment


      #3
      Jesse
      it maybe related to Time issue? when chart messes up i see this message in log

      in setdefaults i have
      Start = DateTime.Parse("06:55", System.Globalization.CultureInfo.InvariantCulture) ;
      End = DateTime.Parse("15:45", System.Globalization.CultureInfo.InvariantCulture) ;​

      and in condition i have
      (Times[0][0].TimeOfDay >= Start.TimeOfDay) && (Times[0][0].TimeOfDay <= End.TimeOfDay)

      [NinjaScriptProperty]
      [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
      [Display(Name = "Start Time", Order = 1, GroupName = "05. Trade Management")]
      public DateTime Start
      { get; set; }​

      Maybe something is wrong here?
      I was getting this code from strategy builder when first created strategy...

      Click image for larger version  Name:	image.png Views:	0 Size:	221.9 KB ID:	1279676
      Last edited by tkaboris; 11-28-2023, 02:43 PM.

      Comment


        #4
        Hello tkaboris,

        I really couldn't say, to make sure you have valid code I would highly suggest using the strategy builder to re generate the file and re test in a new file without other logic you have added.

        The error in the image generally happens if you try to re enable a strategy that was used in a different mode, for example you applied a strategy in playback and now tried to re enable it using a live connection. You need to remove and re apply strategies when testing between different connections.


        Comment


          #5
          tkaboris You should read this thread https://forum.ninjatrader.com/forum/...atabase-errors - what these things seemingly have in common is you're creating DateTimes that have a "Kind" that is not what is expected, and subsequently, the SQLite database seemingly encounters errors.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            QuantKey_Bruce
            if this is an issue how do i modify it? its uses offset and I need user selection to selct time
            "DateTimeOffset.Now.AddDays().DateTime"

            my code regarding Time

            Start = DateTime.Parse("06:55", System.Globalization.CultureInfo.InvariantCulture) ;
            End = DateTime.Parse("15:45", System.Globalization.CultureInfo.InvariantCulture) ;

            Condition
            (Times[0][0].TimeOfDay >= Start.TimeOfDay) && (Times[0][0].TimeOfDay <= End.TimeOfDay)

            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
            [Display(Name = "Start Time", Order = 1, GroupName = "05. Trade Management")]
            public DateTime Start
            { get; set; }

            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
            [Display(Name = "End Time", Order = 2, GroupName = "05. Trade Management")]
            public DateTime End
            { get; set; }​​

            Comment


              #7
              NinjaTrader support would have to look into the issue of why, seemingly, two different users are manipulating DateTimes and subsequently the database has error messages. These things do not seem related, yet, it seems wise to be suspicious of coincidence.
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                Also, the thread I referenced has a reasonable suggestion for a workaround - use .DateTime before you submit any orders with SubmitOrder to get a kind of unknown on the datetimes - if you're not using SubmitOrder I'm not certain there's commonality between the two issues but it seems uncanny that two people are using a time picker in the UI and subsequently have database errors and that these are the two top reports on a search for the error message in question. What are the chances?
                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment


                  #9
                  Hello tkaboris,

                  The error and code do not appear to be related.

                  To confirm, if you remove all logic in OnBarUpdate() and just keep the inputs and print the values of these in OnBarUpdate(), does the error continue?

                  Note, use XmlIgnore() on DataTime and TimeSpan public variables.

                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Do you mean xmlignore like this?

                    [XmlIgnore()]
                    [NinjaScriptProperty]
                    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
                    [Display(Name = "Start Time", Order = 1, GroupName = "05. Trade Management")]
                    public DateTime Start
                    { get; set; }

                    [XmlIgnore()]
                    [NinjaScriptProperty]
                    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
                    [Display(Name = "End Time", Order = 2, GroupName = "05. Trade Management")]
                    public DateTime End
                    { get; set; }​

                    Comment


                      #11
                      Hello tkaboris,

                      Yes, this is correct.

                      DateTime objects cannot be auto serialized so require the XmlIgnore attribute. (You can also serialize using a string property if you want to save the value as demonstrated in the forum post I linked)
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Yesterday, 05:17 AM
                      0 responses
                      63 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      139 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      75 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      45 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      50 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X