PDA

View Full Version : Issue "re-setting" a counter


Burga1
12-06-2007, 07:26 PM
Greetings,

I'm using a "counter" in my strategy code so as to prevent re-submission of orders on each bar when I do not wish them. It works fine, however I'm having an issue with how to best "reset" the counter so as to enable future trade possibilities...here's what I'm doing:

if("a set of conditions is TRUE" && subsequentCounter < 1)
{
//enter a trade...and...set the counter...
subsequentCounter = 1;
}

My code I've been using to "reset" the counter back to "0" is the following:

if((Position.MarketPosition == MarketPosition.Short) ||
(Position.MarketPosition == MarketPosition.Long))
{
if(subsequentCounter == 1){subsequentCounter = 0;}
} //reset counter if it needs to be after trade triggers

The problem with this (I believe) is that since this code is calculated only upon bar close...if a trade is entered AND exited INTRA-BAR the counter is never going to be "reset"...this causes problems with future trade conditions not triggering trades. I'm looking for suggestions on how to best correct this?

NinjaTrader_Josh
12-07-2007, 12:47 AM
If you are using NT6.5 you can easily accommodate for this by coding in the OnPositionUpdate() method.

When you receive a "filled" event then you submit your counter reset.

Burga1
12-07-2007, 09:36 AM
Hi,

Thanks for the response. My version is 6.0.1000.6 (demo). Are you saying that in version 6.5 there's something called an "OnPositionUpdate" function that is called when orders are placed and/or conditions for order entry have become true?

NinjaTrader_Ray
12-07-2007, 10:48 AM
Yes, version NT 6.5 Beta. You can download the beta within this forum. Please keep in mind that this level of functionality is aimed at advanced programmers.

Burga1
12-07-2007, 10:57 AM
Hi,

So is the Beta necessary for what I wish to do? Is there no equivilant command to use that signifies a "filled" or potentially filled order?

NinjaTrader_Ray
12-07-2007, 11:23 AM
You can always check Position.Quantity to see what is filled etc...

Burga1
12-07-2007, 11:41 AM
OK, so it sounds like I could re-write my "reset" code to read:

if((Position.Quantity == 0)
{
if(subsequentCounter == 1){subsequentCounter = 0;}
} //reset counter if it needs to be after trade triggers

I'm assuming that if "Position.Quantity" returns "0" that no positions are "open", correct?

NinjaTrader_Ray
12-07-2007, 11:46 AM
That is correct.

Burga1
12-07-2007, 11:51 AM
Thanks. Is there a way to associate "Position.Quantity" with different potential trade conditions? So if a strategy for example had 4 conditions that might initiate trade activity when conditions were true is it possible to know which of those "Positions" have quantity values open associated with them?

NinjaTrader_Ray
12-07-2007, 12:56 PM
This is not possible.