How do I organize its firmware function to perform the same actions with different variables?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
same actions with different variables
Collapse
X
-
Hello,
Are you asking how to use a variable in the entire script?
If so you would need to define the variable outside of the methods body.
Here are a couple of basic examples:
This variable is defined inside of OnBarUpdate so it can only be used inside of OnBarUpdate.Code:protected override void OnBarUpdate() { double lastPrice = 0; }
This variable is defined outside of the OnBarUpdate so it can be used in OnBarUpdate or any other method that is in the same scope as OnBarUpdateCode:private double lastPrice = 0; protected override void OnBarUpdate() { Print(lastPrice); } protected override void OnMarketData(MarketDataEventArgs e) { Print(lastPrice); }
Please let me know if I may be of additional assistance.
Comment
-
Hello,
Thank you for the question.
I will provide a simple example of this below, I would recommend reading some online tutorials on general C# syntax and logic, this will greatly help in understanding NinjaScript as NinjaScript is C#.
For methods in NinjaTrader,
Starting off in a indicator you will see the following lines near the top:
All of your code will need to go in between the open bracket { of the public class and its closing bracket }Code:namespace NinjaTrader.Indicator { [Description("Enter the description of your new custom indicator here")] public class Test : Indicator {
To create a custom method you would need to define the method inside the class or:
Please let me know if I may be of additional assistance.Code:namespace NinjaTrader.Indicator { [Description("Enter the description of your new custom indicator here")] public class Test : Indicator { private void TestMethod(string valueOfPrint) { Print(valueOfPrint); } protected override void OnBarUpdate() { TestMethod("Hello"); } } }
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by kinfxhk, 07-14-2026, 09:39 AM
|
0 responses
125 views
0 likes
|
Last Post
by kinfxhk
07-14-2026, 09:39 AM
|
||
|
Started by kinfxhk, 07-13-2026, 10:18 AM
|
0 responses
105 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 10:18 AM
|
||
|
Started by kinfxhk, 07-13-2026, 09:50 AM
|
0 responses
85 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 09:50 AM
|
||
|
Started by kinfxhk, 07-13-2026, 07:21 AM
|
0 responses
105 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 07:21 AM
|
||
|
Started by kinfxhk, 07-11-2026, 02:11 AM
|
0 responses
85 views
0 likes
|
Last Post
by kinfxhk
07-11-2026, 02:11 AM
|

Comment