PDA

View Full Version : why is this trailing stop getting rejected


junkone
05-01-2009, 11:29 AM
protectedoverridevoid OnExecution(IExecution execution)
{
Print("got execution" + execution.Order.FromEntrySignal );

if((entryOrder != null) && (execution.Order.Token == entryOrder.Token)){

highestHigh = lowestLow = entryOrder.AvgFillPrice;
if (Position.Quantity > positionSize)
{

ordersDictionary.Add(PositionIndex.Last, PositionStates.inTrade);
ordersQuantity.Add(PositionIndex.Last,Position.Qua ntity- positionSize);
ordersEntrySignalName.Add(PositionIndex.Last, execution.Order.FromEntrySignal);


}
ordersDictionary.Add(PositionIndex.First, PositionStates.inTrade);
ordersQuantity.Add(PositionIndex.First, positionSize);
ordersEntrySignalName.Add(PositionIndex.First, execution.Order.FromEntrySignal);
Print("setup stops");
Print("ATR Value " + ATRValue);
SetTrailStop("ENTRY_ZLR", CalculationMode.Ticks, ATRValue, false);
}


the logs are
01/05/2009 1:21:33 PM Execution Execution='dbc54e82ef9a496fa9e72b85205429e8' Instrument='$USDJPY' Account='Sim101' Exchange=Default Price=99.45 Quantity=0.02M Market position=Long Operation=Insert Order='9bdbb3bb681942f1a56916c108185e57' Time='01/05/2009 1:21:33 PM' Multiplier=0.001 Rate=0.0100563153660499
]

01/05/2009 1:21:33 PM Order Order='707da53031c84583a4dcc935f2e4d1c0/Sim101' Name='Trail stop' New State=Rejected Instrument='$USDJPY' Action=Sell Limit price=0 Stop price=99.45 Quantity=0.02M Type=Stop Filled=0 Fill price=0 Error=OrderRejected Native error='Sell stop or sell stop limit orders can't be placed above the market.'

The ATRvalue @ this point is ATR Value 0.0582825907257643
it filled @ 99.45 and is trying to setup a stop @ 99.45
why is it setting a stop @ 99.45

should it not be setting it atleast 5 ticks below the current price.

NinjaTrader_Bertrand
05-01-2009, 11:46 AM
Hi junkone, your ATR value is 0.0582825907257643 which is very to close 0 ticks - try this multiplied by a factor of for example 100.

junkone
05-01-2009, 12:36 PM
so if i set it to CalculationMode.Price would it then trail stop @ .05 of the exeution price and as it rises higher?
.05 is basically 5 pips range

NinjaTrader_Bertrand
05-01-2009, 12:47 PM
Yes, you could set it to price mode, but then you should put in OnBarUpdate().

junkone
05-01-2009, 01:04 PM
why cannot i see the trail stop in my orders tab. i can see it being outputted to my output tab as i had set
TraceOrders = true;

NinjaTrader_Bertrand
05-01-2009, 01:18 PM
Not sure junkone - does it appear as working order on the SuperDOM?

junkone
05-01-2009, 01:26 PM
would a trail stop kick inonly if there is initial profits? or would it trail from my execution price?

NinjaTrader_Josh
05-01-2009, 01:39 PM
Execution price.

junkone
05-01-2009, 05:51 PM
i simplified my strategy to debug. for some reason, its not triggering my trail stop. here is the code. pl let me know what is wrong

namespace NinjaTrader.Strategy
{
publicclass MyCustomStrategy : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; privatedouble ATRValue=0;
#endregion
protectedoverridevoid Initialize()
{
CalculateOnBarClose = false;

TraceOrders = true;
EntriesPerDirection = 1;
CalculateOnBarClose = false;
}
protectedoverridevoid OnBarUpdate()
{
if(Position.MarketPosition==MarketPosition.Flat){
EnterLong(40000,"buying");
ATRValue = ATR(14)[0];
}
else


{
SetTrailStop("buying", CalculationMode.Price,.0005, false);
}
}
}
}

roonius
05-01-2009, 06:37 PM
Set it at the same time when Entering position

SetTrailStop("buying", CalculationMode.Ticks,5, false);

junkone
05-01-2009, 07:28 PM
i changed it but no effect
protectedoverridevoid OnBarUpdate()
{

if(Position.MarketPosition==MarketPosition.Flat){
SetTrailStop("buying", CalculationMode.Price,.0005, false);
EnterLong(40000,"buying");
SetTrailStop("buying", CalculationMode.Price,.0005, false);
ATRValue = ATR(14)[0];
}

// if((Position.MarketPosition==MarketPosition.Long) && (Position.GetProfitLoss(Close[0], PerformanceUnit.Points)>2)){
// ExitLong(20000,"Exiting","buying");
// }
else
Print("ATRVAlue"+ ATRValue);
Print("Close" + Close[0]);


{
SetTrailStop("buying", CalculationMode.Price,.0005, false);
}
}

