Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Code example needed
Collapse
X
-
Code example needed
My strategy scales in if current unrealized pnl is negative. I am trying to figure out how to add an additional position to my next entree. So if I'm Long with position size 1 then my second entree is size 2, third is 3, and so on. Code example would be greatly appreciated.Tags: None
-
relogical, as a courtesy to get started please find a simple example attached, it works with the Position.Quantity and MarketPosition to check what size you currently have and thus which should be used on next scale in. Please ensure to run with the EntryHandling set to .UniqueEntries from the UI, so multiple signals in the same direction could be executed.Attached Files
-
relogical, right then a more efficient approach would be beneficial - an idea how you could approach this would be in this modified example. We'll hope this will get you going on further custom works in this area.
For demo purposes, it will take up to 10 entries and then hold overnight only exiting on Friday's at 4PM.
Comment
-
relogical, I would just include a tracking variable then you would set to the Close[0] price for example you last had a signal at. As part of the reentry condition when long check that current price needs to be smaller than this variable - your 20 ticks. Once another scale has been done, this tracking variable would again be updated, so you always have the last signal price as reference to check against. If you're flat and have the first entry again of the sequence you would reset it so another cycle could begin.
Comment
-
relogical, here's how this could be addressed in your script's OnBarUpdate() - refPrice is just a double variable to help us with the tracking of the last trade's level.
So you see whenever we trade, we update the tracking variable with the Close[0] value (you can store any you like though) and have a filter condition in place for further entries if long that would check that the current close is 20 tick lower than the last reference point. If positions of the sequence are closed out and strategy acting from flat state again > we update the tracking then as well...Code:if (Position.MarketPosition == MarketPosition.Flat && CrossAbove(Close, KeltnerChannel(1.5, 10).Upper, 1)) { entryCount = 0; entryCount++; EnterLong(1, "Entry"+ entryCount.ToString()); refPrice = Close[0]; } if (entryCount < maxEntries && Position.MarketPosition == MarketPosition.Long && Close[0] < refPrice - 20 * TickSize) { if (CrossAbove(Close, KeltnerChannel(1.5, 10).Lower, 1)) { newSize = entryCount + 1; entryCount++; EnterLong(newSize, "Entry" + entryCount.ToString()); refPrice = Close[0]; } }
Comment
-
relogical, I would then suggest further debugging the strategy you created from the snippet provided to better understand which part of your conditions evaluates differently as you would expect to allow the entry still to happen. Prints statements would be very helpful in the process -
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, 03-13-2026, 05:17 AM
|
0 responses
86 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
151 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
79 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
53 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
61 views
0 likes
|
Last Post
|

Comment