NexusFi: Find Your Edge


Home Menu

 





How to get number of positive and negative strings?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one zokirb with 3 posts (0 thanks)
    2. looks_two Big Mike with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 MXASJ with 1 posts (0 thanks)
    1. trending_up 3,009 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

How to get number of positive and negative strings?

  #1 (permalink)
 
zokirb's Avatar
 zokirb 
Zagreb Hrvatska
 
Experience: Intermediate
Platform: Ninja Trader
Broker: IB/Ninja
Trading: Crude Oil
Posts: 26 since Mar 2011
Thanks Given: 1
Thanks Received: 10

Question is pretty simple and I'm sure it takes two minutes to write the code, but I'm novice in Ninja programming so please help

I need a code to give me the number of strings of winning trades and the number of strings of losing trades in trades executed by my strategy.

Thank you

Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
Cheap historycal L1 data for stocks
Stocks and ETFs
How to apply profiles
Traders Hideout
 
  #3 (permalink)
 
zokirb's Avatar
 zokirb 
Zagreb Hrvatska
 
Experience: Intermediate
Platform: Ninja Trader
Broker: IB/Ninja
Trading: Crude Oil
Posts: 26 since Mar 2011
Thanks Given: 1
Thanks Received: 10


and here is the non working code....


#region Using declarations
using System;
using System.ComponentModel;
using System.Drawing;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
#endregion

namespace NinjaTrader.Strategy
{

[Gui.Design.DisplayName("test")]
public class Test12 : OptimizationType
{
#region variables

private int n;
private int numberOfTrades;
private int numberOfLosingStrings;
private int numberOfWinningStrings;


private double myTrade;
private double myTradeBefore;



#endregion

public override double GetPerformanceValue(SystemPerformance systemPerformance)
{

numberOfTrades = systemPerformance.AllTrades.TradesPerformance.TradesCount;


for ( int n = 0; n < numberOfTrades; n++ )
{
Trade myTrade = systemPerformance.AllTrades[n].ProfitCurrency;
Trade myTradeBefore = systemPerformance.AllTrades[n-1].ProfitCurrency;


if ( myTrade < 0 && myTradeBefore > 0 );
{
numberOfLosingStrings++;
}

if ( myTrade > 0 && myTradeBefore < 0 )
{
numberOfWinningStrings++;
}
}


return numberOfLosingStrings;


}
}
}

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #4 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


zokirb View Post
Question is pretty simple and I'm sure it takes two minutes to write the code, but I'm novice in Ninja programming so please help

I need a code to give me the number of strings of winning trades and the number of strings of losing trades in trades executed by my strategy.

Thank you

By "number of strings" do you mean consecutive winners and losers? You can use the TradesPerformance objects MaxConsecXxx.

int myStringOfLosers = Performance.AllTrades.TradesPerformance.MaxConsecLoser;
int myStringOfWinners = Performance.AllTrades.TradesPerformance.MaxConsecWinner;

Reply With Quote
  #5 (permalink)
 
zokirb's Avatar
 zokirb 
Zagreb Hrvatska
 
Experience: Intermediate
Platform: Ninja Trader
Broker: IB/Ninja
Trading: Crude Oil
Posts: 26 since Mar 2011
Thanks Given: 1
Thanks Received: 10

if trades look like this.... "+" is winner and "-" is loser

++ -- ++++ -- ++++++

there would be three strings of winners and two strings of losers. i'm not looking for max consecutive winners but for number of positive consecutive trades

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #6 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,463 since Jun 2009
Thanks Given: 33,239
Thanks Received: 101,661


zokirb View Post
if trades look like this.... "+" is winner and "-" is loser

++ -- ++++ -- ++++++

there would be three strings of winners and two strings of losers. i'm not looking for max consecutive winners but for number of positive consecutive trades

So basically you would look at the last trade result.

If winner, then increment your _consecutivewinners variable and if a loser then reset your _consecutivewinners variable to 0.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on May 27, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts