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

CCI Strategy

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

    #16
    Thanks, that did help clear up a few of them and I am left with these errors:
    "invalid token 'double' in class, struct, or interface member declaration. This is for "private int setProfitTarget;"

    I also still get the definition errors for "tradePrice" and for "trade".
    Here is how I now have the code:

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class Test2 : Strategy
    {
    #region Variables
    private double tradePrice;
    private double trade = false;
    private int rSIPeriod;
    private int setProfitTarget;
    private int setStopLoss;
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    Add(RSI(RSIPeriod, 1));


    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(RSI(RSIPeriod, 1), Rsilower, 1))
    {
    SetStopLoss(CalculationMode.Price, Low[0]);
    tradePrice = High[2];
    stopPrice = Low[0];
    trade = true;
    }

    // Condition set 2
    if (Close[0] > tradePrice && trade)
    {
    EnterLong();

    trade = false;
    }



    }

    #region Properties
    [Description("Price at which there will be a trade")]
    [GridCategory("Parameters")]
    public double tradePrice
    {
    get { return tradePrice; }
    set { double tradePrice = Math.Max(1, value); }
    }

    [Description("Trade false")]
    [GridCategory("Parameters")]
    public double trade
    {
    get { return trade = false; }
    set { trade = false = Math.Max(1, value); }
    }

    [Description("RSI period")]
    [GridCategory("Parameters")]
    public int RSIPeriod
    {
    get { return RSIPeriod; }
    set { rSIPeriod = Math.Max(1, value); }
    }

    [Description("Profit")]
    [GridCategory("Parameters")]
    public int SetProfitTarget
    {
    get { return setProfitTarget; }
    set { setProfitTarget = Math.Max(1, value); }
    }

    [Description("Loss")]
    [GridCategory("Parameters")]
    public int SetStopLoss
    {
    get { return setStopLoss; }
    set { setStopLoss = Math.Max(1, value); }
    }

    #endregion
    }
    }

    Comment


      #17
      Hello poipoi11,
      You are still assigning the same name for both the property and for its associated variable.

      [Description("Price at which there will be a trade")]
      [GridCategory("Parameters")]
      public double tradePrice
      {
      get { return tradePrice; }
      set { double tradePrice = Math.Max(1, value); }
      }


      There are other similar errors in the code.
      JoydeepNinjaTrader Customer Service

      Comment


        #18
        ok, I have changed those and that seemed to correct it. However it has created additional errors now. Recursive error on the 'trade' and RSiPeriod", And it does now crash Ninja. Think I am going from bad to worse. Can I use the Wizard to accomplish the same?

        Comment


          #19
          You won't be able to accomplish this strategy via the wizard.

          You're still running into the same thing. Take a look at all of the properties you have set.

          You'll want to ensure that you're not using the same name for the property and the variable for each case.
          MatthewNinjaTrader Product Management

          Comment


            #20
            Okay. I will check all of that and be sure they are different.

            Can I check on one thing that generated an error? You earlier suggested I code with this:
            //In Variable region double tradePrice; double trade = false; //in OnBarUpdate if (CrossAbove(RSI(RSIPeriod, 1), Rsilower, 1)) { SetStopLoss(CalculationMode.Price, Low[0]); tradePrice = High[2]; stopPrice = Low[0]; trade = true; }
            Are you sure that the "Double trade = False" is supposed to be a Double parameter and not a boolean?

            Comment


              #21
              [Description("Price at which there will be a trade")]
              [GridCategory("Parameters")]
              public double tradePrice //error1
              {
              get { return tradePrice; }
              set { double tradePrice = Math.Max(1, value); } //error2
              }
              error1: Recursion error. the Property is named the same as the backing store. You will eventually run out of memory, as the program continues trying to set a value that is changing because you are resetting the same value.
              error2: tradePrice has already been declared as the backing store. You should not be declaring it again in the setter. While not an error, there is probably no need to limit its value either.

              Code:
              [
              Description("Price at which there will be a trade")]
              [GridCategory("Parameters")]
              public double [B][COLOR=red]T[/COLOR][/B]radePrice
              {
              get { return tradePrice; }
              set { tradePrice = value; }
              }
              [Description("Trade false")]
              [GridCategory("Parameters")]
              public double trade //error1
              {
              get { return trade = false; } //error2
              set { trade = false = Math.Max(1, value); } //error3
              }
              error1: Same as above. Recursion error.
              error2: You asked the public variable to return a double, then in the getter you set it to a bool. Variable type mismatch.
              error3: Chained operators returning incorrect variable type, inter alia.

              As trade is itself declared improperly in the backing store, I do not know what it is supposed to be, so I cannot correct it completely.

              [Description("RSI period")]
              [GridCategory("Parameters")]
              public int RSIPeriod
              {
              get { return RSIPeriod; } //error1
              set { rSIPeriod = Math.Max(1, value); }
              }
              error1: Recursion error. the Property is named the same as the backing store. You will eventually run out of memory, as the program continues trying to set a value that is changing because you are resetting the same value.
              Code:
              [Description("RSI period")]
              [GridCategory("Parameters")]
              public int RSIPeriod  
              {
              get { return [COLOR=red][B]r[/B][/COLOR]SIPeriod; } 
              set { rSIPeriod = Math.Max(1, value); }
              }
              Last edited by koganam; 11-30-2012, 03:51 PM.

              Comment


                #22
                Thanks. This is the original intention for the trade:
                "To clarify further, you are trying to enter a position only on a bar in which price closes higher than the high from 2 bars before RSI crossed above 20.

                Thus say RSI crosses above 20 (AND CLOSES ABOVE 20) on Bar X, and the high of Bar X - 2 == $100.

                So you want to enter a trade only when price (CLOSES) above $100.

                Also, the stop loss is a close below the low of the bar that closed with RSI of > 20."

                The code snippet provided by Joydeep to accomplish this was:
                //In Variable region double tradePrice; double trade = false; //in OnBarUpdate if (CrossAbove(RSI(RSIPeriod, 1), Rsilower, 1)) { SetStopLoss(CalculationMode.Price, Low[0]); tradePrice = High[2]; stopPrice = Low[0]; trade = true; } if (Close[0] > tradePrice && trade) { EnterLong(); trade = false; }
                Where Joydeep has "double Trade = False" looked like a boolean but was instead using it as a 'Double" and I was questioning if this was intended or not.

                Comment


                  #23
                  Thanks Koganam - Getting 2 error only now: CS0103 on line 48, CS0266 on line 53. If you compile you will see it. (code is below)

                  Clarification on your question:
                  "To clarify further, you are trying to enter a position only on a bar in which price closes higher than the high from 2 bars before RSI crossed above 20.

                  Thus say RSI crosses above 20 (AND CLOSES ABOVE 20) on Bar X, and the high of Bar X - 2 == $100.

                  So you want to enter a trade only when price (CLOSES) above $100.

                  Also, the stop loss is a close below the low of the bar that closed with RSI of > 20."

                  The code snippet provided by Joydeep to accomplish this was:

                  //In Variable region double tradePrice; double trade = false; //in OnBarUpdate if (CrossAbove(RSI(RSIPeriod, 1), Rsilower, 1)) { SetStopLoss(CalculationMode.Price, Low[0]); tradePrice = High[2]; stopPrice = Low[0]; trade = true; } if (Close[0] > tradePrice && trade) { EnterLong(); trade = false; }
                  Where Joydeep has "double Trade = False" looked like a boolean but was instead using it as a 'Double" and I was questioning if this was intended or not.


                  __________________________________________________ _________
                  // This namespace holds all strategies and is required. Do not change it.
                  namespace NinjaTrader.Strategy
                  {
                  /// <summary>
                  /// Enter the description of your strategy here
                  /// </summary>
                  [Description("Enter the description of your strategy here")]
                  public class TwoBack : Strategy
                  {
                  #region Variables
                  // Wizard generated variables
                  private double tradeprice = 1; // Default setting for Tradeprice
                  private bool trade = false; // Default setting for Trade
                  private int rsilower = 1; // Default setting for Rsilower
                  private int profitTarget = 1; // Default setting for ProfitTarget
                  private int stopLoss = 1; // Default setting for StopLoss
                  private int rsiPeriod = 1; // Default setting for RsiPeriod
                  private int stopPrice = 1; // Default setting for StopPrice
                  // User defined variables (add any user defined variables below)
                  #endregion

                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize()
                  {
                  CalculateOnBarClose = true;
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  // Condition set 1
                  if (CrossAbove(RSI(RsiPeriod, 1), Rsilower, 1))
                  {
                  SetStopLoss(CalculationMode.Price, Low[0]);
                  tradeprice = High[2];
                  stopPrice = Low[0];
                  trade = true;
                  }

                  // Condition set 2
                  if (Close[0] > tradeprice && trade)
                  {
                  EnterLong();

                  trade = false;
                  }
                  }

                  #region Properties
                  [Description("")]
                  [GridCategory("Parameters")]
                  public double Tradeprice
                  {
                  get { return tradeprice; }
                  set { tradeprice = Math.Max(1, value); }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public bool Trade
                  {
                  get { return trade; }
                  set { trade = value; }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public int Rsilower
                  {
                  get { return rsilower; }
                  set { rsilower = Math.Max(1, value); }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public int ProfitTarget
                  {
                  get { return profitTarget; }
                  set { profitTarget = Math.Max(1, value); }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public int StopLoss
                  {
                  get { return stopLoss; }
                  set { stopLoss = Math.Max(1, value); }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public int RsiPeriod
                  {
                  get { return rsiPeriod; }
                  set { rsiPeriod = Math.Max(1, value); }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public int StopPrice
                  {
                  get { return stopPrice; }
                  set { stopPrice = Math.Max(1, value); }
                  }
                  #endregion
                  }
                  }

                  Comment


                    #24
                    Your code is inconsistent. C# is a strongly typed language, so you have to ensure that your types are properly defined.

                    Prices are not integers; they are doubles. You have defined them as integers, then tried to assign doubles to them, without casting. You do not want to cast them to integers, as you will lose considerable accuracy if you do.

                    First correct your type definitions, (and remember to correct their Property definitions), then we can look at any problems. The only variable I see that needs to be an integer is rsiPeriod.


                    Originally posted by poipoi11 View Post
                    Thanks Koganam - Getting 2 error only now: CS0103 on line 48, CS0266 on line 53. If you compile you will see it. (code is below)

                    Clarification on your question:
                    "To clarify further, you are trying to enter a position only on a bar in which price closes higher than the high from 2 bars before RSI crossed above 20.

                    Thus say RSI crosses above 20 (AND CLOSES ABOVE 20) on Bar X, and the high of Bar X - 2 == $100.

                    So you want to enter a trade only when price (CLOSES) above $100.

                    Also, the stop loss is a close below the low of the bar that closed with RSI of > 20."

                    The code snippet provided by Joydeep to accomplish this was:

                    //In Variable region double tradePrice; double trade = false; //in OnBarUpdate if (CrossAbove(RSI(RSIPeriod, 1), Rsilower, 1)) { SetStopLoss(CalculationMode.Price, Low[0]); tradePrice = High[2]; stopPrice = Low[0]; trade = true; } if (Close[0] > tradePrice && trade) { EnterLong(); trade = false; }
                    Where Joydeep has "double Trade = False" looked like a boolean but was instead using it as a 'Double" and I was questioning if this was intended or not.


                    __________________________________________________ _________
                    // This namespace holds all strategies and is required. Do not change it.
                    namespace NinjaTrader.Strategy
                    {
                    /// <summary>
                    /// Enter the description of your strategy here
                    /// </summary>
                    [Description("Enter the description of your strategy here")]
                    public class TwoBack : Strategy
                    {
                    #region Variables
                    // Wizard generated variables
                    private double tradeprice = 1; // Default setting for Tradeprice
                    private bool trade = false; // Default setting for Trade
                    private int rsilower = 1; // Default setting for Rsilower
                    private int profitTarget = 1; // Default setting for ProfitTarget
                    private int stopLoss = 1; // Default setting for StopLoss
                    private int rsiPeriod = 1; // Default setting for RsiPeriod
                    private int stopPrice = 1; // Default setting for StopPrice
                    // User defined variables (add any user defined variables below)
                    #endregion

                    /// <summary>
                    /// This method is used to configure the strategy and is called once before any strategy method is called.
                    /// </summary>
                    protected override void Initialize()
                    {
                    CalculateOnBarClose = true;
                    }

                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                    // Condition set 1
                    if (CrossAbove(RSI(RsiPeriod, 1), Rsilower, 1))
                    {
                    SetStopLoss(CalculationMode.Price, Low[0]);
                    tradeprice = High[2];
                    stopPrice = Low[0];
                    trade = true;
                    }

                    // Condition set 2
                    if (Close[0] > tradeprice && trade)
                    {
                    EnterLong();

                    trade = false;
                    }
                    }

                    #region Properties
                    [Description("")]
                    [GridCategory("Parameters")]
                    public double Tradeprice
                    {
                    get { return tradeprice; }
                    set { tradeprice = Math.Max(1, value); }
                    }

                    [Description("")]
                    [GridCategory("Parameters")]
                    public bool Trade
                    {
                    get { return trade; }
                    set { trade = value; }
                    }

                    [Description("")]
                    [GridCategory("Parameters")]
                    public int Rsilower
                    {
                    get { return rsilower; }
                    set { rsilower = Math.Max(1, value); }
                    }

                    [Description("")]
                    [GridCategory("Parameters")]
                    public int ProfitTarget
                    {
                    get { return profitTarget; }
                    set { profitTarget = Math.Max(1, value); }
                    }

                    [Description("")]
                    [GridCategory("Parameters")]
                    public int StopLoss
                    {
                    get { return stopLoss; }
                    set { stopLoss = Math.Max(1, value); }
                    }

                    [Description("")]
                    [GridCategory("Parameters")]
                    public int RsiPeriod
                    {
                    get { return rsiPeriod; }
                    set { rsiPeriod = Math.Max(1, value); }
                    }

                    [Description("")]
                    [GridCategory("Parameters")]
                    public int StopPrice
                    {
                    get { return stopPrice; }
                    set { stopPrice = Math.Max(1, value); }
                    }
                    #endregion
                    }
                    }

                    Comment


                      #25
                      Thanks - I believe I have worked out all of the inconsistencies. What I see now is that the Stop Loss is not triggering. I may not have the code in the right place. For reference on the objective again, I have pasted the photo of the way it should function. Here also is how I have the code set now.

                      #region Variables
                      // Wizard generated variables
                      private double tradeprice = 1; // Default setting for Tradeprice
                      private bool trade = false; // Default setting for Trade
                      private double rsilower = 1; // Default setting for Rsilower
                      private double profitTarget = 1; // Default setting for ProfitTarget
                      private double stopLoss = 1; // Default setting for StopLoss
                      private int rsiPeriod = 1; // Default setting for RsiPeriod
                      private double stopPrice = 1; // Default setting for StopPrice
                      // User defined variables (add any user defined variables below)
                      #endregion

                      /// <summary>
                      /// This method is used to configure the strategy and is called once before any strategy method is called.
                      /// </summary>
                      protected override void Initialize()
                      {
                      SetProfitTarget("", CalculationMode.Ticks, 10);
                      stopPrice = Low[0];
                      SetStopLoss(CalculationMode.Price, Low[0]);

                      CalculateOnBarClose = true;
                      }

                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                      // Condition set 1
                      if (CrossAbove(RSI(RsiPeriod, 1), Rsilower, 1))
                      {
                      tradeprice = High[2];
                      trade = true;
                      BarColor = Color.Blue;
                      }

                      // Condition set 2
                      if (Close[0] > tradeprice && trade)
                      {
                      EnterLong();

                      trade = false;
                      }
                      }

                      #region Properties
                      [Description("")]
                      [GridCategory("Parameters")]
                      public double Tradeprice
                      {
                      get { return tradeprice; }
                      set { tradeprice = Math.Max(1, value); }
                      }

                      [Description("")]
                      [GridCategory("Parameters")]
                      public bool Trade
                      {
                      get { return trade; }
                      set { trade = value; }
                      }

                      [Description("")]
                      [GridCategory("Parameters")]
                      public double Rsilower
                      {
                      get { return rsilower; }
                      set { rsilower = Math.Max(1, value); }
                      }

                      [Description("")]
                      [GridCategory("Parameters")]
                      public double ProfitTarget
                      {
                      get { return profitTarget; }
                      set { profitTarget = Math.Max(1, value); }
                      }

                      [Description("")]
                      [GridCategory("Parameters")]
                      public double StopLoss
                      {
                      get { return stopLoss; }
                      set { stopLoss = Math.Max(1, value); }
                      }

                      [Description("")]
                      [GridCategory("Parameters")]
                      public int RsiPeriod
                      {
                      get { return rsiPeriod; }
                      set { rsiPeriod = Math.Max(1, value); }
                      }

                      [Description("")]
                      [GridCategory("Parameters")]
                      public double StopPrice
                      {
                      get { return stopPrice; }
                      set { stopPrice = Math.Max(1, value); }
                      }
                      #endregion
                      Attached Files

                      Comment


                        #26
                        Originally posted by poipoi11 View Post
                        Thanks - I believe I have worked out all of the inconsistencies. What I see now is that the Stop Loss is not triggering. I may not have the code in the right place. For reference on the objective again, I have pasted the photo of the way it should function. Here also is how I have the code set now.

                        #region Variables
                        // Wizard generated variables
                        private double tradeprice = 1; // Default setting for Tradeprice
                        private bool trade = false; // Default setting for Trade
                        private double rsilower = 1; // Default setting for Rsilower
                        private double profitTarget = 1; // Default setting for ProfitTarget
                        private double stopLoss = 1; // Default setting for StopLoss
                        private int rsiPeriod = 1; // Default setting for RsiPeriod
                        private double stopPrice = 1; // Default setting for StopPrice
                        // User defined variables (add any user defined variables below)
                        #endregion

                        /// <summary>
                        /// This method is used to configure the strategy and is called once before any strategy method is called.
                        /// </summary>
                        protected override void Initialize()
                        {
                        SetProfitTarget("", CalculationMode.Ticks, 10);
                        stopPrice = Low[0];
                        SetStopLoss(CalculationMode.Price, Low[0]);

                        CalculateOnBarClose = true;
                        }

                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                        // Condition set 1
                        if (CrossAbove(RSI(RsiPeriod, 1), Rsilower, 1))
                        {
                        tradeprice = High[2];
                        trade = true;
                        BarColor = Color.Blue;
                        }

                        // Condition set 2
                        if (Close[0] > tradeprice && trade)
                        {
                        EnterLong();

                        trade = false;
                        }
                        }

                        #region Properties
                        [Description("")]
                        [GridCategory("Parameters")]
                        public double Tradeprice
                        {
                        get { return tradeprice; }
                        set { tradeprice = Math.Max(1, value); }
                        }

                        [Description("")]
                        [GridCategory("Parameters")]
                        public bool Trade
                        {
                        get { return trade; }
                        set { trade = value; }
                        }

                        [Description("")]
                        [GridCategory("Parameters")]
                        public double Rsilower
                        {
                        get { return rsilower; }
                        set { rsilower = Math.Max(1, value); }
                        }

                        [Description("")]
                        [GridCategory("Parameters")]
                        public double ProfitTarget
                        {
                        get { return profitTarget; }
                        set { profitTarget = Math.Max(1, value); }
                        }

                        [Description("")]
                        [GridCategory("Parameters")]
                        public double StopLoss
                        {
                        get { return stopLoss; }
                        set { stopLoss = Math.Max(1, value); }
                        }

                        [Description("")]
                        [GridCategory("Parameters")]
                        public int RsiPeriod
                        {
                        get { return rsiPeriod; }
                        set { rsiPeriod = Math.Max(1, value); }
                        }

                        [Description("")]
                        [GridCategory("Parameters")]
                        public double StopPrice
                        {
                        get { return stopPrice; }
                        set { stopPrice = Math.Max(1, value); }
                        }
                        #endregion
                        I see a few things wrong, but given how much effort you have actually put into learning and creating this, it might make a bit more sense if I showed you how I would code the setup that your picture describes. A picture is really worth a whole lot of words. Unfortunately, your code does not really completely describe the picture.

                        Note that this is just skeleton code that I whipped up to demonstrate how you will need to think, in order that your code matches what you want to do. It is by no means complete, as there are other conditions that you should probably consider: such as make orders live until canceled, and cancel all pending orders at end of day, each of which will mean that there are initial conditions that will need to be reset.

                        I have coded only the long side. You should be able to code the short side, based on it. Or you can just reverse most of it, and have one strategy as long side only, and the other as short side only.

                        There are just so many ways to handle code.

                        Have fun.

                        You will have to do a cut and paste job, even though all the code is here. The reason is that a few bad experiences where I made free complete indicators for folks on this board, who then chose to actually insult me when I refused to keep making refinements after acceding to about 10 requests, made me foreswear ever providing any completed, importable code to anyone. So, even though I am, posting the entire code, I am keeping the letter of that resolution, even if the spirit is suspect in this case.

                        Remember that this is just my style of coding: it is not the only way. There are many other ways to code the picture that you have drawn.

                        Code:
                         
                        #region Variables
                        // Wizard generated variables
                        private double rSILower = 20.0; // Default setting for RSILower
                        private double rSIUpper = 80; // Default setting for RSIUpper
                        private int rSIPeriod = 9; // Default setting for RSIPeriod
                        // User defined variables (add any user defined variables below)
                        private bool MayTradeLong = false;
                        private double LongEntryPrice = 1000000000.0;
                        private double LongStopPrice = 0.0;
                        private bool LongStopReset = false;
                        private bool exitByBarClose = true;
                        #endregion
                        Code:
                         
                        protected override void Initialize()
                        {
                        SetStopLoss("LongEntry", CalculationMode.Ticks, 40, false);
                        EntriesPerDirection = 1;
                        EntryHandling = EntryHandling.AllEntries;
                         
                        // TraceOrders = true;
                        CalculateOnBarClose = true;
                        }
                        Code:
                          
                        protected override void OnBarUpdate()
                        {
                        // Print(null); 
                        // Print("CurrentBar: " + CurrentBar);
                         
                        if (Position.MarketPosition == MarketPosition.Flat && !this.LongStopReset) //rest stop when we go flat
                        {
                        SetStopLoss("LongEntry", CalculationMode.Ticks, 40, false); 
                        this.LongStopReset = true;
                        this.LongEntryPrice = 1000000000.0;
                        // Print("LongStop reset here");
                        }
                         
                        if (CrossAbove(RSI(RSIPeriod, 1), RSILower, 1) 
                        && !this.MayTradeLong) //rsi cross condition
                        //met while we are not
                        //in a trading position
                        {
                        BarColor = Color.Blue;
                        this.LongEntryPrice = High[2];
                        this.LongStopPrice = Low[0];
                        this.MayTradeLong = true; //trade condition triggered, so we disable re-entry
                        // Print("LongEntry conditions met here");
                        }
                         
                        if (Close[0] > this.LongEntryPrice && this.MayTradeLong)
                        {
                        // Print("LongEntry here");
                         
                        if (!this.ExitByBarClose) 
                        {
                        SetStopLoss("LongEntry", CalculationMode.Price, this.LongStopPrice, false);
                        }
                        else
                        {
                        SetStopLoss("LongEntry", CalculationMode.Price, 0.01, false); 
                        }
                        EnterLong("LongEntry"); //Market order
                        this.MayTradeLong = false; //re-enable entry condition processing
                        }
                         
                        if (Position.MarketPosition == MarketPosition.Long && this.ExitByBarClose && Close[0] < this.LongStopPrice) 
                        {
                        // Print("Long Exit conditions met here if ExitByBarClose");
                        ExitLong("LongEntry");
                        }
                        }
                        Code:
                         
                         #region Properties
                        [Description("Threshold on RSI to trigger long entry")]
                        [GridCategory("Parameters")]
                        public double RSILower
                        {
                        get { return rSILower; }
                        set { rSILower = Math.Max(0.01, value); }
                        }
                        [Description("Threshold on RSI to trigger short entry")]
                        [GridCategory("Parameters")]
                        public double RSIUpper
                        {
                        get { return rSIUpper; }
                        set { rSIUpper = Math.Min(99.99, value); }
                        }
                        [Description("Period to use for RSI filter")]
                        [GridCategory("Parameters")]
                        public int RSIPeriod
                        {
                        get { return rSIPeriod; }
                        set { rSIPeriod = Math.Max(1, value); }
                        }
                         
                        [Description("Choose whether to exit when the bar that the triggers the stop loss closes, or when the stop loss is hit.")]
                        [GridCategory("Parameters")]
                        public bool ExitByBarClose
                        {
                        get { return exitByBarClose; }
                        set { exitByBarClose = value; }
                        }
                        #endregion
                        Last edited by koganam; 12-02-2012, 08:03 PM. Reason: Corrected code bound check error

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by elirion, Yesterday, 09:32 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post elirion
                        by elirion
                         
                        Started by cre8able, Yesterday, 09:15 PM
                        1 response
                        8 views
                        0 likes
                        Last Post bltdavid  
                        Started by cummish, Yesterday, 08:43 PM
                        0 responses
                        16 views
                        0 likes
                        Last Post cummish
                        by cummish
                         
                        Started by Option Whisperer, Yesterday, 07:58 PM
                        4 responses
                        21 views
                        0 likes
                        Last Post Option Whisperer  
                        Started by ETFVoyageur, 05-07-2024, 07:05 PM
                        13 responses
                        87 views
                        0 likes
                        Last Post ETFVoyageur  
                        Working...
                        X