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

New

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

    New

    Hi I've programmed in several languages but I'm new here so a little help would be great:

    How do I code RVI example I've looking for when the value crosses the signal line so something like RVi[14](0) > RVi[14] (0) Signal

    How do I code getting the current time live if CurrentTime > 945 and Current time < 1200

    How do I use a flag integer example if something is true x=1 if its false x=0 then if x=1 then begin.

    I have a TradeStation strategy that I'm writing in Nija trader.

    All of your help would be greatly appreciated.

    Thank You

    RM


    #2
    Hello RM,

    Thank you for reaching out.

    Since you are getting started with NinjaTrader, I suggest keeping the following post handy as it contains many tips and resources for working with NinjaScript:


    I have addressed your specific questions below:
    • How do I code RVI example I've looking for when the value crosses the signal line so something like RVi[14](0) > RVi[14] (0) Signal
    • How do I code getting the current time live if CurrentTime > 945 and Current time < 1200
    • How do I use a flag integer example if something is true x=1 if its false x=0 then if x=1 then begin.
      • It sounds like you may be referring to an "if else" statement or setting up conditions. The following publicly available resource covers the basics of how to use these types of conditions and statements in C#: https://www.w3schools.com/cs/cs_conditions.php
    Please feel free to reach out with any additional questions or concerns.​
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hi Emily

      What si the RVI Signal line code? The value line is RVI(14) but I don't know what the RVI Signal line is. Is the current time just Time? In the example, you sent the link to just cross over an SMA not the RVI signal line.

      Comment


        #4
        Hello RM,

        Thank you for your reply.

        The RVI indicator in NinjaTrader only plots the value and not a signal line. The value ranges from 0 to 100 and it is mentioned in the description of the indicator that "Readings below 50 indicate that the direction of volatility is to the downside and that you should be looking to sell, readings above 50 indicate that the direction of volatilty is to the upside and that you should be looking to buy." If you consider 50 to be the signal line, you could add logic that checks if the RVI value crosses above 50 or crosses below 50.

        Time is kept in a series:


        You can get the time for a bar with Time[int barsAgo]


        If you want the time of the current bar, that would be Time[0] using 0 as the barsAgo index. For more details on making sure you are referencing the correct bar:


        I sent a link to set up an SMA crossover as an example of how to set up crossover conditions. It can also be helpful, whether you plan on using the Strategy Builder or not, to set up conditions and actions in the Strategy Builder window then click on the "View Code" button to see how the builder set up the logic behind it. Here are some examples of common conditions and actions in the builder:



        Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          I'm confused so what is the red and green line, in the picture there are two lines typically the green line is the value and the red line is the signal


          Attached Files

          Comment


            #6
            Hello RMin101,

            Thank you for your reply.

            It seems you have plotted the "Relative vigor index" indicator rather than the RVI (which is Relative Volatility Index). The indicators are listed in alphabetical order and RVI should be a little further down the list than Relative vigor index.

            Thank you for your patience.

            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Great I found it but I'm not sure how to define which line is which?

              If I had to guess it would be the indicators source data of 1 for the value and 0 fo the signal.

              I'm trying to do if the RVI(14)(Value) is > RVI(14)(Signal) then begin...


              Still don't understand how to get the current time, CurrentTime.

              Are there more sample strategies I can look at besides the few that come with Ninja Trader?


              Description


              The Relative Vigor Index measures the strength of a trend by comparing an instruments closing price to its price range. It's based on the fact that prices tend to close higher than they open in up trends, and closer lower than they open in downtrends.

              Syntax


              RelativeVigorIndex(int period)

              RelativeVigorIndex(ISeries<double> input, int period)

              Return Value


              double; Accessing this method via an index value [int barsAgo] returns the indicator value of the referenced bar.

              Parameters
              input Indicator source data (?)
              period Number of bars used in the calculation
              Examples
              // Prints the current value of a 10 period Relative Vigor Index
              double value = RelativeVigorIndex(10)[0];
              Print("The current Relative Vigor Index value is " + value.ToString());

              Comment


                #8
                Hello RM,

                Thank you for your reply.

                At the beginning of this thread, my understanding was that you were referring to the RVI (Relative Volatility Index) indicator which I shared the link to previously:


                Now, you seem to be referring to Relative Vigor Index:


                Please clarify which indicator you are wanting to work with. You may view the source code for these indicators in the NinjaScript Editor within the Indicators folder.

                Does the time comparison demonstrated in the reference sample for creating a time filter not suit your needs? If not, please provide a description of how time will be used and compared in your strategy so I may better understand and assist you.


                There are reference samples of different strategies that may be found here:


                You could also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.

                Please let me know if I may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  Hi, Emily, I'm trying to use the Relative Vigor Index when viewing the indicators there are two lines Red and green in my picture attached RelativeVigorIndex(10)[0]; How do see if the value line is greater than the signal line?

                  Thank you so much for your help and patience!

                  RM
                  Attached Files

                  Comment


                    #10
                    Hello RM,

                    Thank you for clarifying.

                    Now I have a better understanding of what you are looking for. To get the value from the signal plot, you may use the following syntax:

                    RelativeVigorIndex(int period).Signal[int barsAgo]
                    -or-
                    RelativeVigorIndex(ISeries<double> input, int period).Signal[int barsAgo]

                    I will submit a suggestion to add this information to the help guide for other users to reference.

                    Here is a snippet including a print statement that prints the values:
                    Code:
                    private RelativeVigorIndex myRVI;
                    protected override void OnStateChange()
                    {
                    else if (State == State.DataLoaded)
                    {
                    myRVI = RelativeVigorIndex(14);
                    }
                    }
                    
                    protected override void OnBarUpdate()
                    {
                    if (CurrentBar < 14)
                    return;
                    Print("Current bar time: " + Time[0] + "RVI: " + myRVI[0] + " Signal: " + myRVI.Signal[0]);
                    }
                    }
                    Please let us know if we may be of further assistance.​
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi
                      Thank you for all of your help! I'm getting an error CS01303 the name myrvi does not exist, but I have it under the public class private RelativeVigorIndex myRVI; that's where the other indicators seem to be, what am I missing? I also have the myRVI = RelativeVigorIndex(14); under my other else if's, is the [0] the current bar or what the bar setting is for the indicator?

                      Comment


                        #12
                        Hello RMin101,

                        Thank you for your note.

                        My example is following the best practice "referencing indicator methods" found at the following link:


                        As long as you declare the indicator at the class level, then initialize it somewhere such as OnStateChange() when State == State.DataLoaded, you should be able to avoid compile errors:
                        Code:
                        private RelativeVigorIndex myRVI;
                        protected override void OnStateChange()


                        Here is a screenshot of the indicator I created for that snippet. It compiles without errors:


                        Please let me know if I may be of further assistance.
                        Emily C.NinjaTrader Customer Service

                        Comment


                          #13
                          That's amazing but I'm so sorry I believe that's what I have here is my code, what am I missing? I deleted some code so the } may not match but this should show what my issue is

                          private RelativeVigorIndex myRVI;

                          protected override void OnStateChange()
                          {
                          if (State == State.SetDefaults)
                          {
                          Description = @"NQ Exits 4-24-23";
                          Name = "NQ51023";
                          Calculate = Calculate.OnBarClose;
                          EntriesPerDirection = 1;
                          EntryHandling = EntryHandling.AllEntries;
                          IsExitOnSessionCloseStrategy = false;
                          ExitOnSessionCloseSeconds = 30;
                          IsFillLimitOnTouch = false;
                          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                          OrderFillResolution = OrderFillResolution.Standard;
                          Slippage = 0;
                          StartBehavior = StartBehavior.WaitUntilFlat;
                          TimeInForce = TimeInForce.Gtc;
                          TraceOrders = false;
                          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("NQ 06-23", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                          AddDataSeries("NQ 06-23", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
                          }
                          else if (State == State.DataLoaded)
                          {

                          myRVI = RelativeVigorIndex(14);
                          }
                          }



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

                          if (CurrentBars[0] < 0)
                          return;

                          // Set 1
                          if myRVI[0] > myrvi.sIGNAL[0]

                          )

                          EnterLong(1, "Long");
                          {
                          }

                          }



                          }
                          }​

                          Comment


                            #14
                            and XAverage(Close,MASlow) - XAverage(Close,MAFast) > 20 how do I do this in Ninja code?

                            Comment


                              #15
                              Hello RM,

                              Thank you for your reply.

                              Syntax and casing matters in NinjaScript and C#. For example, the following is likely the cause of the error:
                              Code:
                              if myRVI[0] > myrvi.sIGNAL[0]
                              if you have specifically named your instance of the indicator to be "myRVI" then you need to use the same uppercase/lowercase letters throughout your script when referencing it. "myrvi" is all lowercase and will throw an error. It should be, specifically, "myRVI.Signal[0]" or else you will receive errors.

                              The XAverage() function seems to be specific to TradeStation. It may be the same as the EMA in NinjaTrader:


                              That said, we do not provide hands-on script conversion services. It is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                              Through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                              As I previously mentioned:
                              You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
                              This thread will also remain open in case other members of the forum community would like to assist you with this conversion.

                              Thank you for using NinjaTrader.​
                              Emily C.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by funk10101, Today, 11:35 AM
                              0 responses
                              0 views
                              0 likes
                              Last Post funk10101  
                              Started by samish18, Today, 11:26 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post samish18  
                              Started by Trader146, 03-29-2024, 01:22 PM
                              2 responses
                              14 views
                              0 likes
                              Last Post Trader146  
                              Started by tsantospinto, 04-12-2024, 07:04 PM
                              7 responses
                              127 views
                              0 likes
                              Last Post aligator  
                              Started by futtrader, 04-21-2024, 01:50 AM
                              5 responses
                              56 views
                              0 likes
                              Last Post NinjaTrader_Eduardo  
                              Working...
                              X