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 FilesBertrandNinjaTrader Customer Service
-
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.BertrandNinjaTrader Customer Service
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.BertrandNinjaTrader Customer Service
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.
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]; } }
BertrandNinjaTrader Customer Service
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 -
BertrandNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by inanazsocial, Today, 01:15 AM
|
1 response
5 views
0 likes
|
Last Post Today, 02:18 AM | ||
Started by rocketman7, Today, 02:12 AM
|
0 responses
6 views
0 likes
|
Last Post
by rocketman7
Today, 02:12 AM
|
||
Started by dustydbayer, Today, 01:59 AM
|
0 responses
1 view
0 likes
|
Last Post
by dustydbayer
Today, 01:59 AM
|
||
Started by trilliantrader, 04-18-2024, 08:16 AM
|
5 responses
23 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by Davidtowleii, Today, 12:15 AM
|
0 responses
3 views
0 likes
|
Last Post
by Davidtowleii
Today, 12:15 AM
|
Comment