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.
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.Kate W.NinjaTrader Customer Service
- 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?
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
-
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.
Kate W.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by junkone, Today, 11:37 AM
|
2 responses
12 views
0 likes
|
Last Post
by junkone
Today, 12:09 PM
|
||
Started by frankthearm, Yesterday, 09:08 AM
|
12 responses
43 views
0 likes
|
Last Post Today, 12:05 PM | ||
Started by quantismo, 04-17-2024, 05:13 PM
|
5 responses
35 views
0 likes
|
Last Post Today, 11:32 AM | ||
Started by proptrade13, Today, 11:06 AM
|
1 response
7 views
0 likes
|
Last Post Today, 11:27 AM | ||
Started by love2code2trade, 04-17-2024, 01:45 PM
|
4 responses
35 views
0 likes
|
Last Post Yesterday, 10:31 PM |
Comment