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
max value
Collapse
X
-
Tags: None
-
Hello shaista parveen,
Welcome to the NinjaTrader support forum.
You could use the MAX indicator for this: https://ninjatrader.com/support/help...aximum_max.htm
Code:double smaMax = MAX(SMA(12), 30)[0]; Print(smaMax);
Code:double smaMax = MAX(SMA(12), 30)[0]; double smaMax2 = MAX(SMA(15), 30)[0];
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
i have create three different SMAs like i want finding maximum & minimum through Math function
namespace NinjaTrader.NinjaScript.Strategies
{
public class SMA1to2 : Strategy
{
private SMA SMA1;
private SMA SMA2;
private SMA SMA3;
private double Maximum;
private double Minimum;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "SMA1to2";
Calculate = Calculate.OnBarClose;
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;
Period1 = 1;
Period2 = 1;
Period3 = 1;
else if (State == State.DataLoaded)
{
SMA1 =SMA(Typical, Convert.ToInt32(Period1));
SMA2 =SMA(Typical, Convert.ToInt32(Period2));
SMA3 =SMA(Typical, Convert.ToInt32(Period3));
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
for (int barIndex = ChartBars.FromIndex; barIndex <= CharBars.ToIndex; barIndex++)
{
double val1 = SMA1[barIndex];
double val2 = SMA2[barIndex];
double val3 = SMA3[barIndex];
double maximum = Math.Max(val1, Math.Max(val2,val3));
double manimum = Math.Min(val1, Math.Min(val2,val3));
}
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Period1", Order=0, GroupName="Parameters")]
public int Period1
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Period2", Order=1, GroupName="Parameters")]
public int Period2
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Period3", Order=2, GroupName="Parameters")]
public int Period3
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Low_length", Order=3, GroupName="Parameters")]
public int Low_length
{ get; set; }
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="Low_multi", Order=4, GroupName="Parameters")]
public double Low_multi
{ get; set; }
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="Vol_multi", Order=5, GroupName="Parameters")]
public double Vol_multi
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="AdxLowValue", Order=6, GroupName="Parameters")]
public int AdxLowValue
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="AdxHighValue", Order=7, GroupName="Parameters")]
public int AdxHighValue
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="AdxLength", Order=8, GroupName="Parameters")]
public int AdxLength
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Range1", Order=9, GroupName="Parameters")]
public int Range1
{ get; set; }
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="Profit_Target", Order=10, GroupName="Parameters")]
public double Profit_Target
{ get; set; }
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="Stop_Loss", Order=11, GroupName="Parameters")]
public double Stop_Loss
{ get; set; }
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="TstopLoss", Order=12, GroupName="Parameters")]
public double TstopLoss
{ get; set; }
#endregion
}
}
Comment
-
Hello shaista parveen,
If you wanted to gather the max of all 3 values it would be like koganam had shown in post #3, this is the same concept I am describing in post #2 it is just combining the max's to find the max of all values used.
Please let me now if I may be of additional assistance.
JesseNinjaTrader Customer Service
Comment
-
hello KOGANAM Sir
but how i can print this and write on which method
double maxValue = Math.Max(SMA(Period1), Math.Max(SMA(Period2), SMA(Period3)));
Comment
-
-
Hello shaista parveen,
but how i can print this and write on which method
https://ninjatrader.com/support/help...lightsub=print
https://ninjatrader.com/support/help...nt8/output.htm
To print this value would look like Print(maxValue);
and Math.Max is applicable on SMA because Math.Max takes double value as in arguments
https://docs.microsoft.com/en-us/dot...tframework-4.5
NinjaScript is C# programming language so you can use any existing methods or namespaces within the standard C# libraries.
Math.Max takes a double so any double value in NinjaScript could be used with this method.
In the prior examples the SMA is used but it appears there was an error, you need a BarsAgo to retrieve a value. It should look like this:
Code:double maxValue = Math.Max(SMA(12)[0], Math.Max(SMA(14)[0], SMA(16)[0]));
I look forward to being of further assistance.Last edited by NinjaTrader_Jesse; 12-30-2019, 11:14 AM.JesseNinjaTrader Customer Service
Comment
-
i doesn't find to max value SMA(period1).
i just find maximum value of between three SMAs which have different periods.
Comment
-
Originally posted by shaista parveen View Posthello KOGANAM Sir
but how i can print this and write on which method
double maxValue = Math.Max(SMA(Period1), Math.Max(SMA(Period2), SMA(Period3)));
Code:double maxValue = Math.Max(SMA(Period1)[0], Math.Max(SMA(Period2)[0], SMA(Period3)[0]));
Comment
-
-
its not work
else if (State == State.DataLoaded)
{
//double maxSma = Math.Max(SMA(Period1)[0], Math.Max(SMA(Period2)[0], SMA(Period3)[0]));
//Print(maxSma);
SMA1 =SMA(Typical, Convert.ToInt32(Period1));
SMA2 =SMA(Typical, Convert.ToInt32(Period2));
SMA3 =SMA(Typical, Convert.ToInt32(Period3));
// adx =ADX()
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 1)
return;
double maxSma = Math.Max(SMA1(Period1)[0], Math.Max(SMA(Period2)[0], SMA(Period3)[0]));
Print(maxSma);
Comment
-
-
Hello shaista parveen,
this code is written in this section
else if (State == State.DataLoaded)
OnBarUpdate is used for processing bar data and would be where you can calculate values. It looks like in post #12 you have done that.
its not work
Do you have the NinjaScript output window open?
To use the code you have shown you would need to run it and then observe the output window, if you want to attach the whole file so I can run it or see the error that you are that would help. The file is located in the folder: Documents\NinjaTrader 8\bin\Custom\Indicators
No one helps me
I would suggest using the learning resources that are available if you are awaiting replies. I have provided some links to those resource below, if you have follow up questions please feel free to ask.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Originally posted by shaista parveen View Postits not work
else if (State == State.DataLoaded)
{
//double maxSma = Math.Max(SMA(Period1)[0], Math.Max(SMA(Period2)[0], SMA(Period3)[0]));
//Print(maxSma);
SMA1 =SMA(Typical, Convert.ToInt32(Period1));
SMA2 =SMA(Typical, Convert.ToInt32(Period2));
SMA3 =SMA(Typical, Convert.ToInt32(Period3));
// adx =ADX()
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 1)
return;
double maxSma = Math.Max(SMA1(Period1)[0], Math.Max(SMA(Period2)[0], SMA(Period3)[0]));
Print(maxSma);- Have you defined the Periodn? Silly question, I know, but you would be surprised how many times I have done it myself.
- You have tried to directly pass a parameter to an object. In effect, you have tried to use a variable as if it were a method. (see the "1" I have emphasized in bold red?)
- "Its not work" is not a problem report, even if true. At the very least, tell us what errors you are getting. As it is, I am not even sure if you have declared your SMAn variables.
Code:double maxSma = Math.Max(SMA(Period1)[0], Math.Max(SMA(Period2)[0], SMA(Period3)[0]));
Code:double maxSma = Math.Max(SMA(Typical, Period1)[0], Math.Max(SMA(Typical, Period2)[0], SMA(Typical, Period3)[0]));
What are the errors reported, either in a compilation, or in the log?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rocketman7, Today, 09:41 AM
|
4 responses
15 views
0 likes
|
Last Post
by rocketman7
Today, 02:56 PM
|
||
Started by selu72, Today, 02:01 PM
|
1 response
9 views
0 likes
|
Last Post Today, 02:17 PM | ||
Started by WHICKED, Today, 02:02 PM
|
2 responses
12 views
0 likes
|
Last Post
by WHICKED
Today, 02:15 PM
|
||
Started by f.saeidi, Today, 12:14 PM
|
8 responses
21 views
0 likes
|
Last Post
by f.saeidi
Today, 01:55 PM
|
||
Started by Mikey_, 03-23-2024, 05:59 PM
|
3 responses
56 views
0 likes
|
Last Post
by Sam2515
Today, 01:47 PM
|
Comment