NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 07-16-2011, 09:26 AM   #1
svlad1983
Junior Member
 
Join Date: May 2009
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default StopLoss executed immediately!

Hi,

I'm having a very simple scalping strategy and on signal I execute the following code:

Code:
EnterShort(Lot,"LNG");
							SetProfitTarget("LNG", CalculationMode.Ticks, TakeProfit*TickSize);
							SetStopLoss("LNG", CalculationMode.Ticks, StopLoss*TickSize, true);
But when I try to execute this code in Backtesting basically After order is entered it exits right away, like stoploss is 0.

Here is the trace:

7/8/2011 2:29:47 PM Entered internal PlaceOrder() method at 7/8/2011 2:29:47 PM: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='SHRT' FromEntrySignal=''
7/8/2011 2:29:47 PM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='SHRT' Mode=Ticks Value=0.0002 Currency=0 Simulated=False
7/8/2011 2:29:47 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='SHRT' Mode=Ticks Value=0.0004 Currency=0 Simulated=True
7/8/2011 2:29:47 PM Cancelled pending exit order, since associated position is closed: Order='NT-00002/Backtest' Name='Profit target' State=Working Instrument='6E 09-11' Action=Sell Limit price=1.4219 Stop price=0 Quantity=1 Strategy='Scalper' Type=Limit Tif=Gtc Oco='NT-00000-454' Filled=0 Fill price=0 Token='9a318e0d13624113b97b6b85c9bb479a' Gtd='12/1/2099 12:00:00 AM'
7/8/2011 2:29:47 PM Cancelled OCO paired order: BarsInProgress=0: Order='NT-00002/Backtest' Name='Profit target' State=Cancelled Instrument='6E 09-11' Action=Sell Limit price=1.4219 Stop price=0 Quantity=1 Strategy='Scalper' Type=Limit Tif=Gtc Oco='NT-00000-454' Filled=0 Fill price=0 Token='9a318e0d13624113b97b6b85c9bb479a' Gtd='12/1/2099 12:00:00 AM'
7/8/2011 2:30:00 PM Entered internal PlaceOrder() method at 7/8/2011 2:30:00 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LNG' FromEntrySignal=''
7/8/2011 2:30:00 PM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='LNG' Mode=Ticks Value=0.0002 Currency=0 Simulated=False
7/8/2011 2:30:00 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LNG' Mode=Ticks Value=0.0004 Currency=0 Simulated=True
7/8/2011 2:30:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00005/Backtest' Name='Profit target' State=Working Instrument='6E 09-11' Action=BuyToCover Limit price=1.4229 Stop price=0 Quantity=1 Strategy='Scalper' Type=Limit Tif=Gtc Oco='NT-00002-454' Filled=0 Fill price=0 Token='ce2a098eb5d547728e0037ad1b784226' Gtd='12/1/2099 12:00:00 AM'
7/8/2011 2:30:00 PM Cancelled OCO paired order: BarsInProgress=0: Order='NT-00005/Backtest' Name='Profit target' State=Cancelled Instrument='6E 09-11' Action=BuyToCover Limit price=1.4229 Stop price=0 Quantity=1 Strategy='Scalper' Type=Limit Tif=Gtc Oco='NT-00002-454' Filled=0 Fill price=0 Token='ce2a098eb5d547728e0037ad1b784226' Gtd='12/1/2099 12:00:00 AM'


Anyone could help me please?
svlad1983 is offline  
Reply With Quote
Old 07-16-2011, 02:14 PM   #2
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
Default

svlad, what values are you using for TakeProfit and StopLoss?
NinjaTrader_Austin is offline  
Reply With Quote
Old 07-16-2011, 02:25 PM   #3
svlad1983
Junior Member
 
Join Date: May 2009
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default

Takeprofit - 2 and stoploss - 4. you can see it from traces.
but it closes exactly at opening price, so Profit is always 0
svlad1983 is offline  
Reply With Quote
Old 07-17-2011, 12:44 PM   #4
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
Default

Thanks, svlad. What sort of timeframe are you running this on? If an order is filled in the backtester and the bar is taller than the stop/target, the stop/target will be executed immediately on that bar.
NinjaTrader_Austin is offline  
Reply With Quote
Old 07-18-2011, 12:47 AM   #5
svlad1983
Junior Member
 
Join Date: May 2009
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default

Im running this on 1Tick bars as the main DataSeries, so it shouldnt give this problem.

do you have any other ideas?
svlad1983 is offline  
Reply With Quote
Old 07-18-2011, 04:45 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

Do you set those stoplosses and targets from the Initialize() or OnBarUpdate()?

If OnBarUpdate() please try setting them before executing your entry and then recheck.
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ATM StopLoss executed after session close Camdo Version 7 Beta General Questions & Bug Reports 6 03-08-2010 01:53 PM
IB CL StopLoss not being executed Bluepoint Automated Trading 1 02-02-2010 07:34 AM
How do I know when a stoploss was executed? Beauregard Strategy Development 1 01-10-2010 10:44 AM
stoploss not executed Beauregard Strategy Analyzer 2 01-03-2010 10:28 AM
Checking if Stoploss is executed? darckeen Strategy Development 1 04-14-2009 04:39 AM


All times are GMT -6. The time now is 08:33 PM.