How do I organize its firmware function to perform the same actions with different variables?
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
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:
Code:protected override void OnBarUpdate() { double lastPrice = 0; }
Code: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.JesseNinjaTrader Customer Service
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:
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:
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"); } } }
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by FatCanary, 06-11-2021, 09:11 AM
|
17 responses
1,042 views
0 likes
|
Last Post
![]()
by Laurentvan
Yesterday, 11:43 PM
|
||
Started by csrkkalyan, 11-18-2023, 08:38 PM
|
4 responses
54 views
0 likes
|
Last Post
![]()
by csrkkalyan
Yesterday, 10:09 PM
|
||
Started by sidlercom80, 10-28-2023, 08:49 AM
|
94 responses
1,121 views
0 likes
|
Last Post
![]()
by rare312
Yesterday, 09:58 PM
|
||
Started by Conceptzx, Yesterday, 06:56 PM
|
1 response
12 views
0 likes
|
Last Post
![]()
by bltdavid
Yesterday, 09:51 PM
|
||
Started by roblogic, Yesterday, 06:20 PM
|
1 response
26 views
0 likes
|
Last Post
![]()
by elirion
Yesterday, 09:21 PM
|
Comment