Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
how to specify displacement=1 for strategy indicators?
Collapse
X
-
how to specify displacement=1 for strategy indicators?
i am trying to learn how to use the strategy analyzer. In so doing, I have written a strategy but cannot figure out how to specify displacement=1 for the strategy indicators [i.e.] do i do it when creating the strategy in the strategy builder or do i do it elsewhere?Tags: None
-
Hello,
Thank you for the post.
In this case the Visual Displacement property that can normally be used with Indicators would not be avaliable as the strategy is hosting the indicator. It is technically possible to manually code into a strategy Displacement = 1 to displace the visuals but not while using the builder.
If you are trying to Visually displace the indicators from the builder, I will need to submit a feature request to expose the strategies Displacement property. Otherwise if you are trying to access data from 1 BarsAgo, you could use [1] instead of [0] to access the prior data.
I look forward to being of further assistance.
-
Thanks Jesse,
Below is my code generated by the Strategy Builder. If I must unlock and change the code, kindly show me what changes to make.
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class SampleMACrossOverStrategyJoeTest2 : Strategy
{
private DEMA DEMA1;
private TEMA TEMA1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Dema & Tema Cross Over";
Name = "SampleMACrossOverStrategyJoeTest2";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
DemaPeriod = 10;
TemaPeriod = 20;
}
else if (State == State.Configure)
{
DEMA1 = DEMA(Convert.ToInt32(DemaPeriod));
DEMA1.Plots[0].Brush = Brushes.Goldenrod;
AddChartIndicator(DEMA1);
TEMA1 = TEMA(Convert.ToInt32(TemaPeriod));
TEMA1.Plots[0].Brush = Brushes.Goldenrod;
AddChartIndicator(TEMA1);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 1)
return;
// Set 1
if (DEMA1[1] >= TEMA1[1])
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"Entry Long");
}
// Set 2
if (DEMA1[1] < TEMA1[1])
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"Entry Short");
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(ResourceType = typeof(Custom.Resource), Name="DemaPeriod", Description="Signals when crosses Tema Period indicator", Order=1, GroupName="NinjaScriptStrategyParameters")]
public int DemaPeriod
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(ResourceType = typeof(Custom.Resource), Name="TemaPeriod", Order=2, GroupName="NinjaScriptStrategyParameters")]
public int TemaPeriod
{ get; set; }
#endregion
}
}
Comment
-
Hello,
Thank you for the reply.
To manually add Displacement to the script, you would need to unlock the code and then add the Displacement syntax to State.SetDefaults.
There is an example of this property that shows where it would go in a script in the following help guide page:
Please let me know if I may be of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
52 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
43 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
47 views
0 likes
|
Last Post
|

Comment