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)
Intense frustration moving to breakeven+1 in NinjaTrader strategy
After positions are taken, I am monitoring maximum unrealized P/L in a variable called HighestUPnL. When that amount tops $40 (5 ticks in a $10/tick instrument, less transaction fee), I am TRYING to reset the stop to breakeven-1 tick.
The code intended to do so is as follows (I am just showing for short, though have another condition for long):
Per NinjaTrader support, the code to move/set the stoploss is correct. However, when I run the strategy, I get errors, upon trying to take a position, that I can't place orders above (or below, depending whether short or long) the market.
If I comment out the line SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false); I get no errors. This, despite the fact that that code SHOULD only run when the position is open and unrealized P/L is above 40.
When the line is not commented out, the strategy will try to place an order (don't know if for entry or for the stop) MANY points away from the current price.
NT support is telling me it's due to a fast moving market, but no market consistently has transient orders at prices dozens of points away from current market value. They recommended I add, above the line to move the stop to breakeven+1, a line so I have:
When I do so, my strategy never places an order. (I did try to incorporate the GetCurrentBid() check incorporated into the one 'if', but never got that to even compile correctly.)
Despite all my emailing, the tech I am working with insists that the way I am trying to do this screws up because the market is moving too fast and my strategy is trying to place orders above/below inappropriately. However, when telling an ATM strategy to move my stop to breakeven+1, there's never any issue, so I think he's full of it. (I'm a neophyte, so I may be wrong.)
So, I have two issues:
1) My initial order fails if I have the code line below NOT commented out:
Even leaving THAT not commented out makes my initial order fail.
I'm even considering forgetting the stoploss and simply placing limit orders where I want them, but writing the code for that looks even more daunting.
Does anyone have a clue what is going on with this, or have suggestions where to look or what to do? I am fairly desperate, right about now.
Can you help answer these questions from other members on NexusFi?
This is a snippet of code form a robot i wrote, this is actually code that updates both
target and stop to new (higher levels). Use are you own risk
But it might help you forward...
In order to understand what you are trying to do and when
please create a logging :
current price
long or short
previous stop limit
stop limit you are trying to establish
As a sugestion
you might change your code into something :
if (long)
stop < current
SetStopLoss..
else
ExitLong..
if (shot)
stop > current
SetStopLoss
else
ExitShort
(be carefull with exitposition, close to stop's, you might have an OverFill ;-)
which is another headacht
Thank you. The problem I seem to be having is with the syntax of SetStopLoss..., so while your suggestion is good, in terms of cleaning up my code for testing, I'm left with the same syntax that appears to be causing me problems.