public class MyStrategy: Strategy
{
private int winloss = 0;
protected override void Initialize()
{ CalculateOnBarClose = true; }
protected override void OnBarUpdate()
{
int lotsize;
if (winloss > 0)
{
lotsize = Convert.ToInt32(Math.Round(Lots + (Lots * Math.Log(1+winloss))));
}
else
{
lotsize = Lots;
}
// code to enter long goes here
// Condition set 3
if (an exit long is signaled)
{
winloss = UpdateWL(winloss);
ExitLong("", "");
}
private int UpdateWL(int wl)
{
if (Position.GetProfitLoss(Open[0], PerformanceUnit.Percent) <= 0) // a losing trade
{
if (wl <= 0) { wl--; }
else { wl = -1; }
}
else // a winning trade
{
if (wl >= 0) { wl++; }
else { wl = 1; }
}
return(wl);
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Logic Error
Collapse
X
-
Logic Error
I'm trying to increase my position size after winning trades. Do you have any idea why the position size won't increase with this code?
Code:Tags: None
-
In case it's relevant, I'm using the GAIN feed. I took account to round up to whole numbers since that feed supports a minimum unit size of 1.
-
texasnomad, I would suggest printing the values to the ouput window (like your winloss and lotsize) to check they actually return what you would expect based on your code logic - http://www.ninjatrader-support2.com/...ead.php?t=3418
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
62 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
33 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
44 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
58 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
47 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment