|
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 . 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 .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
}
}
|