Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Handling reentry after stop trigger
Collapse
X
-
Handling reentry after stop trigger
I have a strategy which generates "buy" and "sell" signals. Now if I set a stop loss for a long trade using setstoploss function and it gets triggered , I want to ignore all the subsequent buy signals and wait until a "sell" signal is generated. For this I need to know whenever a stop gets triggered so that I can set a flag. How do I do this ?Tags: None
-
Hello Sgeesala,
Thank you for your post
You can use the OnOrderUpdate() method to capture when the Stop Loss order it filled and then set a boolean variable to true.
Example:
Code:protected override void OnOrderUpdate(IOrder order) { if(order.OrderState == OrderState.Filled && order.Name == "Stop Loss") waitTilShort = true; }
Cal H.NinjaTrader Customer Service
-
Originally posted by NinjaTrader_Cal View PostHello Sgeesala,
Thank you for your post
You can use the OnOrderUpdate() method to capture when the Stop Loss order it filled and then set a boolean variable to true.
Example:
Code:protected override void OnOrderUpdate(IOrder order) { if(order.OrderState == OrderState.Filled && order.Name == "Stop Loss") waitTilShort = true; }
Comment
-
Hello sgeesala and trader333,
Another way this can be done is by using if(Position.MarketPosition == MarketPosition.Flat). So you can place all your code to enter in the if condition, meaning you will have to be flat before another entry can be taken.
Please visit the following link for information on Position.MarketPosition: http://www.ninjatrader.com/support/h...etposition.htm
Comment
-
Thanks Patrick.
One last question, my strategy is both short and long how do i prevent it from reentering same direction until opposite trade has been entered. let me explain
I am buying when rsi is above 70 and shorting when rsi is below 30. I entered long and once stoploss or profit targets are hit I dont want to reenter in the same direction until I take short trade.
Comment
-
Hello trader333,
Thank you for your response.
The following is a basic example using two bools to switch between going long and short:
Code:#region Variables private bool goLong = true; private bool goShort = true; #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if(RSI(14, 9)[0] > 70 && goLong) { EnterLong(); goLong = false; goShort = true; } else if(RSI(14, 9)[0] < 30 && goShort) { EnterShort(); goLong = true; goShort = false; } }
Comment
-
Can you show how to wait for the next signal regardless as to whether or not it's in the same direction or opposite?
For example, if conditionlong entry is exited with either a stop-loss or profit target, wait until the next conditionlong or conditionshort.Last edited by ScorpioTravis; 01-13-2017, 12:20 PM.
Comment
-
Hello ScorpioTravis,
Thank you for your response.
Once the position is closed it should be waiting for the next signal in any case. If you only want to enter when flat then use the reference at my previous post: http://ninjatrader.com/support/forum...67&postcount=5
Please let me know if you have any questions.
Comment
-
Originally posted by NinjaTrader_PatrickH View Post
Once the position is closed it should be waiting for the next signal in any case.
However, I now see how I can modify the conditionlong so it's not true on subsequent bars after the first bar that it's true..
Thank you.
Comment
-
Hello,
I'm having a similar issue, the strategy conditions for a long trade have been met with a profit target, and I do not want to reenter the market, though the "conditions" to go long still exist.
How do I "code" the strategy to avoid reentering the market.
In summary:
1) conditions are met for long trade
2) profit targets are fulfilled
3) original conditions still exist for long trade
4) NEED EXCEPTION CODE TO AVOID RE-ENTRY
Goal is to wait for next SHORT conditions.
Thanks for your help in advance!
MLT
Comment
-
Hello mlthompson,
Thank you for your post.
Use a bool to switch between trading long and trading short. For example:
Code:public class SwitchExample : Strategy { private bool TradeSwitch; // true for long, false for short private bool FirstTrade = true; // utilize to avoid missing first signal protected override void Initialize() { } protected override void OnBarUpdate() { if (FirstTrade) // place first trade { if (Close[0] > Open[0]) // basic entry condition { EnterLong(); FirstTrade = false; // first trade was placed TradeSwitch = true; // went long } else { EnterShort(); FirstTrade = false; // first trade was placed TradeSwitch = false; // went short } } // Enter short if prior position was long and we are now flat if (TradeSwitch && Position.MarketPosition == MarketPosition.Flat && Close[0] < Open[0]) { EnterShort(); TradeSwitch = false; } // Enter long is prior position was short and we are now flat else if (!TradeSwitch && Position.MarketPosition == MarketPosition.Flat && Close[0] > Open[0]) { EnterLong(); TradeSwitch = true; } } }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rdtdale, Today, 01:02 PM
|
0 responses
2 views
0 likes
|
Last Post
by rdtdale
Today, 01:02 PM
|
||
Started by alifarahani, Today, 09:40 AM
|
3 responses
15 views
0 likes
|
Last Post Today, 12:47 PM | ||
Started by RookieTrader, Today, 09:37 AM
|
4 responses
18 views
0 likes
|
Last Post
by RookieTrader
Today, 12:46 PM
|
||
Started by PaulMohn, Today, 12:36 PM
|
0 responses
7 views
0 likes
|
Last Post
by PaulMohn
Today, 12:36 PM
|
||
Started by love2code2trade, 04-17-2024, 01:45 PM
|
4 responses
41 views
0 likes
|
Last Post Yesterday, 10:31 PM |
Comment