Thanks.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Last trade profit
Collapse
X
-
Thanks Kate. the strategy does exactly do that. It takes a trade after X losers. Problem is after the first trade is taken, it completely stops taking trades. What I want to achieve is see the trades it did not take and the trades it took on the chart. I can always open another chart and see all trades taken with all the conditions except the X losers in a row. For some reason after it takes the first trade and say that is a winner, it will not calculate any further on the chart. I want it to continue doing so in order to trade after X losses in a row. Is it possible in Ninja?
Thanks.
-
Sure. Here you go.
You could use a simpler version like if Close[0] > Close[1] then Enter Long. And set profit and stop to 5 ticks.Code:protected override void OnBarUpdate() { NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe; if (barsType == null) return; if (BarsInProgress != 0) return; if (CurrentBars[0] < 20) return; double val1 = barsType.Volumes[CurrentBar].CumulativeDelta; double val2 = barsType.Volumes[CurrentBar-BarsAgo].CumulativeDelta; if (SystemPerformance.AllTrades.Count > 0) { firstTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency; if (SystemPerformance.AllTrades.Count > 1) { secondTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 2].ProfitCurrency; } } // Set 1 if ( Low[0] < Low[BarsAgo] && Close[0] > Open[0] && val1 > val2 && Low[0] <= MIN1[1] && firstTradeProfitCurrency <= 0 && secondTradeProfitCurrency <= 0 ) //&& Low[0] <= MIN(Low,5)[1]) // Low[1] <= MIN(Low,5)[2] { EnterLong(Convert.ToInt32(DefaultQuantity), ""); } // Set 2 if ( High[0] > High[BarsAgo] && Close[0] < Open[0] && val1 < val2 && High[0] >= MAX1[1] && firstTradeProfitCurrency <= 0 && secondTradeProfitCurrency <= 0 )//&& firstTradeProfitCurrency < 0 && secondTradeProfitCurrency < 0 )//High[0] >= MAX(High,5)[1] ) // High[1] >= MAX(High,5)[2] { EnterShort(Convert.ToInt32(DefaultQuantity), ""); }
My problem or challenge I am facing in NT8 is how to let the strategy log in trades when conditions are met and only trade when we see a sequence of X number of winning or losing trades. Because as soon as I do it as in the code above it will not take any more trades after the first one as the sequence does not exist as I guess the strategy is not logging in any more trades. So my main issue here is logging in all trades signaled and only take trades when a sequence is met.
Thanks a lot Angel!!
Comment
-
Hello Trader17,
Thank you for your reply.
SystemPerformance.AllTrades would only contain trades actually taken. Signals that do not take a trade would not be counted in SystemPerformance.AllTrades. You would need to create your own logic to check conditions, using variables to track how many times you've hit certain conditions, and if you get three conditions that would indicate you would have had a "loss" then actually enter after the third time.
Please let us know if we may be of further assistance to you.
- Likes 1
Comment
-
How would you create such logic as a trade has to be taken and completed to get the profit/loss outcome? Where is that record kept if not by System Performance? That is where I am fumbling. I am looking for a log of winning and losing trades without being actually traded by the system. I thought a trade has to be executed in order for the outcome to be logged in. How would I do that without using "Enter Long" in the conditions?
Thanks.
Comment
-
Thanks Kate. So am I on the right track here?
And then in my condition to trade add a condition like if (lastTwoTrades = -2) to only take a trade after 2 losses in a row.Code:protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) return; for (int idx = 1; idx <= 2; idx++) { Trade trade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - idx]; if (trade.ProfitCurrency > 0) { lastTwoTrades++; } else if (trade.ProfitCurrency < 0) { lastTwoTrades--; } }
Am I correct and the code above is Ninja compliant?
Thanks a lot.
Comment
-
So it is not the conditions, but rather the outcome of the condition I am interested in. Do we have an example script somewhere? How can I extract profit/loss figures on a trade without the strategy actually taking the trade? Because System performance only returns profit/loss values of trades actually taken by the strategy. So I am trying to account for "virtual" and "real" trades in a strategy at once. Can NT8 even do such a thing? I am not too sure about extracting profit/loss from a trade without actually taking it.Originally posted by NinjaTrader_Kate View PostHello Trader17,
Thank you for your reply.
SystemPerformance.AllTrades would only contain trades actually taken. Signals that do not take a trade would not be counted in SystemPerformance.AllTrades. You would need to create your own logic to check conditions, using variables to track how many times you've hit certain conditions, and if you get three conditions that would indicate you would have had a "loss" then actually enter after the third time.
Please let us know if we may be of further assistance to you.
Thanks for all your help.Last edited by Trader17; 08-22-2020, 10:22 AM.
Comment
-
Hello Trader17,
Thank you for your reply.
I do not have any examples of such a script. This would require you to do your own tracking with variables for the current price at the time the position would have been opened and closed, and calculating whether the trade would have been a winner or a loser by subtracting the Close price from the Open price. You could then save that value in a List<T> and refer back to that to see how many would have closed negative. The logic could be somewhat tricky and the "virtual trades" you create in this way would not be accounting for market dynamics that could affect fill prices on a "real" order.
Please let us know if we may be of further assistance to you.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
60 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
39 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
20 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
22 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
51 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment