Order Entry, Target, Trailing Stop, and Exit - EasyLanguage Programming | futures io social day trading
futures io futures trading


Order Entry, Target, Trailing Stop, and Exit
Updated: Views / Replies:1,788 / 18
Created: by DrRon 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
 

Order Entry, Target, Trailing Stop, and Exit

  #1 (permalink)
Trading Apprentice
Irvine CA
 
Futures Experience: Advanced
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Favorite Futures: CL
 
Posts: 8 since Aug 2015
Thanks: 11 given, 0 received

Order Entry, Target, Trailing Stop, and Exit

Hello fellow coders,

I consider myself to be a moderate Easy Language coder.

I have coded for a Strategy that if its conditions are met, I can then place an order (long or short depends on the direction that has been determined) with an entry, a target, and a trailing stop at the opening of the new bar.

However, there is a caveat. If the order is not filled within the next 2 bars, then I want the order to cancel. Also, if the order is filled and the target or the stop is not filled within the next 4 bars, then I want to exit the trade at market.

I also want the trailing stop to trail after it has moved into the profitable territory a bit, so that at minimum it makes a 1-tick profit and continues trailing as certain percentages of profit has reached.

Thank you

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)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary


Hi DrRon,

you can store the bar number when you send the orders and then cancel the orders after X bars. As a hint, the order will be cancelled when a condition for the order is not present anymore.
The same can be done for exiting the trade at market. Store the bar number of your entry and after Y bars send a market order to close your position.

Regards,
ABCTG


DrRon View Post
Hello fellow coders,

I consider myself to be a moderate Easy Language coder.

I have coded for a Strategy that if its conditions are met, I can then place an order (long or short depends on the direction that has been determined) with an entry, a target, and a trailing stop at the opening of the new bar.

However, there is a caveat. If the order is not filled within the next 2 bars, then I want the order to cancel. Also, if the order is filled and the target or the stop is not filled within the next 4 bars, then I want to exit the trade at market.

I also want the trailing stop to trail after it has moved into the profitable territory a bit, so that at minimum it makes a 1-tick profit and continues trailing as certain percentages of profit has reached.

Thank you


Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #4 (permalink)
Trading Apprentice
Irvine CA
 
Futures Experience: Advanced
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Favorite Futures: CL
 
Posts: 8 since Aug 2015
Thanks: 11 given, 0 received

Actual Code

Thank you ABCTG. However, would you in fact show me the code the way you would write it please?

Reply With Quote
 
  #5 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 received

By the way, for closing a position you can also use PosTradeEntryBar(), which you then only need to subtract from the current bar number (Symbol_CurrentBar).


DrRon View Post
Thank you ABCTG. However, would you in fact show me the code the way you would write it please?

Can you share your code (attempt) till now? That way we can give more focused feedback and then you'll learn the most, as opposed to being given a copy/paste solution.

Reply With Quote
The following 2 users say Thank You to Jura for this post:
 
  #6 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

I agree with Jura, posting your code attempt and using feedback to improve it will in the end help you much more in climbing the next step up from being a "moderate Easy Language coder".

PosTradeEntryBar will only work in Multicharts though, for Tradestation you'd have to use OOEL and this requires a bit more advanced skills. You can however use BarsSinceEntry() and it should work fine when not dealing with multi leg entries.

Regards,
ABCTG


Jura View Post
By the way, for closing a position you can also use PosTradeEntryBar(), which you then only need to subtract from the current bar number (Symbol_CurrentBar).


Can you share your code (attempt) till now? That way we can give more focused feedback and then you'll learn the most, as opposed to being given a copy/paste solution.


Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
 
  #7 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 received


ABCTG View Post
PosTradeEntryBar will only work in Multicharts though, for Tradestation you'd have to use OOEL and this requires a bit more advanced skills. You can however use BarsSinceEntry() and it should work fine when not dealing with multi leg entries.

Oops. Good catch.

Reply With Quote
The following user says Thank You to Jura for this post:
 
  #8 (permalink)
Trading Apprentice
Irvine CA
 
Futures Experience: Advanced
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Favorite Futures: CL
 
