You can do your "SetStopLoss" line without the Position check. You effectively are attaching the StopLoss to the Entry Order. However, if your entry is market, then you must figure the price from which you want to calculate your target before execution. Such as Close or Close + assumed slippage - StopLoss.
With a bit more trouble, you can use the following section:
protected override void OnOrderUpdate
And when the order is updated to "filled", only then send out the appropriate StopLoss after getting the confirmed execution price.
There is a section in the NT Help File that discusses this further so that you can make a practical implementation.
Thanks for the info, I will read through OnOrderUpdate. However, I think I am already getting the correct entry price with Position.AvgPrice. I am substracting from that entry price the ATR. But the StopLoss is not executing.
I have seen on some examples that you have to reset the StopLoss / TargetProfit after you are flat??. I will give it a try.
I think I got it to work... but I do not know exactly why.
I added some code to set the stoploss and targetprofit to 1 and 10000 if the market position is flat. I could have used other values, I just wanted to make sure they would not be triggered by price action in the next bar(s).
Here is the code:
What I do not understand has to do with the positioning of this new code. At first, I placed the reseting of the StopLoss and TargetProfit, that is, everything under if(...=MarketPosition.Flat), after the if(...MarketPosition.Long) code and it did not work. But placing it as it is now, it is working. Does anyone know why?
BTW, how can I use the C# code highlighting on my messages?
Instead of using CODE block use PHP block for syntax highlighting on posts on futures.io (formerly BMT). Sorry no time to answer the rest, but I'm sure someone will be nice enough to help you.
Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.
Need help? 1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first. 2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses. 3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make. 4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance. 5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers. 6) Help using the forum? Watch this video to learn general tips on using the site.
If you want to support our community, become an Elite Member.