Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.JesseNinjaTrader Customer Service
-
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.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by RubenCazorla, 08-30-2022, 06:36 AM
|
3 responses
77 views
0 likes
|
Last Post
by PaulMohn
Today, 04:44 AM
|
||
Started by f.saeidi, Yesterday, 12:14 PM
|
9 responses
23 views
0 likes
|
Last Post
by f.saeidi
Today, 04:39 AM
|
||
Started by Tim-c, Today, 03:54 AM
|
0 responses
3 views
0 likes
|
Last Post
by Tim-c
Today, 03:54 AM
|
||
Started by FrancisMorro, Today, 03:24 AM
|
0 responses
4 views
0 likes
|
Last Post
by FrancisMorro
Today, 03:24 AM
|
||
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
10 responses
1,772 views
0 likes
|
Last Post
by Leafcutter
Today, 03:01 AM
|
Comment