NexusFi: Find Your Edge


Home Menu

 





Intense frustration moving to breakeven+1 in NinjaTrader strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one DavidBodhi with 4 posts (0 thanks)
    2. looks_two rleplae with 2 posts (0 thanks)
    3. looks_3 Bartw with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,496 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 8 posts
    2. attach_file 0 attachments




 
Search this Thread

Intense frustration moving to breakeven+1 in NinjaTrader strategy

  #1 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 207

Hello, All.

I have been working on the following for untold hours, with overly vague feedback from NinjaTrader support and am intensely frustrated.

I have a strategy with a stoploss set in the Initialize() region. The entirety of that region is as follows:

protected override void Initialize()
{
SetStopLoss("", CalculationMode.Ticks, 10, false);
Add(SMA(21));
Add(ADX(14));
CalculateOnBarClose = false;
}

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):

// Condition set 3
if (Position.MarketPosition == MarketPosition.Short
&& (HighestUPnL >= 40))
{
SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false);
}

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:

// Condition set 3
if (Position.MarketPosition == MarketPosition.Short
&& (HighestUPnL >= 40))
{
if (Position.AvgPrice - 1 * TickSize < GetCurrentBid())
{
SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false);
}
}

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:

SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false);

2) I cannot get code that works to move my stop to 1 tick of profit.

I can't even get it to go to breakeven using:

SetStopLoss("", CalculationMode.Price, Position.AvgPrice, false);

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.


Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
15 thanks
GFIs1 1 DAX trade per day journal
15 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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...

 
Code
if (mylong == 1 && myturbo2OnOff == 1)
				{
					if (myCCI[0] > myCCI[1] && myCCI[0] > myCCIEMA34[0] && Close [0] > myEMA15[0])
					{ 
						if (High[0] >=  (mylongstop + ((double)myUPDATESTOP /myMULTIPLYER)) && mylongstop > mylongentry )
						{
						 mylongstop = High[0]-((double)8 / myMULTIPLYER);
						 mylongtarget = High [0]+((double)8/myMULTIPLYER);
						 DebugPrint ("Turbo 2 fired, new stop : "+mylongstop+", new target : "+mylongtarget);
 					     SetProfitTarget(CalculationMode.Price,mylongtarget);
					     SetStopLoss(CalculationMode.Price,mylongstop);
						 mynewstop++;
						}
					}
				}

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 207


rleplae View Post
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...

 
Code
if (mylong == 1 && myturbo2OnOff == 1)
				{
					if (myCCI[0] > myCCI[1] && myCCI[0] > myCCIEMA34[0] && Close [0] > myEMA15[0])
					{ 
						if (High[0] >=  (mylongstop + ((double)myUPDATESTOP /myMULTIPLYER)) && mylongstop > mylongentry )
						{
						 mylongstop = High[0]-((double)8 / myMULTIPLYER);
						 mylongtarget = High [0]+((double)8/myMULTIPLYER);
						 DebugPrint ("Turbo 2 fired, new stop : "+mylongstop+", new target : "+mylongtarget);
 					     SetProfitTarget(CalculationMode.Price,mylongtarget);
					     SetStopLoss(CalculationMode.Price,mylongstop);
						 mynewstop++;
						}
					}
				}

Thanks, Becky. It looks pretty much like the code I already have, but I'll review it and see if I can extract insights from it.

Follow me on Twitter Started this thread Reply With Quote
  #5 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

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

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 207


rleplae View Post
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.

Follow me on Twitter Started this thread Reply With Quote
  #7 (permalink)
Bartw
Santa Cruz
 
Posts: 4 since Jul 2019
Thanks Given: 1
Thanks Received: 0

If you are setting a stop loos for a long you must be 2 ticks above the ask.

This is not Ninja trader specific

Reply With Quote
  #8 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 207


Bartw View Post
If you are setting a stop loos for a long you must be 2 ticks above the ask.

This is not Ninja trader specific


Thanks, but the post you replied to is from 7 years ago.

I've had the move to breakeven working for a long time.

Follow me on Twitter Started this thread Reply With Quote
  #9 (permalink)
Bartw
Santa Cruz
 
Posts: 4 since Jul 2019
Thanks Given: 1
Thanks Received: 0

Yeah it came up in a search so I responded.

I am creating my own bracket order Stop and Target always present.

Strategy does it and a separate account watcher does it

Reply With Quote




Last Updated on April 5, 2022


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts