Ex. If bar 2 and bar 1 are bullish place order at x-target and y-stop loss.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Newbie in need of help
Collapse
X
-
Newbie in need of help
I'd like to make a simple strategy that just looks at the last 2 bars (or current and previous, I'm not sure) and enters a order in the direction of the previous two like bars. I know this is a very simple strategy but I'm new and i want to build off this idea.
Ex. If bar 2 and bar 1 are bullish place order at x-target and y-stop loss. -
Hello BTBX,
Welcome to the NinjaTrader forums!
What you want to do can be accomplished with a NinjaScript automated strategy. Using the strategy wizard is the best place to get started creating strategies. You can define conditions and actions in a point and click interface, with no coding required.
Please see the following link
There is a similar example to what you're looking for in the section How to make price data comparisons
That will compare current close to 1 bar ago. You could create an additional condition then that compares close 1 bar ago to close 2 bars ago.
Help with strategy action for order placement is available here:
Ryan M.NinjaTrader Customer Service
-
Thanks for the speedy reply
Yes, I found that site by looking around on similar questions. But now I'm stuck with trying to figure out how to get it to work. I have the buy code set but the mark on the graph isn't showing up and its not placing the order. = ( This may take a while lol
Comment
-
Yes, there can definitely be a learning curve at first but it's also really powerful once you get the hang of it.
Share the code you have so far and we can take a quick look. You can either copy / paste the code after hitting View code, or attach the .cs file from
My Documents\NinjaTrader\bin\custom\strategyRyan M.NinjaTrader Customer Service
Comment
-
Here what i have so far
#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>
/// After two consecutive same color bars it scalps for 2 ticks.
/// </summary>
[Description("After two consecutive same color bars it scalps for 2 ticks.")]
public class RuleOftwo : Strategy
{
#region Variables
// Wizard generated variables
// 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()
{
SetTrailStop("", CalculationMode.Ticks, 2, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (Close[0] > Close[1])
{
EnterLong(DefaultQuantity, "In");
DrawArrowDown("Enter" + CurrentBar, true, 0, Close[0], Color.Blue);
}
}
#region Properties
#endregion
}
}
#region Wizard settings, neither change nor remove
/*@
<?xml version="1.0" encoding="utf-16"?>
<NinjaTrader>
<Name>RuleOftwo</Name>
<CalculateOnBarClose>True</CalculateOnBarClose>
<Description>After two consecutive same color bars it scalps for 2 ticks.</Description>
<Parameters />
<State>
<CurrentState>
Comment
-
That looks like it should produce some trades for you. You have a narrow trailstop set so you might run into issues where the stop loss is triggered on the same bar as the entry.
I would make sure the strategy is enabled - Right Click on chart > Strategies > Select your strategy and set enabled to true.
Scroll to the beginning of chart so you can then see how it behaves at the earliest historical point.Ryan M.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Aviram Y, Today, 05:29 AM
|
0 responses
2 views
0 likes
|
Last Post
by Aviram Y
Today, 05:29 AM
|
||
Started by quantismo, 04-17-2024, 05:13 PM
|
3 responses
25 views
0 likes
|
Last Post Today, 05:23 AM | ||
Started by ScottWalsh, 04-16-2024, 04:29 PM
|
7 responses
34 views
0 likes
|
Last Post Today, 05:15 AM | ||
Started by cls71, Today, 04:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by cls71
Today, 04:45 AM
|
||
Started by mjairg, 07-20-2023, 11:57 PM
|
3 responses
217 views
1 like
|
Last Post
by PaulMohn
Today, 04:22 AM
|
Comment