If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: count++

Thanks for this, best info I've received so far. If what I'm trying to count is the # of times the three stock ticker symbols below are triggered for a trade. Would I have to make a seperate variable for each of these below or can I somehow use info from the below initialize section without having to create a new variable for each. The method below is standard to the trading software called Ninja Trader that I use.

Re: count++

Ya, you actually understand what im trying to do thats great. EnterLong() gets called for any stock that meets the entry conditions. Each stock 0 thru 2 is passed thru the entry conditions via the for loop below. 0 being 1st stock, 1 being 2nd stock and so on. I used series instead of stock below. Then the software uses BarsInProgress below I guess to call each Added stock from the initialize section.

for (int series = 0; series < 3; series++)
if (BarsInProgress == series)

//conditions for stock entry where "series" is plugged in.
EnterLong() //enters long for any stock/series thats passing thru at the moment that met conditions
//here count & hold # entries for each particular stock/series that triggered

where you have [stockSymbol] above will that pull each stock in the dictionary through?

and what is ContainsKey?

I will have 100's of stocks so thats why Im trying to loop all stocks through limited code and not have to repeat EnterLong() for each individual stock over and over.

Re: count++

To answer your questions, you need to better define what this is:

There method for entering a trade is
EnterLong()

Does this get called by the framework you are using? and, if so...
Does a separate EnterLong() method get called for each stock?
or
Does a single EnterLong() method get called for all the stocks? If so, how do you know which stock is getting updated?

Re: count++

Yes a single EnterLong() method gets called for all stocks. That for loop that loops the script through 0,1,2... that proceeds BarsInProgress == 0, then goes to BarsInProgress == 1 then BarsInProgress == 2 and so on and dictates which stock is running through. So when 0 is looping through the script the first stock is routing through all the code and ultimately to EnterLong(), then 1 is looping through which is the second stock and so on.

Re: count++

Re: count++

Oh boy well here goes, hope it doesn't scare you away. I used NumEntries++ any place where I was wanting it to count and store entries, but that's not anything that actually functions. After it counts I was wanting it to route back to the bool statement that you will see below to make sure number of entries is < 1.

Re: count++

I took the liberty of formatting your code a bit. I also added curly braces because without them, it's easy to introduce error because a for loop will only act on the first line of code immediately following the for loop (or the if statement). Maybe it works right now without the extra braces, but you might add a line of code and then it won't work as you expect. Better to get into the practice of adding curly braces after for and if statements. Then it's clear to all how the code should work.

That being said, I took a guess as to where the placement of the NumEntries++; statement should go. I probably got it wrong (which is why you should use curly braces).

As far as the code scaring me. I'm not scared, but I really don't know what you are accomplishing with this code. In earlier posts, you mentioned that EnterLong() method gets called. Well, the way you have that coded, you always pass in a value of 200, so I'm not sure what that does.

Also, what is NumEntries? Is that the number of stocks or the number of tick counts? Or the number of times something meets your criteria?

Getting back to what we discussed earlier with keeping track of counts for a particular stock. Looking at your code, you are tracking the stock by it's index (i.e. the series variable), right? Therefore if a stock meets the criteria and you want to increment its count, you can use a dictionary like I described before (except make it a Dictionary<int, int>) and then change your code to:

Re: count++

I just missed a curly bracket when I was copying and pasting and moving things around, sorry about that. And NumEntries++ is just the number of times a particular stock or index meets the criteria and Enters the stock Long. The 200 is just the # of shares to buy. EnterLong(int quantity).

Yes tracking by the index which I named series(could have just named index instead).

Thanks alot! I will experiment with this over the weekend and let you know how I make out.

Re: count++

You can use an dictionary of structs, but you can also keep it simple. Instead of supplying a string, period type and value, can get rid of the period type by converting everything to the lowest unit. For example if you only track hours and seconds (and don't need milli-seconds), convert the hours to seconds and store everything in seconds. Therefore the dictionary will be <string, int> where the int represents the seconds.

Btw, using a struct is a good idea, but try to get this approach working first.