Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with Variables

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

    Problem with Variables

    Hi, Could you help me with this:
    I set my exit signal as following (both as a int):
    1)When CCI hits 50 exit long position (Variable nVLong).
    2)When CCI hits -50 exit short position (Variable nVShort).
    There is no problem when I am in Long position strategy always exits when CCI hits 50. But when I am in short position it does not work.

    Thanks

    #region Variables
    // Wizard generated variables
    privateint cCIperiod = 14; // Default setting for CCIperiod
    privateint eMA_Q = 5; // Default setting for EMA_Q
    privateint eMA_M = 34; // Default setting for EMA_M
    privateint eMA_S = 102; // Default setting for EMA_S
    privateint nVLong = 50; // Default setting for NVLong
    privateint sL = 18; // Default setting for SL
    privateint nVShort = -50; // Default setting for NVShort
    // User defined variables (add any user defined variables below)
    #endregion
    Last edited by kokos; 05-25-2010, 12:01 PM.

    #2
    Hi kokos,

    Let's start by taking a look at the snippet of code you use for short exit, please provide that.
    TimNinjaTrader Customer Service

    Comment


      #3
      // Condition set 3
      if (CrossBelow(CCI(50), NVLong, 1))
      {
      ExitLong(
      "", "");
      }
      // Condition set 4
      if (CrossAbove(CCI(50), NVShort, 1))
      {
      ExitShort(
      "", "");
      }
      }

      Comment


        #4
        Hi kokos,

        Start by placing Print() in your condition to ensure it's being met...
        More info at - http://www.ninjatrader.com/support/f...ead.php?t=3418

        Do you have SetStopLoss or any Limit order being executed in your code, you may be getting ignored orders, which you can use TraceOrders to verify/diagnose.
        More info at - http://www.ninjatrader.com/support/f...ead.php?t=3627
        TimNinjaTrader Customer Service

        Comment


          #5
          I do have a Stoploss. If I set the exit trigger as a numeric value strategy works fine. Problem is only when I set it as a variable. Can "int" be set as a negative?

          // Condition set 4
          if (CrossAbove(CCI(50), -50, 1))
          {
          ExitShort(
          "", "");
          }
          }

          Comment


            #6
            Hi kokos,

            The int value can be set as a negative.

            How are you using your SetStopLoss? Snippet?
            TimNinjaTrader Customer Service

            Comment


              #7
              Hi,
              I copied the strategy into txt file.
              Attached Files

              Comment


                #8
                Hi kokos,

                Ensure your ExitShort conditions are being met.

                Something like...
                Code:
                // Condition set 4
                if (CrossAbove(CCI(50), -50, 1))
                {
                Print("Condition for ExitShort has been met");
                ExitShort("", "");
                }
                TimNinjaTrader Customer Service

                Comment


                  #9
                  Hello Kokos,

                  The issue may be with the range of values for NVShort. When you initially setup the strategy you have to declare a minimum value. Default here is 1. You can create again through the wizard or change the value in the public property, highlighted below.

                  Code:
                   
                  public int NVShort
                  {
                  get { return nVShort; }
                  set { nVShort = Math.Max([B][COLOR=red]-200[/COLOR][/B], value); }
                  }
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    much appreciated! thanks RyanM

                    Comment


                      #11
                      I have another problem. How can I set my strategy to enter only on trend bars? For example, if I want to enter into long position it has to be a bullish bar.

                      Comment


                        #12
                        Hi kokos,

                        Assuming you define a bullish bar as an up bar, you could set up a condition that only enters on such a bar, something like...

                        Code:
                        if (Close[0] > Open[0]) && other conditions)
                        {
                        do something;
                        }
                        or

                        Code:
                        if (Close[0] > Close[1]) && other conditions)
                        {
                        do something;
                        }

                        You can also use the Rising()
                        More info at - http://www.ninjatrader-support.com/H...de.html?Rising
                        and - http://www.ninjatrader.com/support/f...ad.php?t=19384
                        Last edited by NinjaTrader_Tim; 05-26-2010, 11:16 AM.
                        TimNinjaTrader Customer Service

                        Comment


                          #13
                          I used following for the range bars.
                          && Close[
                          0] >= Close[1])
                          Thank you again really helpful

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          649 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          370 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          109 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          576 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X