If not, it could be a useful feature I presume.
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
First tick on Position
Collapse
X
-
First tick on Position
I have a use for setting variables when Position.MarketPosition == MarketPosition.Long only at the first tick of when it is Long. I don't need it setting this variable during every bar of the Long position - just during the first tick when Long is detected. Is there something like IsFirstTickOfLong just as there is IsFirstTickOfBar?
If not, it could be a useful feature I presume.Tags: None
-
Hello Bluebeep,
There would not be anything like this in NinjaScript as this would relate to your custom logic and how you want it to work. You can accomplish this type of goal by using variables and logic along with the existing script properties.
If your script is already running OnEachTick, that would solve part of the question as you could perform checks for each tick. Checking for the position is also something you can do from code so really the only part you would need to figure out would be the setting it once per position part.
This could likely be accomplished by using an object, or even the order's object.
Here is one simple way to do that:
Code:private object placeholderObject = null; protected override void OnBarUpdate() { if(Position.MarketPosition == MarketPosition.Flat) { placeholderObject = null; //when you are flat, reset the object to null so the next time a position is entered you can do this again } if(Position.MarketPosition != MarketPosition.Flat && placeholderObject == null) { placeholderObject = new object(); //set your variables here one time } }
I look forward to being of further assistance.
JesseNinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Kaledus, Today, 01:29 PM
|
1 response
6 views
0 likes
|
Last Post Today, 01:53 PM | ||
Started by frankthearm, Yesterday, 09:08 AM
|
13 responses
45 views
0 likes
|
Last Post
by frankthearm
Today, 01:52 PM
|
||
Started by PaulMohn, Today, 12:36 PM
|
2 responses
16 views
0 likes
|
Last Post
by PaulMohn
Today, 01:48 PM
|
||
Started by Conceptzx, 10-11-2022, 06:38 AM
|
2 responses
55 views
0 likes
|
Last Post
by PhillT
Today, 01:47 PM
|
||
Started by yertle, Yesterday, 08:38 AM
|
8 responses
37 views
0 likes
|
Last Post
by ryjoga
Today, 01:22 PM
|
Comment