Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Changing variables within an Indicator from another indicator with Buttons
Collapse
X
-
Changing variables within an Indicator from another indicator with Buttons
I need some guidance. I need to create a script that has 3 plots that are public and they plot either a 1 or 0. But I need to create another indicator that has 3 chart buttons that sets these variables. The first indicator needs to get those values from the second indicator depending on the button clicks. Because of using Markers Plus I cannot create a single indicator because I receive 'Error on calling 'OnStateChange' method: Object reference not set to an instance of an object. when I combine both processes into 1 indicator. The Markers Plus copy indicator run just fine if the indicator has just the 3 public plots. But when I add the button to change the values is when I get the error. I am not sure how to proceedTags: None
-
Hello thepcmd,
A hosted indicator can set a value to a public variable. If bar information is used, Update() will need to be called before the return. The Browsable(false) attribute may also be used so the property does not appear in the UI, and XmlIgnore() so the property is not saved with the workspace or template.
The value for the plot would only be set in real-time. A plot is intended to have values for every bar on the chart. Perhaps a plot is not the best object to hold the values?
Is the hosted indicator intended to be used with multiple host indicators? (Can you further clarify why the buttons and the plots could not be set from a single indicator?)
You have mentioned there is an error due to a null object. What is the null object causing the error?
Use prints on every other line to see which print is the last print to appear. The line below it may be causing the error.
Below is a link to a forum post that demonstrates using prints to understand behavior.
Chelsea B.NinjaTrader Customer Service
-
I have created an indicator with 3 plots. I need them to either be 1 or 0. I have tried to troubleshoot the issue by just creating the indicator without any buttons. If I set the value from Close[1} > Close[0] = 1 and vis-versa then the 'Markers Plus Copy' indicator works as expected If I add the buttons to the indicator to change values from 0 to 1 based on the button click. The 'Markers Plus Copy' indictor is added to the chart I select the indicator that I created as the input series. When it is added like that - that is when I get error messages in the NT8 log file. I get 2 errors - the first is on the indicator I created as Error on calling 'OnStateChange' method: Object reference not set to an instance of an object. The 'Markers Plus Copy' indicator error is - Error on calling 'SetState' method: Object reference not set to an instance of an object. I have based the buttons portion of the script on NT8 'SampleAddButton' aa_ApexFilters.cs > i have attached my indicator for reference. aa_ApexFilter.cs This is the version of the indicator that works correcty without the buttons. I am trying to create this 1 indicator so I can use it for a filter on 3 other indicators so I can click 1 button and set the value instead of making the changes to 3 others. Any help or alternatives would be appreciated. ThanksLast edited by thepcmd; 11-08-2020, 08:07 PM.
Comment
-
Hello thepcmd,
One thing I forgot to mention is that if you are attempting to set a series value from a non-data-driven method, such as a button click, this must use TriggerCustomEvent.
Below is a link to the help guide.
In the button click event, print "button clicked", then print the value of the plot to ensure it is set. Once set, that value will be readable by a host script on the next bar update.
With the null object, you will need to use prints and debug the script to identify which line is causing an error.
Try Print("1"); then a line of logic, then Print("2"), as shown in the forum post that I have linked you.
I am happy to assist with analyzing the output from the debugging prints.
Just a heads up, I can walk you the process and assist with analyzing the output, I but I cannot debug your code on your behalf.Chelsea B.NinjaTrader Customer Service
Comment
-
Chelsea I have this example on my platform. I have not download in last several months if it has been updated. The example I have is Long Orders only. I have created a version to includes short orders as well. I actually had it working trading secondary symbol to short as well. Some how in creating the secondary on the long side something went crazy. Now when i apply my indicator the indicator without clicking the buttons starts sending Long and Short Orders (it does recognize my code to select primary or secondary) but once applied to the chart IT JUST START SENDING ORDERS IN BOTH DIRECTIONS even though the buttons are not yet clicked to be enabled and IT SEND ORDER endlessly, it never stops. Have to use task manager to close ninja trader and restart (since the indicator was just added and the workspace not saved I just have to re open) Thanks for any ideas
Comment
-
I did add
if(CurrentBar< 1){
return;
}
in the OnBarUdate() area, which was there when I had the secondary short working properly
overnight I did change the conditions and the instant both directional trades stopped. The Secondary Instrument tradeing worked as expected, the when I test the primary I still had the same issues with instant trading regardless of button click status.
So I created a new indicator and removed the secondary trading conditions, the primary still instantly traded. I then removed the
if(CurrentBar< 1){
return;
}
from the OnBarUpdate()
BUT I STILL HAVE THE INSTANT TRADING REGARDLESS of click status of button
Comment
-
update, IN THE NEW INDICATOR FOR THE SECONDARY INSTRUMENT TRADING
KEEPING (which I think i added for the secondary to work properly)
if(CurrentBar< 1){
return;
}
from the OnBarUpdate()
the indicator does NOT instantly trade without the buttons click.
IN this indicator everything works as expected
Comment
-
when i removed the
if(CurrentBar< 1){
return;
}
i still had instant trades, (I do have the example and I know that is not included), I think since the secondary is working as expected and the primary not the only difference I have in the code there is a section of code with 3 indicators in a group to trade if any of those are true, so I have blocked that group and I am not getting INSTANT trading, so I am trying to isolate if it is the any statement or one of those indicators
Thanks for the help
Comment
-
Chelsea B Interesting development today when I load my indicator OR the default Example indicator on the Futures instruments. Which I rolled over this morning. The indicator Loads MES 12-21 and MNQ 12-21 instead of the new expiration that the chart has loaded MES 03-22 and MNQ 03-22. Also there is no way to change it.
thanks
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by thafuz, Today, 06:17 AM
|
2 responses
6 views
0 likes
|
Last Post
|
||
Started by Board game geek, 10-04-2023, 08:27 AM
|
13 responses
1,107 views
0 likes
|
Last Post
![]() |
||
Started by surya, 03-14-2025, 10:16 AM
|
4 responses
51 views
0 likes
|
Last Post
![]()
by surya
Today, 07:00 AM
|
||
Started by thafuz, Today, 05:53 AM
|
1 response
2 views
0 likes
|
Last Post
|
||
Started by tatjanabojic, Yesterday, 05:14 PM
|
1 response
21 views
0 likes
|
Last Post
|
Comment