roonius
05-01-2009, 08:21 PM
i changed it but no effect
protectedoverridevoid OnBarUpdate()
{

if(Position.MarketPosition==MarketPosition.Flat){
SetTrailStop("buying", CalculationMode.Price,.0005, false);
EnterLong(40000,"buying");
SetTrailStop("buying", CalculationMode.Price,.0005, false);
ATRValue = ATR(14)[0];
}

// if((Position.MarketPosition==MarketPosition.Long) && (Position.GetProfitLoss(Close[0], PerformanceUnit.Points)>2)){
// ExitLong(20000,"Exiting","buying");
// }
else
Print("ATRVAlue"+ ATRValue);
Print("Close" + Close[0]);


{
SetTrailStop("buying", CalculationMode.Price,.0005, false);
}
}

CalculationMode.Ticks, 5

What role ATR supose to play here?

junkone
05-02-2009, 07:14 AM
i want to trail stop to 1 ATR.

junkone
05-02-2009, 07:50 AM
now this makes me mad. i have been led on a goose chase wasting a good full day worth of effort.
SetTrailStop("buying", CalculationMode.Ticks,5, false);=WORKS
SetTrailStop("buying", CalculationMode.Price,.0005, false);= DOES NOT WORK.


some one from NT better come up with some explanation....,

NinjaTrader_Josh
05-02-2009, 03:28 PM
junkone,

Everything works as expected. CalculationMode.Price means you type in the EXACT price you want your stop to be at. You do not type in the price you want to offset. That is what CalculationMode.Ticks is for.

junkone
05-02-2009, 06:32 PM
do you guys know what trailing stop means.

http://www.interactivebrokers.com/en/trading/orders/trailingStops.php

it means follow the price with a certail threshold.
excact price is not trailing stop. exact price is STOP. plus, i did not get the ORDER initiated that i can see in my control center

roonius
05-02-2009, 07:33 PM
do you guys know what trailing stop means.

http://www.interactivebrokers.com/en/trading/orders/trailingStops.php

it means follow the price with a certail threshold.
excact price is not trailing stop. exact price is STOP. plus, i did not get the ORDER initiated that i can see in my control center

So you set the trailing stop which follows by certain amount of ticks.
You told in your previous post that it's working. Where is the problem?

junkone
05-03-2009, 04:12 AM
if you set trail stop by certain price for eg if i want to trail stop by 1 ATR in price, it does not create the trail stop order. that is where the prob is.
SetTrailStop("buying", CalculationMode.Price,.0005, false);
does not work.

Funny. all the stuff in NT docs does not work if you set calculationmode.price

SetTrailStop()
Definition
Generates a trail stop order to exit a position. Trail stops are ammended on a tick by tick basis. Trail stop orders are real working orders (unless simulated is specified in which case the stop order is locally simulated and submitted as market once triggered) submitted immediately to the market upon receiving an execution from an entry order.

NinjaTrader_Josh
05-03-2009, 04:13 PM
junkone,

As stated, if you want a trailing stop of a certain tick offset use CalculationMode.Ticks. You are NOT using CalculationMode.Price properly. CalculationMode.Price sets the trailing stop at an EXACT price value. This is the initial stop and after price starts moving up it will trail up from that initial start.

junkone
05-03-2009, 07:30 PM
This is not very clearly identified as you are stating in the docs.

additionally pl explain why i dont see the stop order on my command console when i set this statement
SetTrailStop("buying", CalculationMode.Price,.0005, false);= DOES NOT WORK.

why did i dnot see the stop order @ .0005?

NinjaTrader_Josh
05-04-2009, 07:23 AM
junkone,

In the docs, the expanded definition exists on the SetStopLoss() page. http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?SetStopLoss
Thank you for bringing to light that it does not appear in the SetTrailStop().

0.0005 is likely not a valid stop price because it is way too far from the currently traded price. That is one reason why you may have not seen it. You will need to use TraceOrders = true in your Initialize() method to fully understand what did/did not occur with your order.

junkone
05-04-2009, 12:31 PM
frankly, i dont see the trail stop order if i use price. i even tried the following line
SetTrailStop(entry.FromEntrySignal, CalculationMode.Price,Close[0]-.0005, false);

i am working on EURUSD. SO 5 pips should be a valid trail stop. i can see my output window getting
23/04/2009 7:09:17 AM Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='' Mode=Price Value=1.3047 Currency=0 Simulated=False
Close1.3052profits in currency 7.99999999999912

but it is not seen in the order in the control center. so you have a bug!!!!!

NinjaTrader_Josh
05-04-2009, 01:13 PM
junkone,
We will look into it, but for your intents and purposes please use CalculationMode.Ticks.