Any help would be appreciated.!
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
Historical state or CurrentBar issue - indicator run amok
Collapse
X
-
Historical state or CurrentBar issue - indicator run amok
I'm trying ot create an indicator that looks at the latest 4 bars of a chart and send me and send me an email if a particular condition occurs.I set it to use Calculate.OnBarClose but when I apply it to a chart and switch the IsVisible to on, it sends a flood on email and crashes NT. My guess is it is processing more bars than it should. I've tried changing the value of "CurrentBar", tried using "IsFirstTickOfBar", all to no avail. I'm attaching a snippet of some of the relevant code. I believe the resolution will involve State === historical but I'm not sure where it would go and the how it is worded correctly.
Any help would be appreciated.!Tags: None
-
Hello sobertradingpartner,
Thank you for your post.
I also suspect that it is attempting to send a flood of emails when it runs through the historical data upon starting the indicator.
I recommend adding logic to either prevent the indicator from processing in historical (you can add this at the top of OnBarUpdate()):
Code:if (State == State.Historical) return;
Code:if (State == State.Realtime) // send email
Please let me know if you have any further questions.Gaby V.NinjaTrader Customer Service
- Likes 1
-
Originally posted by NinjaTrader_Gaby View PostI also suspect that it is attempting to send a flood of emails when it runs through the historical data upon starting the indicator.
The SendMail documentation says,
"This method can only be called once the State has reached State.Realtime.
Calls to this method in any other State will be silently ignored..."
So, according to the help guide, calls to SendMail in State.Historical should
not be causing the problem.
Just my 2˘.
Comment
-
Originally posted by NinjaTrader_Gaby View PostHello sobertradingpartner,
Thank you for your post.
I also suspect that it is attempting to send a flood of emails when it runs through the historical data upon starting the indicator.
I recommend adding logic to either prevent the indicator from processing in historical (you can add this at the top of OnBarUpdate()):
Code:if (State == State.Historical) return;
Code:if (State == State.Realtime) // send email
Please let me know if you have any further questions.
Comment
-
Originally posted by sobertradingpartner View PostI'm trying ot create an indicator that looks at the latest 4 bars of a chart and send me and send me an email if a particular condition occurs.I set it to use Calculate.OnBarClose but when I apply it to a chart and switch the IsVisible to on, it sends a flood on email and crashes NT. My guess is it is processing more bars than it should. I've tried changing the value of "CurrentBar", tried using "IsFirstTickOfBar", all to no avail. I'm attaching a snippet of some of the relevant code. I believe the resolution will involve State === historical but I'm not sure where it would go and the how it is worded correctly.
Any help would be appreciated.!
Code:if (CurrentBar < -2) return;
I see the highest BarsAgo index used is 3,
so that guard code should actually be,
Code:if (CurrentBar < 3) return;
-=o=-
Try changing your code to this,
IsSuspendedWhileInactive = false;
See if that makes a difference.
-=o=-
You'll need to debug your code.
Instead of calling SendMail, use Print instead,
then isolate why that Print is being called so
much using other Print statements.
//SendMail(....);
Print("Bar=" + CurrentBar + " Calling SendMail now");
If you need more help than that, we'd probably
need to see more code, esp the code that is
calling SendMail.
Last edited by bltdavid; 02-16-2024, 09:53 AM.
- Likes 1
Comment
-
Originally posted by bltdavid View Post
First off, let's consider this code,
Code:if (CurrentBar < -2) return;
I see the highest BarsAgo index used is 3,
so that guard code should actually be,
Code:if (CurrentBar < 3) return;
-=o=-
Try changing your code to this,
IsSuspendedWhileInactive = false;
See if that makes a difference.
-=o=-
You'll need to debug your code.
Instead of calling SendMail, use Print instead,
then isolate why that Print is being called so
much using other Print statements.
//SendMail(....);
Print("Bar=" + CurrentBar + " Calling SendMail now");
If you need more help than that, we'd probably
need to see more code, esp the code that is
calling SendMail.
Last edited by sobertradingpartner; 02-16-2024, 10:20 AM.
Comment
-
Originally posted by sobertradingpartner View PostAS that part of code is working now it was as I suspected, it was running off the historical data.
You should confirm that, with something like this,
SendMail(..., "Testing SendMail",
"Bar=" + CurrentBar + " State=" + State + " Calling SendMail");
Are you using the SendMail API?
Comment
-
Comment
-
Originally posted by bltdavid View Post
But, SendMail is supposed to do nothing when called during State.Historical.
You should confirm that, with something like this,
SendMail(..., "Testing SendMail",
"Bar=" + CurrentBar + " State=" + State + " Calling SendMail");
Are you using the SendMail API?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Tin34, Today, 03:30 AM
|
2 responses
15 views
0 likes
|
Last Post
by Tin34
Today, 04:11 AM
|
||
Started by sastrades, Yesterday, 09:59 AM
|
2 responses
27 views
0 likes
|
Last Post Today, 04:06 AM | ||
Started by ETFVoyageur, Today, 12:52 AM
|
1 response
14 views
0 likes
|
Last Post Today, 03:36 AM | ||
Started by lollers, Today, 03:26 AM
|
0 responses
10 views
0 likes
|
Last Post
by lollers
Today, 03:26 AM
|
||
Started by aliyahany, Today, 03:16 AM
|
0 responses
2 views
0 likes
|
Last Post
by aliyahany
Today, 03:16 AM
|
Comment