Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multible EMA Problem Long Only strategy

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

    #16
    The code always confirm the all "if" statements and for this reason I assume that my if stamtments are wrong. I try to enter "esle" statment but it has several mistakes with the code.

    if (EMA(Fast)[0] > EMA(Medium)[0]);
    {
    Print(CurrentBar + " Fast MA > Medium MA");
    Variable0=1;
    } /// Statement expected
    else /// Invalid expression of "esle" , Expected ;
    {
    Print(CurrentBar + " Fast MA < Medium MA");
    Variable0=0;
    }

    I open the if statment on the NinjaTrader Help but the code structure is the same and for this reason i could not understand where are these new mistakes. Do you have any idea?

    Comment


      #17
      Originally posted by Loukas View Post
      The code always confirm the all "if" statements and for this reason I assume that my if stamtments are wrong. I try to enter "esle" statment but it has several mistakes with the code.

      if (EMA(Fast)[0] > EMA(Medium)[0]);
      {
      Print(CurrentBar + " Fast MA > Medium MA");
      Variable0=1;
      } /// Statement expected
      else /// Invalid expression of "esle" , Expected ;
      {
      Print(CurrentBar + " Fast MA < Medium MA");
      Variable0=0;
      }

      I open the if statment on the NinjaTrader Help but the code structure is the same and for this reason i could not understand where are these new mistakes. Do you have any idea?
      Off the bat, your initial "if" statement executes as a completed null statement, as it is terminated with a semi-colon (emphasis mine), meaning that when you get to the "else" clause, there is no corresponding "if", so you would get an error.

      Which leads me to realize that as all your "if" statements were so terminated, in fact, every single line of your code is executed on every single pass, so your "Long Entry" conditions will be identically true on every single pass.
      Last edited by koganam; 06-19-2011, 10:54 PM.

      Comment


        #18
        Thanks Koganam for the explanation, the semi-colon was causing the errors. I would like to ask you something else, how can I code a statement where RSI is above one certain level?
        - RSI (RSIperiod,RSIsmooth) higher a Number Value
        - RSI(14,3) > 50

        Comment


          #19
          Originally posted by Loukas View Post
          Thanks Koganam for the explanation, the semi-colon was causing the errors. I would like to ask you something else, how can I code a statement where RSI is above one certain level?
          - RSI (RSIperiod,RSIsmooth) higher a Number Value
          - RSI(14,3) > 50
          That depends on which Plot from that indicator you wish to access, as the RSI indicator has 2 plots. While it is possible to just access the default plot, I find that, for me, specificity always trumps dependence on default behavior, unless the default behavior is also the only behavior.

          RSI(14, 3).Avg[0] > 50; //accesses the Avg plot
          RSI(14, 3).Value[0] > 50; //accesses the RSI plot, as it is the plot name is not directly assigned within the indicator.
          RSI(14, 3).Default[0] > 50; //accesses the RSI plot, as it is tagged as "Default" within the indicator properties.
          RSI(14, 3)[0] > 50; //accesses the RSI plot (default)
          RSI(14, 3).Values[0][0]; //always accesses the first plot, no matter how it is designated.
          RSI(14, 3).Values[x][0]; //always accesses the plot that is defined in position "x + 1"
          Last edited by koganam; 06-21-2011, 04:22 PM.

          Comment


            #20
            Hi,

            Do you have any suggestions about possible reasons why this indicator is not illustrated on the chart?

            Initialize()
            Add(new Plot(Color.FromKnownColor(KnownColor.DarkRed), PlotStyle.Line, "Plot0"));

            OnBarUpdate()
            Plot0.Set(((ADX(Close,14)[0]-ADX(Close,14)[1])/(ADX(Close,14)[1]))*100);

            Thanks

            Comment


              #21
              Hi Loukas,

              Are there any error messages in log tab of control center? You likely run into this issue:


              You may also need to convert those calculations into a data series:
              Last edited by NinjaTrader_RyanM1; 07-05-2011, 10:39 AM.
              Ryan M.NinjaTrader Customer Service

              Comment


                #22
                Hi RyanM
                In the Log tab shows me this message

                Error on calling 'OnBarUpdate' method for indicator 'ATrendStrength' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                Plot0.Set(((ADX(Close,14)[0]-ADX(Close,14)[BarsAgo])/(ADX(Close,14)[BarsAgo]))*100);

                I dont believe is a vital to make a dataseries for this indicator exept the Plot0

                Comment


                  #23
                  Yes, issue caused when attempting to access bar objects that don't exist. To resolve, add this line at the top of OnBarUpdate()

                  if (CurrentBar < BarsAgo) return;

                  You're right - likely no data series needed here.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by Loukas View Post
                    Hi,

                    Do you have any suggestions about possible reasons why this indicator is not illustrated on the chart?

                    Initialize()
                    Add(new Plot(Color.FromKnownColor(KnownColor.DarkRed), PlotStyle.Line, "Plot0"));

                    OnBarUpdate()
                    Plot0.Set(((ADX(Close,14)[0]-ADX(Close,14)[1])/(ADX(Close,14)[1]))*100);

                    Thanks
                    Looks like you are accessing an index of 1 when it may not yet exist. What is the message in your log?

                    Comment


                      #25
                      Thanks for your contridution! It needed if (CurrentBar < BarsAgo) return;

                      However, I cannot use the operator " ^ " on this calculation.
                      The message is Operator '^' cannot be applied to operands of type 'double' and 'int'
                      Plot0.Set(((ADX(Close,14)[0]-ADX(Close,14)[BarsAgo])/(ADX(Close,14)[BarsAgo])^4));

                      How can I use this operator with not getting this error ?

                      Comment


                        #26
                        Are you trying to raise to the 4th power? Check the System.Math class for this. Maybe you need Math.Pow() ?
                        Ryan M.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by argusthome, Yesterday, 10:06 AM
                        0 responses
                        18 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        17 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        14 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post TheRealMorford  
                        Started by Mindset, 02-28-2026, 06:16 AM
                        0 responses
                        38 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Working...
                        X