PDA

View Full Version : Breakeven Stop


jlm0@infionline.net
10-24-2007, 08:29 AM
Is there a way in Ninjascript to place a breakeven stop, once a certain level of ticks above entry price has been reached?
Seems it would be simple, but I'm a newbie to coding.

NinjaTrader_Ray
10-24-2007, 08:43 AM
Absolutely! The following link will take you to a reference sample that will demonstrate this concept.

http://www.ninjatrader-support.com/vb/showthread.php?t=3222

jlm0@infionline.net
10-24-2007, 09:02 AM
Thanks Ray, looks good to me.

jlm0@infionline.net
10-29-2007, 08:30 AM
I am getting an error message saying "the name "stoplossticks" does not exist in the current context".

NinjaTrader_Ray
10-29-2007, 08:34 AM
This means that the variable "stoplossticks" does not exist. Could be a spelling typo or something like that if you believe you have declared this variable.

jlm0@infionline.net
10-29-2007, 08:42 AM
I copied it from the sample strategy.
Here's my code:
protected override void Initialize()
{
CalculateOnBarClose = false;
// SetProfitTarget(CalculationMode.Ticks, 20);
SetStopLoss(CalculationMode.Ticks, stoplossticks);


// ExitOnClose = true;

}

NinjaTrader_Josh
10-29-2007, 11:05 AM
If you go back to look at the SamplePriceModification reference sample please take note of the "Variables" and "Properties" sections of the code. In the "Variables" section you will see where stoplossticks was defined. Here is the code snippet from there.
private int stoplossticks = 20;In the "Properties" section of the code you will see how I made that a user definable input with this code segment.
/// <summary>
/// </summary>
[Description("Numbers of ticks away from entry price for the Stop Loss order")]
[Category("Parameters")]
public int StopLossTicks
{
get { return stoplossticks; }
set { stoplossticks = Math.Max(0, value); }
}Because I defined stoplossticks in the "Variables" section I can use that variable in the Initialize() method. You will need to do the same if you wish to use a variable. Alternatively, you can just input an integer in place of stoplossticks so for example:
SetStopLoss(CalculationMode.Ticks, 4);http://www.ninjatrader-support.com/HelpGuideV6/SetStopLoss.html

jlm0@infionline.net
10-29-2007, 11:52 AM
I think I have it now.
Thanks