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 CaptainJack, 05-29-2026, 05:09 AM
|
0 responses
475 views
0 likes
|
Last Post
by CaptainJack
05-29-2026, 05:09 AM
|
||
|
Started by CaptainJack, 05-29-2026, 12:02 AM
|
0 responses
315 views
0 likes
|
Last Post
by CaptainJack
05-29-2026, 12:02 AM
|
||
|
Started by charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
253 views
1 like
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
340 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
305 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|

Comment