Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ADXVMA with Ninja 8 strategy builder

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

    #16
    Hello willwin,

    Thank you for that information.

    If you are wanting to check for the exact moment that the crossover condition occurs, you would need to set the indicator's Calculate mode to OnEachTick. This will have the indicator calculate for each incoming tick instead of only on the close of each bar.

    Please note that for any crossover based on price movement, you may get hundreds of crosses in the same bar. If you decide to detect when the crossover condition happens and set the condition so it only happens once per bar, there is the risk that when you look at the indicator on a chart, if the price pulls away, it may appear that the crossover condition did not happen in the Market Analyzer column.

    See the help guide link below for more information.
    Calculate - https://ninjatrader.com/support/help.../calculate.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #17
      ok i tried fixing the code, but the results are still not working.
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class CrossDetectionForMarketAnalyzerExampleModified2 : Indicator
      {
      private int last;
      private bool triggered;
      private Brush Brush1;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"";
      Name = "CrossDetectionForMarketAnalyzerExampleModifie d2";
      Calculate = Calculate.OnEachTick;
      IsOverlay = false;
      IsSuspendedWhileInactive = false;
      AddPlot(Brushes.Transparent, "SignalPlot");
      }
      else if (State == State.Configure)
      {
      Brush1 = new SolidColorBrush((Color)ColorConverter.ConvertFromS tring("#FF333333"));
      Brush1.Freeze();
      }
      else if (State == State.DataLoaded)
      {
      last = 0;
      triggered = false;
      }
      }

      protected override void OnBarUpdate()
      {
      // this is where we reset everything on a new bar
      if (IsFirstTickOfBar || Calculate == Calculate.OnEachTick)
      {
      Value[0] = 0;
      triggered = false;
      last = 0;
      }

      // if the OnEachTick crosses above EMA(55), set the plot to 1
      if (CrossAbove(Close, EMA(55), 1) && last != 1)
      {
      Alert(@"CrossAboveAlert", Priority.Medium, @"OnEachTick crossed above EMA(55)", @"", 0, Brushes.Transparent, Brush1);
      // set the value
      Value[0] = 1;
      // we set last to 1 so that we can re-trigger the cell color or re-trigger an alert
      last = 1;
      // we set triggered to true so that the alerts do not continue alerting on each new tick after a cross is detected
      triggered = true;
      }
      // if the OnEachTick crosses below EMA(55), set the plot to -1
      else if (CrossBelow(Close, EMA(55), 1) && last != -1)
      {
      Alert(@"CrossAboveAlert", Priority.Medium, @"OnEachTick crossed below EMA(55)", @"", 0, Brushes.Transparent, Brush1);
      Value[0] = -1;
      last = -1;
      triggered = true;
      }
      // if resetAfterTrigger is true, then we are using alerts.
      // Set the value back to 0 so that the alerts stop and set triggered to false and ready for a new trigger
      else if (ResetAfterTrigger == true && triggered == true)
      {
      Value[0] = 0;
      triggered = false;
      }
      }

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> SignalPlot
      {
      get { return Values[0]; }
      }

      [NinjaScriptProperty]
      [Display(Name = "Reset after trigger", Order = 0, GroupName = "Parameters")]
      public bool ResetAfterTrigger
      { get; set; }
      }
      }

      #region NinjaScript generated code. Neither change nor remove.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private CrossDetectionForMarketAnalyzerExampleModified2[] cacheCrossDetectionForMarketAnalyzerExampleModifie d2;
      public CrossDetectionForMarketAnalyzerExampleModified2 CrossDetectionForMarketAnalyzerExampleModified2(bo ol resetAfterTrigger)
      {
      return CrossDetectionForMarketAnalyzerExampleModified2(In put, resetAfterTrigger);
      }

      public CrossDetectionForMarketAnalyzerExampleModified2 CrossDetectionForMarketAnalyzerExampleModified2(IS eries<double> input, bool resetAfterTrigger)
      {
      if (cacheCrossDetectionForMarketAnalyzerExampleModifi ed2 != null)
      for (int idx = 0; idx < cacheCrossDetectionForMarketAnalyzerExampleModifie d2.Length; idx++)
      if (cacheCrossDetectionForMarketAnalyzerExampleModifi ed2[idx] != null && cacheCrossDetectionForMarketAnalyzerExampleModifie d2[idx].ResetAfterTrigger == resetAfterTrigger && cacheCrossDetectionForMarketAnalyzerExampleModifie d2[idx].EqualsInput(input))
      return cacheCrossDetectionForMarketAnalyzerExampleModifie d2[idx];
      return CacheIndicator<CrossDetectionForMarketAnalyzerExam pleModified2>(new CrossDetectionForMarketAnalyzerExampleModified2(){ ResetAfterTrigger = resetAfterTrigger }, input, ref cacheCrossDetectionForMarketAnalyzerExampleModifie d2);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.CrossDetectionForMarketAnalyzerExampleM odified2 CrossDetectionForMarketAnalyzerExampleModified2(bo ol resetAfterTrigger)
      {
      return indicator.CrossDetectionForMarketAnalyzerExampleMo dified2(Input, resetAfterTrigger);
      }

      public Indicators.CrossDetectionForMarketAnalyzerExampleM odified2 CrossDetectionForMarketAnalyzerExampleModified2(IS eries<double> input , bool resetAfterTrigger)
      {
      return indicator.CrossDetectionForMarketAnalyzerExampleMo dified2(input, resetAfterTrigger);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.CrossDetectionForMarketAnalyzerExampleM odified2 CrossDetectionForMarketAnalyzerExampleModified2(bo ol resetAfterTrigger)
      {
      return indicator.CrossDetectionForMarketAnalyzerExampleMo dified2(Input, resetAfterTrigger);
      }

      public Indicators.CrossDetectionForMarketAnalyzerExampleM odified2 CrossDetectionForMarketAnalyzerExampleModified2(IS eries<double> input , bool resetAfterTrigger)
      {
      return indicator.CrossDetectionForMarketAnalyzerExampleMo dified2(input, resetAfterTrigger);
      }
      }
      }

      #endregion


      Attached Files

      Comment


        #18
        Another poor result from code and market analyzer using last 2 bars. supposed to be a cross below 55EMA on last bar.
        ...................
        ok I put 1 tick on the chart with the market analyzer and appears to somewhat follow that.
        so how do i tell it to bypass all tick close until the daily closing price close finally appears at 4:00pm for example?
        or simply just produce results off last close?
        and eliminating any other chart that is already >/< the 55EMA?

        would I be able to call you direct on this?

        I just noticed on the weekly chart on AAPL the chart shows the 55EMA at 101.70, but the market analyzer displays 131.87.
        So that would be one reason why this isn't working as I expect.
        Attached Files
        Last edited by willwin; 01-20-2021, 01:14 PM.

        Comment


          #19
          Hello willwin,

          Thank you for your note.

          In the second screenshot you shared, it seems that the last bar is above the 55-period EMA.

          I see that you are using a Daily Chart in your screenshot. How many days of data are being loaded for the Data Series on the chart? How many days of data are you loading in the Market Analyzer indicator column?

          Please ensure that the Days to Load property is the same for both the Data Series on the chart and the indicator column in the Market Analyzer. If the indicator in the Market Analyzer column is not using the same number of Days to Load as the Data Series in the chart, then the EMA would not be calculated the same.

          After testing the code you provided on a 1-minute data series with 3 days to load I am seeing the correct output in the Market Analyzer column. This is seen in the screenshot attached below. When the last bar crosses above the 55-period EMA, a 1 is displayed in the Market Analyzer column. When the last bar crosses below the 55-period EMA, a -1 is shown in the Market Analyzer column.

          Click image for larger version

