![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Dec 2009
Posts: 47
Thanks: 12
Thanked 0 times in 0 posts
|
I am using Enter and Exit orders to unwind positions that are profitable after 3 ticks or better. They are both being ignored. Can't figure out why.
protected override void OnBarUpdate() { // Condition set 1 if (Close[0] > Close[1]) { EnterLongLimit(1, GetCurrentBid(), "Ofc Long"); } // States that if position is profitable by 3 ticks at bid price, exit position at bid price if (GetCurrentBid() >= Position.AvgPrice + 3 * Ticksize) { ExitLongLimit (GetCurrentBid(), "Profit Long"); } // States that if bar following entry long closes against initial position, exit long and go flat. if (Close[0] < Position.AvgPrice) { ExitLongLimit (GetCurrentBid(), "Ofc Long"); } Thank You, Jamie Hendrix |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
Jamie, please set TraceOrders = true in the Initialize() portion of your strategy to see why these orders are being ignored. You can also add some Print() statements to send output to the debugging window (Tools -> Output Window) to verify these code blocks are actually executing:
Code:
if (Close[0] > Close[1])
{
Print("entering long limit at bar: " + Time[0].ToString());
EnterLongLimit(1, GetCurrentBid(), "Ofc Long");
}
// States that if position is profitable by 3 ticks at bid price, exit position at bid price
if (GetCurrentBid() >= Position.AvgPrice + 3 * Ticksize)
{
Print("trying to exit long at bar: " + Time[0].ToString());
ExitLongLimit (GetCurrentBid(), "Profit Long");
}
Austin
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Austin for this post: |
|
|
|
#3 |
|
Member
Join Date: Dec 2009
Posts: 47
Thanks: 12
Thanked 0 times in 0 posts
|
Austin, Thanks very much.... I feel like I am very close.... I have an ATM strategy that I am comfortable working with..... is there any way to call that strategy into use via the automated code? If not, where can I find out how to code the parameters from that strategy into my automated system.
Thanks for your help, Jamie Hendrix |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
There is such a way. Please take a look at the sample provided by NinjaTrader at Tools -> Edit NinjaScript -> Strategy -> SampleAtmStrategy for additional information.
Austin
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Austin for this post: |
|
|
|
#5 |
|
Member
Join Date: Dec 2009
Posts: 47
Thanks: 12
Thanked 0 times in 0 posts
|
I loaded the ATM Strategy template and have tried many things... I even cut and paste most of the code right into my own..... it just does not want to cooperate.... I have an ATM template that I use in manual trading and I would like to incorporate it into my automated system..... all I am missing in my auto system is an auto breakeven which this would take care of.....
I added it to a basic entry signal to test it.... here is what I have.... What am I doing wrong?...... // Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK **** if ((Close[0] >= Close[1] + 3 * TickSize ) && BarsSinceExit() >=2 || BarsSinceExit() == -1) { atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, GetCurrentBid(), 0 , TimeInForce.Day, orderId, "Ofc", atmStrategyId); } if ((Close[0] <= Close[1] - 3 * TickSize ) && BarsSinceExit() >=2 || BarsSinceExit() == -1) { atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Limit, GetCurrentAsk(), 0 , TimeInForce.Day, orderId, "Ofc", atmStrategyId); } // Check for a pending entry order if (orderId.Length > 0) { string[] status = GetAtmStrategyEntryOrderStatus(orderId); // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements if (status.GetLength(0) > 0) { // Print out some information about the order to the output window Print("The entry order average fill price is: " + status[0]); Print("The entry order filled amount is: " + status[1]); Print("The entry order order state is: " + status[2]); // If the order state is terminal, reset the order id value if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected") orderId = string.Empty; } } // If the strategy has terminated reset the strategy id else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat) atmStrategyId = string.Empty; if (atmStrategyId.Length > 0) { // You can change the stop price //if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat) AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId); // Print some information about the strategy to the output window Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId)); Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId)); Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId)) ; Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId)) ; } } Thanks Austin, Jamie Hendrix |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
Hi Jamie, were you able to get the SampleAtmStrategy working by itself? That is a necessary first step before you start using your own strategies. Please keep in mind these strategies do not work on historical data (backtesting).
Austin
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Austin for this post: |
|
|
|
#7 |
|
Member
Join Date: Dec 2009
Posts: 47
Thanks: 12
Thanked 0 times in 0 posts
|
Austin. I loaded the Sample Atm Strategy by itself but nothing happened... no entries??? Not sure what to do next.
Jamie |
|
|
|
|
|
#8 |
|
Member
Join Date: Dec 2009
Posts: 47
Thanks: 12
Thanked 0 times in 0 posts
|
Austin, I got it figured out, just didn't realize about the historical thing.... just zoned out on that one I guess. Two other things I am trying to figure out..... Is there a way for me to turn on the strategy and have it just ignore the first bar of the day and just start on bar two... can't use "to time" cause I use Tick charts. Number two is that I would like it to stop trading after a certain cumulative profit has been reached for the day ( Like once it hits $100, stop trading or 2 points then stop)?
Thanks man, I am almost there. Jamie Hendrix |
|
|
|
|
|
#9 |
|
Member
Join Date: Dec 2009
Posts: 47
Thanks: 12
Thanked 0 times in 0 posts
|
OK Austin I have the first bar thing pretty much figured out... just need the cumulative profit trigger (still has me stumped..... I also want to create a price bracket of the first half hour of trading (630- 700) and have my system only recognize buy signals above this range and only recognize sell signals below the range....
For example. Low price of range (630 - 700) == 1280 High price of range (630- 700) == 1300 recognize long signal > 1300 and recognize Short signal < 1280. THanks man. Jamie Hendrix |
|
|
|
|
|
#10 | ||
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hi JamieHendrix,
Quote:
Quote:
http://www.ninjatrader.com/support/f...4911#post44911
Ryan M
NinjaTrader Customer Service |
||
|
|
|
|
|
#11 | |
|
Senior Member
|
Quote:
Code:
if (Bars.FirstBarOfSession) return; before the first line that processes strategy orders, should take care of that. |
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
|
|
#12 |
|
Member
Join Date: Dec 2009
Posts: 47
Thanks: 12
Thanked 0 times in 0 posts
|
Thanks for your reply man. Do you happen to know how to get indicators to start calculating starting from the first bar? Mine are continuing from the previous days close... totally throwing everything off for about an hour or so.
|
|
|
|
|
|
#13 | |
|
Senior Member
|
Quote:
Code:
private int DeadZoneStartBar = 0; private int DeadZoneEndBar = 7; // or whatever you need private barsRequiredToStartCalculations = 7; // or whatever you need Code:
if (Bars.FirstBarOfSession)
{
DeadZoneStartBar = CurrentBar;
DeadZoneEndBar = CurrentBar + barsRequiredToStartCalculations;
}
if (CurrentBar >= DeadZoneStartBar && CurrentBar < DeadZoneEndBar) return;
// do the rest of stuff here.
|
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
|
|
#14 |
|
Member
Join Date: Dec 2009
Posts: 47
Thanks: 12
Thanked 0 times in 0 posts
|
Thanks for your help... it worked as far as waiting to execute N bars before it trades but it has no effect on when the EMA is calculated.... the chart is taking the last 20 bars of yesterdays close and using that data to calculate in todays open.... this totally throws off at least the first hour of the day.... I can tell it to wait until the second hour to start, but I would rather not.
Again, thanks so much for your help. Jamie Hendrix |
|
|
|
|
|
#15 | |
|
Senior Member
|
Quote:
|
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| NinjaTrader’s 3rd Party Partner Program adds Profitable-Daytrading.com | NinjaTrader_Ray | News and Announcements | 0 | 12-13-2010 02:31 PM |
| try to develop some loe risk profitable stratgey | tah123 | Strategy Development | 1 | 09-21-2010 07:21 AM |
| Slippage and commission applied to Percent Profitable in Strategy Analyzer results? | adamus | Version 7 Beta General Questions & Bug Reports | 3 | 08-09-2010 09:08 AM |
| Profitable aty close | maninjapan | General Programming | 1 | 10-15-2009 01:26 PM |
| sell at the first profitable open - is it possible? | pasmao | General Programming | 1 | 10-14-2008 08:35 AM |