If not, it could be a useful feature I presume.
Announcement
Collapse
No announcement yet.
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:
A different approach could be to use the OnExecutionUpdate override to observe when an order fills, you could assign the Order object to a variable similar to what is shown above. Using the order object and position information you could accomplish the same general task of having a null/not null variable to control timing.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.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
48 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
66 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment