Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am trying to program a simple stop loss and profit target based on a fraction of the ATR value at the bar where the trade was placed, but can not get it to work. Any help would be much welcome!!!
I am using calculatemode.price for the stops and using an if(BarsSinceEntry()==0) in order to set the value of my stops directly after the trade is placed. The code looks like this:
Any ideas on how this could be implemented?
Thanks in advance!
Can you help answer these questions from other members on NexusFi?
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[0] or Close[0] + 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.