Name:	2021-01-20_12-35-04.png
Views:	52
Size:	76.8 KB
ID:	1137614

          Click image for larger version

Name:	2021-01-20_12-55-12.png
Views:	37
Size:	75.5 KB
ID:	1137617

          Please see the following images regarding the settings used to test this. Do you see the same behavior occur when testing the indicator in the Market Analyzer column using these settings?

          Click image for larger version

Name:	2021-01-20_12-35-31.png
Views:	40
Size:	39.9 KB
ID:	1137615
          ​​​​​​

          Click image for larger version

Name:	2021-01-20_12-52-22.png
Views:	38
Size:	77.6 KB
ID:	1137616

          Please let us know if we may assist further.
          Brandon H.NinjaTrader Customer Service

          Comment


            #20
            I only get the CrossBelow in market Analyzer search not a cross above.
            I am assuming there has to be at least one instrument that has the vortex(13) has crossed above.
            Can you see something in my code that is not allowing the CrossAbove feature?
            thks
            Raymond
            willwin
            Attached Files

            Comment


              #21
              Hello willwin,

              Thank you for your note.

              I do not see anything specific in your code that would cause any error. However, when testing the Vortex(13) indicator on my end, I am seeing an output of around 0.98 - 1.65 which means your condition may not be returning true if the current Close does not CrossAbove that value.

              Ultimately, debugging steps should be taken to determine how your script is behaving.

              To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

              In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.
              Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

              Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
              https://ninjatrader.com/support/foru...121#post791121

              Please let me know if I may further assist
              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by nutmame1, Today, 08:26 PM
              0 responses
              8 views
              0 likes
              Last Post nutmame1  
              Started by dr0832, Today, 07:02 PM
              0 responses
              14 views
              0 likes
              Last Post dr0832
              by dr0832
               
              Started by mlurskint8, Today, 05:27 PM
              3 responses
              19 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by SteveTheCPA, Today, 04:54 PM
              0 responses
              10 views
              0 likes
              Last Post SteveTheCPA  
              Started by Unsuitable, Today, 02:42 PM
              2 responses
              14 views
              0 likes
              Last Post Unsuitable  
              Working...
              X