View Full Version : Help me with a order
firecan
08-19-2010, 08:36 PM
Hello my name is Salvador, I´m a Ninja Trader´s new user. I have a problem executing this order:
If (ToTime(Time(0)) == ToTime(14,30,00))
{Enter LongLimit(DefaultQuantity,Close[0]+0.0010,"");}
I want call an order of buying 10 picks above the closed bar at an especific hour and I only achieved to buy between 1 to 3 picks above the closed bar. How could I call the order?
And some time buy in the same 14,30,00 bar.
Thank you.
NinjaTrader_Brett
08-19-2010, 10:40 PM
Hello,
Thank you for your first forum post.
I will have a member of our support team respond in the morning.
Thank you for your patience.
NinjaTrader_Bertrand
08-20-2010, 07:16 AM
firecan, you place a long limit entry order above the market, which would fill instantly (it's marketable) - please try placing a Stop limit order instead for your case.
firecan
08-20-2010, 06:36 PM
Hello again, I´ve tried "Enter Long Stop" and ran ok.
Once the order is called and visualized in the chart. If the price does not reach the order, the order is cancelled one minute later,
Hope you can find out how to solve it.
Waiting your reply.
Regards.
Salvador Hernandez
Sevilla
NinjaTrader_Bertrand
08-21-2010, 02:13 AM
firecan, please resubmit the order on the next bar or use the overload that offers you to set the 'liveUntilCancelled' parameter, per default orders expire at the end of bar in NinjaTrader.
firecan
08-23-2010, 10:08 AM
Hello, thank you for your help. I tried to set the liveUntilCancelled parameter but it was not sucsesful. I solve the problem by the moment using 15 minutes bars.
I noticed by reading your post that you live in Hamburg. I should have been in Germany yesterday because it was the rottweiller klubsieger show due to the fact that I´m a rottweiller breader.
By the way, is it possible to send an autobreakeven order at the strategy, I can´t find it out.
Waiting for your reply. Regards.
NinjaTrader_Bertrand
08-23-2010, 10:26 AM
Nice Salvador, I bet that's a challenging profession, too...if you run into order placement issue and wish to debug those in your strategy, the TraceOrders feature we have is very helpful - http://www.ninjatrader.com/support/forum/showthread.php?t=3627
For realtime use, you could call ATM templates to manage exits where a autoBreakeven is setup or use this sample code structure to move the stop as you're into profit -
http://www.ninjatrader.com/support/forum/showthread.php?t=3222
firecan
08-23-2010, 05:48 PM
Hola , de nuevo mi amigo. Lo rottweiler es sólo un hobby , yo soy un bombero.
He resuelto el problema con el punto de equilibrio. Me gustaría saber qué estoy haciendo mal con esta orden :
/ / Condición 1 juego
si ( ToTime ( Tiempo [ 0] ) == ToTime (14 , 30, 00) )
{ EnterLongStop ( DefaultQuantity , Primer plano [0 ] + 0,0005, " ") ; }
{ EnterShortStop ( DefaultQuantity , Cerrar [ 0] - 0,0005, " ") ; }
Se envía la orden de largo por primera vez en el momento adecuado y funciona cuando el precio alcanza . Pero el orden de corto segunda sólo se envía cuando el primero está cerrado.
Lo que realmente quiero es enviar dos pedidos al mismo tiempo, y quiero que al trabajo cuando el precio llega a ellos , los dos de ellos si es necesario.
No estoy buscando para llamar a una orden OCO.
Esperando su respuesta, saludos.
NinjaTrader_Vincent
08-24-2010, 02:23 AM
Hola , de nuevo mi amigo. Lo rottweiler es sólo un hobby , yo soy un bombero.
He resuelto el problema con el punto de equilibrio. Me gustaría saber qué estoy haciendo mal con esta orden :
/ / Condición 1 juego
si ( ToTime ( Tiempo [ 0] ) == ToTime (14 , 30, 00) )
{ EnterLongStop ( DefaultQuantity , Primer plano [0 ] + 0,0005, " ") ; }
{ EnterShortStop ( DefaultQuantity , Cerrar [ 0] - 0,0005, " ") ; }
Se envía la orden de largo por primera vez en el momento adecuado y funciona cuando el precio alcanza . Pero el orden de corto segunda sólo se envía cuando el primero está cerrado.
Lo que realmente quiero es enviar dos pedidos al mismo tiempo, y quiero que al trabajo cuando el precio llega a ellos , los dos de ellos si es necesario.
No estoy buscando para llamar a una orden OCO.
Esperando su respuesta, saludos.
Firecan,
Please write up your posts in English as this forum is English only. We don't address any issues in Spanish or other languages than English.
firecan
08-24-2010, 05:35 AM
Hello my friend.
The Rottweiller thing is just a hobby, I'm a fireman.
I solved the problem with the breakeven.
I'd like to know what am I doing wrong with this order:
if (ToTime(Time[0]) == ToTime(14, 30, 00))
{ EnterLongStop(DefaultQuantity, Close[0] + 0.0005, ""); }
{ EnterShortStop(DefaultQuantity, Close[0] - 0.0005, ""); }
The first long order is sent at the right time and it works when the price reaches it. But the second one is sent only when the first order is closed.
What I really want is to send both orders at the same time, and I want them to work when the price reaches them, the two of them if it's necessary.
I'm not looking to call an OCO order
Waiting for your reply, regards.
NinjaTrader_Bertrand
08-24-2010, 06:04 AM
Thanks for the translation Sevilla, if you're enabling TraceOrders in your strategy you would see ignored orders in your output window while debugging it, this is because you're running into the internal order handling rules with the approach (on NT7 you could use the unmanaged order submission mode not 'guarded' by these rules) -
http://www.ninjatrader-support.com/HelpGuideV6/Overview36.html
Interal Order Handling Rules that Reduce Unwanted Positions
NinjaTrader is a real-time live trading platform and thus we need to ensure that we prevent situations in real-time where you may have multiple orders working accomplishing the same task. An example of this would be if your strategy had a target limit order for 1 contract working and then your strategy issued a market order to close the position. This is dangerous since it could result in both orders getting filled and instead of having a flat position you are now short! To prevent these types of situations, there are some "under the hood" rules that a NinjaScript strategy follows when order methods are called.
For the most part, you do not need to be intimately familiar with these rules as you develop your strategies, its all taken care of for you internal within a strategy. If a rule is violated, you will be notified through an error log in the Control Center log tab when running a strategy in real-time or in a backtest.
The following rules are true per unique signal name excluding market orders:
Methods that generate orders (excluding market orders) to enter a position will be ignored if:
A position is open and an order submitted by an exit method (ExitLongLimit() (http://www.ninjatrader-support.com/HelpGuideV6/ExitLongLimit.html) for example) is active and the order is used to open a position in the opposite direction
A position is open and an order submitted by a set method (SetStopLoss() (http://www.ninjatrader-support.com/HelpGuideV6/SetStopLoss.html) for example) is active and the order is used to open a position in the opposite direction
The strategy position is flat and an order submitted by an enter method (EnterLongLimit() (http://www.ninjatrader-support.com/HelpGuideV6/EnterLongLimit.html) for example) is active and the order is used to open a position in the opposite direction
Methods that generate orders to exit a position will be ignored if a strategy position is open and:
An order submitted by an enter method (EnterLongLimit() (http://www.ninjatrader-support.com/HelpGuideV6/EnterLongLimit.html) for example) is active and this entry order is used to open a position in the opposite direction
An order submitted by a set method (SetStopLoss() (http://www.ninjatrader-support.com/HelpGuideV6/SetStopLoss.html) for example) is active
Set() methods that generate orders to exit a position will be ignored if a strategy position is open and:
An order submitted by an enter method (EnterLongLimit() (http://www.ninjatrader-support.com/HelpGuideV6/EnterLongLimit.html) for example) is active and this entry order is used to open a position in the opposite direction
An order submitted by an exit method (ExitLongLimit() (http://www.ninjatrader-support.com/HelpGuideV6/ExitLongLimit.html) for example) is active
firecan
08-28-2010, 09:33 AM
Hello again.
I have this order:
// Once the price is greater than entry price+10 ticks, set stop loss to breakeven
if (Close[0] >= Position.AvgPrice +10 * TickSize)
{ SetStopLoss(CalculationMode.Price, Position.AvgPrice); }
first I´d like to know why do not work.
And then I´d like to kown how send the stop loss to breakeven when the price arrive to entry +15 ticks, without wait closes a bar.
Thank you.
NinjaTrader_Austin
08-28-2010, 11:49 AM
firecan, is there an error shown in the output window from TraceOrders?
To send in a stop at breakeven without waiting for the bar to close would require you to run only certain logic every tick, and then your main strategy code on every closed bar. There is a reference sample (http://www.ninjatrader.com/support/forum/showthread.php?t=19387) that goes over how to do that. You can also take a look at the reference sample that goes over how to modify your stop loss/profit target (http://www.ninjatrader.com/support/forum/showthread.php?t=3222) prices.
firecan
08-31-2010, 09:54 AM
Hello again.
I have this order that is executed at the exact hour.
if (ToTime(Time[0]) == ToTime(15,45,00))
{ EnterLongStop(DefaultQuantity,Close[0]+0.000005, ""); }
But when I change the hour of entry it stops working, I do not why.
How to do that the order of the hour of entry into the zone of variables and her it could change this one there.
#region Variables
private int stoplossticks = 20;
private int profittargetticks = 100;
Here time of entry
#endregion
Thank you.
NinjaTrader_Bertrand
08-31-2010, 10:03 AM
What kind of chart / timeframe are you running this on? Does it have a bar timestamp at this time, allowing your time condition to evaluate to true and trigger the trade?
You can for example setup a user defined integer input for entering the time -
http://www.ninjatrader.com/support/forum/showthread.php?t=5782
firecan
09-01-2010, 03:27 PM
Hello again
I have this order
#region Variables
private int horas = 00;
private int minutos = 00;
private int segundos = 00;
#endregion
// Condition Entry.
if (ToTime(Time[0]) == ToTime(horas,minutos,segundos))
{ EnterShort }
And send the order sometimes yes and sometimes not.
If you put an hour as 15,00,00 - or 17,30,00 in general it works well.
But if you place 14, 29, 00, or 13, 05, 00, it does not do anything.
Can you tell me why.
Thanks.
(timeframe 15 mint.)
NinjaTrader_Josh
09-01-2010, 03:43 PM
firecan,
That would be expected because your code is looking for an exact match. You are using == which means the timestamp of the bar needs to match exactly the time you push in which is 14:29:00. On a 15 minute chart there would never be any bar timestamped as 14:29 and that is why nothing happens.
Instead you should use numbers that would actually fit with the time frame of your chart or change your logic to use >= or <= and setup a range of acceptable values.
firecan
09-01-2010, 05:36 PM
Ok. thanks I try it. (>=)
And now:
I have this order:
// Once the price is greater than entry price+10 ticks, set stop loss to breakeven
if (Close[0] >= Position.AvgPrice +10 * TickSize)
{ SetStopLoss(CalculationMode.Price, Position.AvgPrice); }
first I´d like to know why do not work.
But that I need is how send the stop loss to breakeven when the price arrive to entry +15 ticks, without wait closes a bar.
Please if is possible do not send to the tutorial again, I do not understand.
Thank you.
NinjaTrader_Bertrand
09-02-2010, 04:29 AM
Firecan, you would need to add print statements to debug your code, making sure the logic triggers to adjust the stop to a new price level - http://www.ninjatrader.com/support/forum/showthread.php?t=3418
You can adjust intrabar when trading it live or in MarketReplay if you set the CalculateOnBarClose setting to false - http://www.ninjatrader-support.com/HelpGuideV6/CalculateOnBarClose1.html
firecan
09-10-2010, 09:34 AM
Hello, someone can help me with the following order.
I try to throw two orders simultaneously to the market.
One (Long) to the current price +10 pips
and another (Short) to the current price-10 pips
I can to do it but in two script different one for Long and other one for Short, I expect it could unify the order.
-----------------------------------------------------------------------------------------------------
// Condition Long.
if (ToTime(Time[0]) == ToTime(horas,minutos,segundos))
{ EnterLongStop(contratos,Close[0]+10, ""); }
------------------------------------------------------------------------------------------------------
// Condition Short.
if (ToTime(Time[0]) == ToTime(horas,minutos,segundos))
{ EnterShortStop(contratos,Close[0]-10, ""); }
--------------------------------------------
If I put both orders in the same script only send the first one order, already is short or long.
I wait there exists some order or way of putting these orders in the same script.
Thanks.
NinjaTrader_Bertrand
09-10-2010, 09:53 AM
firecan, unfortunately you would run into the 'internal order handling rules' with this approach - http://www.ninjatrader-support.com/HelpGuideV6/Overview36.html
You would see this with TraceOrders as debug tool enabled in your script -
http://www.ninjatrader.com/support/forum/showthread.php?t=3627
A workaround is to monitor price and only place one order as needed and CancelOrder the other working one, so you would only have one working order all the time in this case.
firecan
10-20-2010, 10:58 AM
Hello again, I try with samples but don´t speak about prices only SMA. Please can you tell me, what I need change in this code:
// When the pryce is more big than entry price +0.0010 ticks send Stop Loss to Breakeven.
if ( Close (0) >= Position.AvgPrice + 0.0010 * TickSize)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e -0.0001); }
this code need whait close bar (0)
----------------------------------------------------------------------------------
if ( ???:confused:??? >= Position.AvgPrice + 0.0010 * TickSize)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e +0.0001); }
Regards.
NinjaTrader_Bertrand
10-20-2010, 11:14 AM
firecan, you could simply run this code with CalculateOnBarClose set to false in realtime trading, it would then update the Close[0] value intrabar as the bar develops. Should you want to trigger certain conditions still on bar close, please review this sample showing a dual approach to setting this property -
http://www.ninjatrader.com/support/forum/showthread.php?t=19387
firecan
10-20-2010, 12:06 PM
Hello again
I run this code with CalculateOnBarClose set to false in realtime trading. And not OK.
I need to know the code that I need change here. (Entry Price)
if ( ____________________ >= Position.AvgPrice + 0.0010 * TickSize)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e +0.0001); }
Regards.
NinjaTrader_RyanM
10-20-2010, 01:36 PM
Hello firecan,
Can you let us know what it is you're looking to express here?
firecan
10-20-2010, 03:29 PM
Hello again.
I am looking for the order correct order that, after having a long entry, send the Stop Loos to Breakeven+1 when the price arrive +10 ticks from entry price.
Regards.
firecan
10-20-2010, 03:33 PM
if ( Close [0] >= Position.AvgPrice = + 0.0010 * TickSize)
{SetStopLoss (CalculationMode.Price,Position.AvgPrice+0,0001);}
NinjaTrader_RyanM
10-20-2010, 04:06 PM
If you're using TickSize, then you want to use whole numbers rather than decimals to express "10 Ticks"
if (Position.MarketPosition == MarketPosition.Long)
{
if ( Close [0] >= Position.AvgPrice + 10 * TickSize)
{
SetStopLoss (CalculationMode.Price, Position.AvgPrice + TickSize);
}
}
firecan
10-20-2010, 05:19 PM
Thanks for your reply.
I try it right now.
Regards.
firecan
10-22-2010, 05:51 AM
Hello again, thank you, now it run correctly.
I have some questions:
1) I have opened a real account, need to change some parameters into options. I have seen a video and it changes some of them, is necessary or I can operate since it comes from origin.
2) While I am connected the ninja connection loses after a time without realizing any action, ¿ comes predetermined for it, is necessary to change any parameter.
This problem makes me hollow without information when I want to do a replay conection.
Thank you.
(sorry, automatic translation)
NinjaTrader_RyanM
10-22-2010, 09:48 AM
Hello firecan,
If you're looking to define user input parameters, this post can help:
Creating User Defined Input Parameters (http://www.ninjatrader.com/support/forum/showthread.php?t=5782)
We realize that lost connections can be frustrating. A connection state between NinjaTrader and your broker/market data vendor is not dictated by NinjaTrader. The NinjaTrader application only reports the connection state as it is reported by the API you are connected through. NinjaTrader behaves like a radio receiver in that it receives signals from the connected server. If the signals are not coming through, the underlying broker/market data vendor API reports this to the NinjaTrader application which in turn reports this back to you. Once a loss of connection is reported, NinjaTrader or the underlying API wil continuously try to re-establish a connection.
Common reasons that contribute to connection stability are:
ISP issues
Hardware firewall changing IP addresses frequently
Dynamic IP addresses changing frequently intraday. Usually this happens once a week buy you may want to check with your ISP. If they do change daily, requesting a static IP address may help.
With Windows XP SP2, if you have more than 10 open TCPIP socket connections (10 programs making socket connections through the internet) Windows will randomly shut down some connections
Broker/market data servers may be experiencing temporary downtime
firecan
10-22-2010, 01:40 PM
Thanks again.
Once I implemented the strategy, in chart appears the situation of the price entry and stop loss and profit.
Try changing your position and in a few seconds return to initial place.
It is possible with any order to let me move and stay in the new place.
Regards.
NinjaTrader_RyanM
10-22-2010, 01:47 PM
Hello firecan,
This is possible when you connect your NinjaScript stratey to an ATM strategy. Control of these orders is passed on to the ATM strategy and you can manually adjust orders here.
You can view a sample through Tools > Edit NinjaScript > Strategy > SampleAtmStrategy.
http://www.ninjatrader.com/support/helpGuides/nt7/atm_strategy_methods.htm
firecan
10-22-2010, 03:15 PM
Thanks again I´ll try it.
Now I Find a problem with these orders:
Order 1)
if (Close[0] >= Position.AvgPrice + 8 * TickSize)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e + 1 * TickSize);}
Order 2)
if (Close[0] >= Position.AvgPrice + 14 * TickSize)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e + 7 * TickSize);}
While the condition are true the price is going to the new place.
But if the price down the condition is false and the stop loss returns to the starting point.
What I'm doing wrong, how I can fix it
Regards.
NinjaTrader_RyanM
10-22-2010, 03:46 PM
What's happening is your first condition continues to evaluate true. What you can do here is use bool variables so that this first movement is only evaluated once.
VariablesRegion:
private bool firstMove = true;
if (Close[0] >= Position.AvgPrice + 8 * TickSize && firstMove)
{
SetStopLoss(CalculationMode.Price,Position.AvgPric e + 1 * TickSize);
firstMove = false;
}
if (Close[0] >= Position.AvgPrice + 14 * TickSize)
{
SetStopLoss(CalculationMode.Price,Position.AvgPric e + 7 * TickSize);
}
Reset these variables when you're flat.
firecan
10-22-2010, 06:37 PM
Hello.
Dont run OK, something I'm doing wrong.
Maybe dont understand "Reset these variables when you're flat."
How can I do it.
Regards.
NinjaTrader_Austin
10-23-2010, 02:31 PM
Hello.
Dont run OK, something I'm doing wrong.
Maybe dont understand "Reset these variables when you're flat."
How can I do it.
Regards.
Firecan, what Ryan means is that when your strategy is flat, reset the stop losses to a price of 0.
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Price, 0);
}
firecan
10-25-2010, 12:02 PM
Hello again.
This is the code, can you tell me if is it ok.
protected override void Initialize()
{
SetStopLoss(CalculationMode.Ticks, stoplossticks);
SetProfitTarget(CalculationMode.Ticks, profittargetticks);
TraceOrders = true ;
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
// Resetea stop loss y profit al cerrar la posicion.
if (Position.MarketPosition == MarketPosition.Flat)
{ SetStopLoss(CalculationMode.Ticks, stoplossticks); }
// Abierta una posicion Larga, modifica el Stop Loss a Breakeven.
else if (Position.MarketPosition == MarketPosition.Long)
{
/* Cuando el precio es mayor que la entrada en + ? ticks
envia el Stop Loss a Breakeven +/- ? */
if (Close[0] >= Position.AvgPrice + distbreak1 * TickSize && PriMove)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e - enviabreak1 * TickSize); PriMove = false; }
if (Close[0] >= Position.AvgPrice + distbreak2 * TickSize)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e + enviabreak2 * TickSize); }
}
// Condicion de Entrada en Largo.
if (ToTime(Time[0]) == ToTime(horas,minutos,00))
{ EnterLongStop(0, true, contratos, Close[0] + distmercado * TickSize, "Largo 1"); }
NinjaTrader_Josh
10-25-2010, 12:13 PM
firecan,
Your code uses PriMove, but you never reset its value anywhere. You will most likely need logic to reset it or else it will only act once and then never again.
firecan
10-25-2010, 12:30 PM
I have :
#region Variables
private int contratos = 1;
private int profittargetticks = 50;
private int stoplossticks = 10;
private int distmercado = 7;
private int distbreak1 = 0;
private int enviabreak1 = 0;
private int distbreak2 = 0;
private int enviabreak2 = 0;
private int horas = 0;
private int minutos = 0;
private bool PriMove = true;
#endregion
NinjaTrader_Brett
10-25-2010, 12:53 PM
Hello,
These are variable declarations when the script is loaded.
You need to reset this Inside of as well when it is needed to be reset.
OnBarUpdate()
{
}
Let me know if I can be of further assistance.
firecan
10-25-2010, 01:07 PM
Hello again, sorry.
I'm confused . Please, could you write me the missing piece of code and tell me where I put it, thanks
Regards.
NinjaTrader_RyanM
10-25-2010, 01:12 PM
firecan,
You want to reset the stop loss to an initial value when flat. You also want to reset your bool flag.
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, 20);
PriMove = true;
}
firecan
10-25-2010, 02:19 PM
Hello.
I re-wrote the scrip without variables to make it look more clear about what I do.
Could you make it run and tell me where is the error it does not work.
I try to place a pending order on the market at a particular time. And run the stop loss 3 times when touch each price set, without wait close a bar.
I do not why the stop loss only run when the price is +20 , and forget +3 , +8 an +14 ticks.
Regards
firecan
10-25-2010, 02:23 PM
protectedoverridevoid Initialize()
{
SetStopLoss(CalculationMode.Ticks, stoplossticks);
SetProfitTarget(CalculationMode.Ticks, profittargetticks);
TraceOrders = true ;
CalculateOnBarClose = true;
}
protectedoverridevoid OnBarUpdate()
{
// Resetea stop loss y profit al cerrar la posicion.
if (Position.MarketPosition == MarketPosition.Flat)
{ SetStopLoss(CalculationMode.Ticks, stoplossticks); }
// Abierta una posicion Larga, modifica el Stop Loss a Breakeven.
if (Position.MarketPosition == MarketPosition.Long)
firecan
10-25-2010, 02:24 PM
{
if (Close[0] >= Position.AvgPrice +3 * TickSize && PriMove)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e -5 * TickSize); PriMove = false; }
if (Close[0] >= Position.AvgPrice +8 * TickSize && SegMove)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e +1 * TickSize); SegMove = false; }
if (Close[0] >= Position.AvgPrice +14 * TickSize && TerMove)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e +7 * TickSize); TerMove = false; }
if (Close[0] >= Position.AvgPrice +20 * TickSize)
{ SetStopLoss(CalculationMode.Price,Position.AvgPric e +15 * TickSize);}
}
// Condicion de Entrada en Largo.
if (ToTime(Time[0]) == ToTime(horas,minutos,00))
{ EnterLongStop(0,true,contratos,Close[0] +7 * TickSize, "Largo 1"); }
NinjaTrader_RyanM
10-25-2010, 02:30 PM
firecan,
Make sure you are managing your bool variables effectively. They should be true initially and also reset back to true once you're flat.
To help debug this: You can add print statements to any block of code to check if it's being processed properly.
Simplify to a two stage movement first and verify this is working properly, before adding more movements.
firecan
10-25-2010, 05:11 PM
Sorry, I am tired of trying to run the script, I take two months and nothing. If possible, please make it work will be grateful.
NinjaTrader_Bertrand
10-26-2010, 05:19 AM
firecan, we can for sure understand the frustrations involved in custom coding and debugging, however unfortunately we would not offer such services - if you want this code rather professionally custom developed for you the best option would be checking with a certified NinjaScript consultant -
http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm