Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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
}
}
Can you help answer these questions from other members on NexusFi?
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.