Posts: 8 since Aug 2015
Thanks: 11 given, 0 received


ABCTG View Post
I agree with Jura, posting your code attempt and using feedback to improve it will in the end help you much more in climbing the next step up from being a "moderate Easy Language coder".

PosTradeEntryBar will only work in Multicharts though, for Tradestation you'd have to use OOEL and this requires a bit more advanced skills. You can however use BarsSinceEntry() and it should work fine when not dealing with multi leg entries.

Regards,
ABCTG

Thank you ABCTG & Jura. I wrote some simple code to get the order execution portion of the coding running correctly. Here is how far I've gotten so far and I haven't been successful at the order execution portion of the coding yet! I haven't even gotten into canceling an order yet either.

 
Code
Inputs:
Numb_Shares(10), //[DisplayName="Number of Shares",ToolTip="Enter the number of shares per trade."],
Min_Range(1), //[DisplayName="Minimum Range",ToolTip="Minimum range to trade."],
Max_Range(10), //[DisplayName="Maximum Range",ToolTip="Maximum range to trade."],
Bullish(1), //[DisplayName="Bullish Trades",ToolTip="Do you want to take bullish trades?(0=No/1=Yes)"],
Bearish(1), //[DisplayName="Bearish Trades",ToolTip="Do you want to take bearish trades?(0=No/1=Yes)"],
x(.2); //[DisplayName="Threshold",ToolTip="What threshold do wish to trade with?"],
Variables:
Bull(False),
Bear(False),
BuyTarget(0),
SellTarget(0),
BuyStop(0),
SellStop(0);
If BarStatus(1)=2 And Range>=Min_Range And Range<=Max_Range Then
	Begin
	Bull=Open<Close;
	Bear=Open>Close;
	If MarketPosition(0)=0 Then
		Begin
		If Bullish=1 And Bull
		Then
			Begin
			Buy Numb_Shares Shares Next Bar At High Stop;
			BuyTarget=High+(Range*x);
			BuyStop=Low+(Range*x);
			SetProfitTarget(BuyTarget);
			SetStopLoss(BuyStop);
			Print(File("c:\testOrderExe.txt"),Date,Time,Close,"Bullish",High,BuyTarget,BuyStop);
			End
		Else
		If Bearish=1 And Bear
		Then
			Begin
			Sell Short Numb_Shares Shares Next Bar At Low Stop;
			SellTarget=Low-(Range*x);
			SellStop=High-(Range*x);
			SetProfitTarget(SellTarget);
			SetStopLoss(SellStop);
			Print(File("c:\testOrderExe.txt"),Date,Time,Close,"Bearish",Low,SellTarget,SellStop);
			End;
		End;
	End;

Reply With Quote
 
  #9 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

DrRon,

you place your stop and target reserved words inside conditional checks. This means these will only be active when the conditions are true, too. Whenever your conditions are false you'd be left without a stop and target.

Please elaborate what the exact issues are that you are seeing with your code.

Regards,
ABCTG


DrRon View Post
Thank you ABCTG & Jura. I wrote some simple code to get the order execution portion of the coding running correctly. Here is how far I've gotten so far and I haven't been successful at the order execution portion of the coding yet! I haven't even gotten into canceling an order yet either.

 
Code
Inputs:
Numb_Shares(10), //[DisplayName="Number of Shares",ToolTip="Enter the number of shares per trade."],
Min_Range(1), //[DisplayName="Minimum Range",ToolTip="Minimum range to trade."],
Max_Range(10), //[DisplayName="Maximum Range",ToolTip="Maximum range to trade."],
Bullish(1), //[DisplayName="Bullish Trades",ToolTip="Do you want to take bullish trades?(0=No/1=Yes)"],
Bearish(1), //[DisplayName="Bearish Trades",ToolTip="Do you want to take bearish trades?(0=No/1=Yes)"],
x(.2); //[DisplayName="Threshold",ToolTip="What threshold do wish to trade with?"],
Variables:
Bull(False),
Bear(False),
BuyTarget(0),
SellTarget(0),
BuyStop(0),
SellStop(0);
If BarStatus(1)=2 And Range>=Min_Range And Range<=Max_Range Then
	Begin
	Bull=Open<Close;
	Bear=Open>Close;
	If MarketPosition(0)=0 Then
		Begin
		If Bullish=1 And Bull
		Then
			Begin
			Buy Numb_Shares Shares Next Bar At High Stop;
			BuyTarget=High+(Range*x);
			BuyStop=Low+(Range*x);
			SetProfitTarget(BuyTarget);
			SetStopLoss(BuyStop);
			Print(File("c:\testOrderExe.txt"),Date,Time,Close,"Bullish",High,BuyTarget,BuyStop);
			End
		Else
		If Bearish=1 And Bear
		Then
			Begin
			Sell Short Numb_Shares Shares Next Bar At Low Stop;
			SellTarget=Low-(Range*x);
			SellStop=High-(Range*x);
			SetProfitTarget(SellTarget);
			SetStopLoss(SellStop);
			Print(File("c:\testOrderExe.txt"),Date,Time,Close,"Bearish",Low,SellTarget,SellStop);
			End;
		End;
	End;


Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #10 (permalink)
Trading Apprentice
Irvine CA
 
Futures Experience: Advanced
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Favorite Futures: CL
 
Posts: 8 since Aug 2015
Thanks: 11 given, 0 received

Entry, Target, and Stop



ABCTG View Post
DrRon,

you place your stop and target reserved words inside conditional checks. This means these will only be active when the conditions are true, too. Whenever your conditions are false you'd be left without a stop and target.

Please elaborate what the exact issues are that you are seeing with your code.

Regards,
ABCTG

Thank you ABCTG. I cleaned up my code a bit more as shown below:

 
Code
If BarStatus(1)=2 And Range>=Min_Range And Range<=Max_Range Then
	Begin
	Bull=Open<Close;
	Bear=Open>Close;
	If MarketPosition(0)=0 Then
		Begin
		If Bullish=1 And Bull
		Then
			Begin
			Buy Numb_Shares Shares Next Bar At High Stop;
			SetStopShare;
			BuyTarget=(Range*x);
			BuyStop=Range-(Range*x);
			SetProfitTarget(BuyTarget);
			SetStopLoss(BuyStop);
			Print(File("c:\testOrderExe.txt"),Date,Time,Close,"Bullish",High,BuyTarget,BuyStop);
			End
		Else
		If Bearish=1 And Bear
		Then
			Begin
			SellShort Numb_Shares Shares Next Bar At Low Stop;
			SetStopShare;
			SellTarget=(Range*x);
			SellStop=Range-(Range*x);
			SetProfitTarget(SellTarget);
			SetStopLoss(SellStop);
			Print(File("c:\testOrderExe.txt"),Date,Time,Close,"Bearish",Low,SellTarget,SellStop);
			End;
		End;
	End;
I want to be able to enter a trade when the conditions, noted above, are met and at the same time, my target and stop are set once and only once until the trade is complete. Ultimately, also, if my order is not filled, I also want to be able to cancel that order, if the price goes past the Stop first before coming back to fill me!

Right now, what happens is that only two trades are taken place a few bars apart. No further trades before or after these two trades take place, even though the conditions are appropriate for more order entries.

Reply With Quote

Reply



futures io > > > > > Order Entry, Target, Trailing Stop, and Exit

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
Ninja trailing stop based upon R/R to the target Cristian NinjaTrader Programming 1 October 30th, 2014 03:34 PM
Exit using Entry price plus/minus profit target Bodil Elite EasyLanguage Automated Trading 2 November 30th, 2013 07:21 PM
profit target turns into trailing stop loss peaceNlove NinjaTrader Programming 3 August 22nd, 2013 01:07 PM
Exit at close for trailing stop strategy skorpyo ThinkOrSwim Programming 0 July 27th, 2013 05:56 AM
Trailing stop and Target on Idicator Help bdd069 Elite Automated Trading 4 February 10th, 2013 08:38 PM


All times are GMT -4. The time now is 09:44 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-15 in 0.14 seconds with 19 queries on phoenix via your IP 54.91.171.137