NexusFi: Find Your Edge


Home Menu

 





Cannot use decimal in RSI formula


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one RJay with 1 posts (1 thanks)
    2. looks_two sqadri with 1 posts (0 thanks)
    3. looks_3 bukkan with 1 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 1,981 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Cannot use decimal in RSI formula

  #1 (permalink)
 sqadri 
Orlando, FL/ USA
 
Experience: Beginner
Platform: Ninja Trader, Firetip
Trading: Crude Oil
Posts: 2 since Sep 2011
Thanks Given: 2
Thanks Received: 0

Hi,

I hope someone can help me out here. I am beginner with Ninja Trader. Was trying to write out my first strategy using Ninja Trader. I was following the book with the example of the RSI code. I wanted to know if I wanted to code such that I go long for instance when RSI hits 18.5 as opposed to my current 17 how can I do that since it tells me RSI is a Int? I thought RSI has a decimal when I look in the chart ? Below is my code .

My goal is to make the line where it says
if (CrossAbove(RSI(RSIPeriod, RSISmooth),17,1))
something like this ..

if (CrossAbove(RSI(RSIPeriod, RSISmooth),18.5,1))

If I do this the code compiles fine but doesn't Enter me long if RSI comes below 18.5 and moves up. I think it has to do because it's expecting a Integer.

Thanks


#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
///<summary>
/// RSI with a Stop loss and Profit Target
///</summary>
[Description("RSI with a Stop loss and Profit Target")]
publicclass ShoaibRSILow : Strategy
{
#region Variables
// Wizard generated variables
privateint rSIPeriod = 14; // Default setting for RSIPeriod
privateint rSISmooth = 3; // Default setting for RSISmooth
privateint profitTarget = 25; // Default setting for ProfitTarget
privateint stopLoss = 20; // Default setting for StopLoss
// 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>
protectedoverridevoid Initialize()
{
CalculateOnBarClose =
true;
//This will add the RSI indicator to the chart for vizulation
Add(RSI(RSIPeriod,RSISmooth));
//Add stop loss and profit target orders
SetStopLoss(CalculationMode.Ticks, StopLoss);
SetProfitTarget(CalculationMode.Ticks, ProfitTarget);
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
if (CurrentBar < RSIPeriod)
return;

if (CrossAbove(RSI(RSIPeriod, RSISmooth),17,1))
{
EnterLong();
}
}
#region Properties
[Description(
"RSI Period")]
[GridCategory(
"Parameters")]
publicint RSIPeriod
{
get { return rSIPeriod; }
set { rSIPeriod = Math.Max(1, value); }
}
[Description(
"RSI Smooth")]
[GridCategory(
"Parameters")]
publicint RSISmooth
{
get { return rSISmooth; }
set { rSISmooth = Math.Max(1, value); }
}
[Description(
"Profit Target Offset")]
[GridCategory(
"Parameters")]
publicint ProfitTarget
{
get { return profitTarget; }
set { profitTarget = Math.Max(1, value); }
}
[Description(
"Stop Loss Offset")]
[GridCategory(
"Parameters")]
publicint StopLoss
{
get { return stopLoss; }
set { stopLoss = Math.Max(1, value); }
}
#endregion
}
}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
What broker to use for trading palladium futures
Commodities
ZombieSqueeze
Platforms and Indicators
 
  #3 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 278 since Jun 2009
Thanks Given: 161
Thanks Received: 271


havent tested but it should be like this. the changes are in green.

just assign the appropriate value from the parameter dialog box CrossoverValue

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
///<summary>
/// RSI with a Stop loss and Profit Target
///</summary>
    [Description("RSI with a Stop loss and Profit Target")]
    public class ShoaibRSILow : Strategy
    {
        #region Variables
        // Wizard generated variables
        private int rSIPeriod = 14; // Default setting for RSIPeriod
        private int rSISmooth = 3; // Default setting for RSISmooth
        private int profitTarget = 25; // Default setting for ProfitTarget
        private int stopLoss = 20; // Default setting for StopLoss
        // User defined variables (add any user defined variables below)
        
        double crossoverValue = 17;
        #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;
            //This will add the RSI indicator to the chart for vizulation
            Add(RSI(RSIPeriod,RSISmooth));
            //Add stop loss and profit target orders
            SetStopLoss(CalculationMode.Ticks, StopLoss);
            SetProfitTarget(CalculationMode.Ticks, ProfitTarget);
        }
        ///<summary>
        /// Called on each bar update event (incoming tick)
        ///</summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar < RSIPeriod)
            return;

            if (CrossAbove(RSI(RSIPeriod, RSISmooth),crossoverValue,1))
            {
                EnterLong();
            }
        }
        
        
        
        
        #region Properties
        [Description("RSI Period")]
        [GridCategory("Parameters")]
        public int RSIPeriod
        {
            get { return rSIPeriod; }
            set { rSIPeriod = Math.Max(1, value); }
        }
        [Description("RSI Smooth")]
        [GridCategory("Parameters")]
        public int RSISmooth
        {
            get { return rSISmooth; }
            set { rSISmooth = Math.Max(1, value); }
        }
        [Description("Profit Target Offset")]
        [GridCategory("Parameters")]
        public int ProfitTarget
        {
            get { return profitTarget; }
            set { profitTarget = Math.Max(1, value); }
        }
        [Description("Stop Loss Offset")]
        [GridCategory("Parameters")]
        public int StopLoss
        {
            get { return stopLoss; }
            set { stopLoss = Math.Max(1, value); }
        }
        
        [Description("Crossover value")]
        [GridCategory("Parameters")]
        public double CrossoverValue
        {
            get { return crossoverValue; }
            set { crossoverValue = Math.Max(1, value); }
        }
        #endregion
    }
}

Reply With Quote
Thanked by:
  #4 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 683 since Jun 2009
Thanks Given: 758
Thanks Received: 787

Hi sqadri,

Everywhere you see "int" in your code you are restriction those values to whole numbers. If you want decimals, you must redefine those values to "double" so they will be processed as decimal values.

RJay

Reply With Quote
Thanked by:




Last Updated on October 22, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts