Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Last market position
Collapse
X
-
Last market position
So I have a strategy that I want to alternate from long to short positions or vice versa and the strategy may generate multiple buys or sells in a row but I only want to take the first one and then wait for the market to reverse. Is there a condition I could add like last market position = short for the buys and reverse for the sells?Tags: None
-
Hello burton82,
Thank you for the question.
One way would be to check your current position and then apply your logic for your buy or sell depending what your position is.
Code:if (Position.MarketPosition == MarketPosition.Flat) { //do something like place an order } else if(Position.MarketPosition == MarketPosition.Long) { //logic to determine when the market reverses exit the position that was entered when flat } else if(Position.MarketPosition == MarketPosition.Short) { //logic to determine when the market reverses exit the position that was entered when flat }
Here is the help guide reference on using Position.MarketPosition:
Please let me know if I may be of additional assistance.JesseNinjaTrader Customer Service
-
Thanks that not exactly what I am looking for though, so say lets say the day opens and my strategy enters a long entry and then exits based on the signal generated, then another long entry signal comes, and that is what I do not want to happen until a short signal comes. So basically I do not what to have consecutive long or short signals.
Comment
-
Hello burton82,
Thank you for clarifying that for me. I have an Idea of some logic that you could use, although not knowing the full complexity of your code this may or may not work for you in your perticular situation.
The following logic would be in addition to your conditions for entering and exiting that you already have in place.
To start You could create two integer variables that are set to 0 at start.
So maybe something like this:
Code:#region Variables int longOrder = 0; int shortOrder = 0; #endregion
if the longOrder == 0 after you place your order you would set it to a 1 so the original condition can not be met. This prevents multiple orders in the same direction.
So let’s say you entered long and exited and the condition for your short order is met, after the short orders entry you could reset the longOrder back to 0 so the next time the long orders condition is met it can place an order again.
This is essentially a toggle, if an order is placed, don't place more of the same and wait for the opposite, once the opposite happens don't place any more of the same and again wait for the opposite.
Here is an example of the logic I described
Code:if(longOrder == 0) // if a long order has not been placed, continue. { EnterLong(); //submit the entry longOrder = 1; //add 1 to longOrder so this condition does not happen again until it is 0 again shortOrder = 0; //change shortOrder to 0 so if the short order condition is met a short order can be placed } if(shortOrder == 0) { EnterShort(); shortOrder = 1; //add 1 to shortOrder so this condition does not happen again until it is 0 again longOrder = 0; //change longOrder to 0 so if the longOrder condition is met and a longOrder can be placed again }
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by AttiM, 02-14-2024, 05:20 PM
|
11 responses
184 views
0 likes
|
Last Post Today, 09:28 AM | ||
Started by fernandobr, Today, 09:11 AM
|
1 response
3 views
0 likes
|
Last Post Today, 09:26 AM | ||
Started by timmbbo, Today, 08:59 AM
|
1 response
3 views
0 likes
|
Last Post Today, 09:16 AM | ||
Started by KennyK, 05-29-2017, 02:02 AM
|
2 responses
1,281 views
0 likes
|
Last Post
by marcus2300
Today, 09:13 AM
|
||
Started by itrader46, Today, 09:04 AM
|
1 response
6 views
0 likes
|
Last Post Today, 09:10 AM |
Comment