Code for Entering Orders with Profit Target and Stop Loss orders - NinjaTrader Programming | futures io social day trading
futures io futures trading


Code for Entering Orders with Profit Target and Stop Loss orders
Updated: Views / Replies:4,744 / 4
Created: by aguison Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Code for Entering Orders with Profit Target and Stop Loss orders

  #1 (permalink)
Membership Revoked
Long Beach CA
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: RUT
 
Posts: 3 since Jun 2013
Thanks: 1 given, 0 received

Code for Entering Orders with Profit Target and Stop Loss orders

Hello

I first did some diligence to see if there were any threads in the forum that could answer my question. Did not find any but I'll apologize in advance just in case I missed them.

I'm coding a strategy that places orders when a signal is triggered (not important how) and encountering an issue when I place my buy or sell limit orders using the EnterLongLimit() or EnterShortLimit() functions of Ninja, I saw that the software does not place the accompanying profit target or stop loss orders for my order that was just entered.

According to the Help guide, using the Managed Orders approach the above should occur automatically, however it is not.

The code for placing my orders is as follows:

EnterLongLimit(0, false, iOrderQty, dLimitPrice, GenerateSignalName("Buy Limit"));

EnterShortLimit(0, false, iOrderQty, dLimitPrice, GenerateSignalName("Sell Limit"));

The code for the profit target and stop loss is as follows:

SetProfitTarget("Profit Target", CalculationMode.Ticks, dProfitTargetTicks);

SetStopLoss("Stop Loss", CalculationMode.Ticks, dStopLossTicks, true);

I tried including the profit target and stop loss code in the Initialize section of the strategy (as per the manual) and when that didn't work, I moved them to the OnBarUpdate() section and that didn't work either.

Checked the Log tab in the Control Center and there are no entries. My entry orders are firing but they are not getting close out. The only thing that is closing them out is the system's Exit on Close automatic routines.

Hoping that someone can show how to resolve this issue or better yet send a code sample that works.

Thanks in advance,

Al G


Last edited by aguison; June 23rd, 2013 at 08:26 PM.
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
 Vendor: www.probabletrades.com 
OC, California, USA
 
Futures Experience: Advanced
Platform: IB/TWS, NinjaTrader, thinkorswim
Favorite Futures: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,860 since Jun 2009
Thanks: 480 given, 3,255 received


Check your signal names for your entries and you stop/profit target. If they don't match then it won't work. Assign a variable to your signal name, then use the same variable in your entry orders and your stop loss and profit targets as well.

I also like to have my signal names be unique so they don't collide with potentially other orders, so I append CurrentBar. This is important if you are making multiple entries but you don't need it if you're only in one entry at a time.

 
Code
string signal;

if (buySignal)
{
   signal = GenerateSignalName("Buy Limit") + CurrentBar;
   EnterLongLimit(0, false, iOrderQty, dLimitPrice, signal);
}
else if (shortSignal)
{
   signal = GenerateSignalName("Sell Limit") + CurrentBar;
   EnterShortLimit(0, false, iOrderQty, dLimitPrice, signal);
}

SetProfitTarget(signal, CalculationMode.Ticks, dProfitTargetTicks);
SetStopLoss(signal, CalculationMode.Ticks, dStopLossTicks, true);


Last edited by shodson; June 24th, 2013 at 01:48 PM.
Reply With Quote
The following user says Thank You to shodson for this post:
 
  #4 (permalink)
Membership Revoked
Long Beach CA
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: RUT
 
Posts: 3 since Jun 2013
Thanks: 1 given, 0 received

Hi Shodson

Good suggestion on using the CurrentBar as the signal name! I tried it and it works!

However in my code I am making calls to the SetProfitTarget and SetStopLoss methods RIGHT BEFORE placing my entry order because I want to make sure the CurrentBar value is updated.

In other words if I move the statements into the Initialize() section, it doesn't appear that it will work since Initialize is only invoked once. Is this correct?

What would you suggest is the proper code implementation for this?

Many thanks,

Al

Reply With Quote
 
  #5 (permalink)
 Vendor: www.probabletrades.com 
OC, California, USA
 
Futures Experience: Advanced
Platform: IB/TWS, NinjaTrader, thinkorswim
Favorite Futures: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,860 since Jun 2009
Thanks: 480 given, 3,255 received


aguison View Post
Hi Shodson

Good suggestion on using the CurrentBar as the signal name! I tried it and it works!

However in my code I am making calls to the SetProfitTarget and SetStopLoss methods RIGHT BEFORE placing my entry order because I want to make sure the CurrentBar value is updated.

In other words if I move the statements into the Initialize() section, it doesn't appear that it will work since Initialize is only invoked once. Is this correct?

What would you suggest is the proper code implementation for this?

Many thanks,

Al

Then use the method signature of SetProfitTarget() and SetStopLoss() that doesn't take a signal name and it will be applied to all entries.

 
Code
SetProfitTarget(CalculationMode.Ticks, dProfitTargetTicks);
SetStopLoss(CalculationMode.Ticks, dStopLossTicks, true);

Reply With Quote
The following user says Thank You to shodson for this post:

Reply



futures io > > > > > Code for Entering Orders with Profit Target and Stop Loss orders

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
tracking each contract's profit target and stop loss sunsun MultiCharts 1 May 6th, 2013 09:10 AM
Calculating Stop and Profit Target via ATR drunkcolonel Psychology and Money Management 14 August 20th, 2012 06:50 AM
on NT7 - Anyway to make market replay have orders sit on the dom/ move stop loss? Itchymoku NinjaTrader 4 May 13th, 2012 02:50 AM
Stop Orders sam028 Terms (Glossary) 0 June 27th, 2010 06:40 PM
Stop Loss/Target & SendMail() dsraider NinjaTrader Programming 4 May 30th, 2010 07:15 AM


All times are GMT -4. The time now is 11:40 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-17 in 0.09 seconds with 19 queries on phoenix via your IP 54.221.73.186