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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
152 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
87 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
131 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
127 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
106 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment