NexusFi: Find Your Edge


Home Menu

 





Order Entry, Target, Trailing Stop, and Exit


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one DrRon with 9 posts (0 thanks)
    2. looks_two ABCTG with 8 posts (9 thanks)
    3. looks_3 Jura with 2 posts (3 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 7,334 views
    2. thumb_up 12 thanks given
    3. group 2 followers
    1. forum 18 posts
    2. attach_file 0 attachments




 
Search this Thread

Order Entry, Target, Trailing Stop, and Exit

  #11 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

DrRon,

you should study how the reserved words for SetProfitTarget and SetStopLoss work and should be used. Take a look at the build in Profit Target and Stop Loss signals.
They are still placed inside your conditions and this will most likely result in your entries being without stops and targets at some point.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
Increase in trading performance by 75%
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
GFIs1 1 DAX trade per day journal
11 thanks
HumbleTraders next chapter
11 thanks
  #12 (permalink)
 DrRon 
Irvine CA
 
Experience: Advanced
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Trading: CL
Posts: 9 since Aug 2015
Thanks Given: 11
Thanks Received: 1


ABCTG View Post
DrRon,

you should study how the reserved words for SetProfitTarget and SetStopLoss work and should be used. Take a look at the build in Profit Target and Stop Loss signals.
They are still placed inside your conditions and this will most likely result in your entries being without stops and targets at some point.

Regards,
ABCTG

Thank you ABCTG! I've made considerable progress in the coding of my order execution strategy. However, I've noticed that not every new bar is getting me in the trade. Also, it appears that every trade I'm getting in is getting me in at the opening of the new bar- NOT the high/low of the previous bar, as ordered. Any input would be greatly appreciated.

 
Code
[IntrabarOrderGeneration = True]

Inputs:
Numb_Shares(10), //[DisplayName="Number of Shares",ToolTip="Enter the number of shares per trade."],
Min_Range(.01), //[DisplayName="Minimum Range",ToolTip="Minimum range to trade."],
Max_Range(100), //[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)"],
BlTgt_Thres(.2), //[DisplayName="Bull Target Threshold",ToolTip="What target threshold do wish to trade with?"],
BlStp_Thres(.8), //[DisplayName="Bull Stop Threshold",ToolTip="What stop threshold do wish to trade with?"],
BrTgt_Thres(.4), //[DisplayName="Bear Target Threshold",ToolTip="What target threshold do wish to trade with?"],
BrStp_Thres(1); //[DisplayName="Bear Stop Threshold",ToolTip="What stop 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;
	Print(File("c:\testOrderExe.txt"),Date,Time,Close);
	If MarketPosition(0)=0 Then
	Begin
		If Bullish=1 And Bull
		Then
		Begin
			BuyTarget=Range*BlTgt_Thres;
			BuyStop=Range*BlStp_Thres;
			Print(File("c:\testOrderExe.txt"),Date,Time,Close," Bullish ",High,(High+BuyTarget),(High-BuyStop));
			Buy Numb_Shares Shares Next Bar At High Stop;
		End
		Else
		If Bearish=1 And Bear
		Then
		Begin
			SellTarget=Range*BrTgt_Thres;
			SellStop=Range*BrStp_Thres;
			Print(File("c:\testOrderExe.txt"),Date,Time,Close," Bearish ",Low,(Low-SellTarget),(Low+SellStop));
			SellShort Numb_Shares Shares Next Bar At Low Stop;
		End;
	End;	
End;
If MarketPosition(0)=1 Then
Begin
	Print(File("c:\testOrderExe.txt"),Date,Time,Close," Bullxxh ",High,(High+BuyTarget),(High-BuyStop));
	SetStopShare;
	SetProfitTarget(BuyTarget);
	SetStopLoss(BuyStop);
End;
If MarketPosition(0)=-1 Then
Begin
	Print(File("c:\testOrderExe.txt"),Date,Time,Close," Bearxxh ",Low,(Low-SellTarget),(Low+SellStop));
	SetStopShare;
	SetProfitTarget(SellTarget);
	SetStopLoss(SellStop);
End;

Started this thread Reply With Quote
  #13 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627


DrRon,

you might want to add print statements to check your conditions on the bars that don't get you in a trade. So you can check what happens there. If you are already inside a position, this might just be caused by your pyramiding settings that block new trades.
Using your code I don't see any situation on a chart where the trade entry is not at the high or low of the previous bar (or higher/lower due to the stop order). What chart symbol and time frame did you use. Can you post an example of a specific situation?

On a side note, with intrabar order generation you should use the look inside bar backtesting feature if you don't already.

Regards,

ABCTG


DrRon View Post
Thank you ABCTG! I've made considerable progress in the coding of my order execution strategy. However, I've noticed that not every new bar is getting me in the trade. Also, it appears that every trade I'm getting in is getting me in at the opening of the new bar- NOT the high/low of the previous bar, as ordered. Any input would be greatly appreciated.

 
Code
[IntrabarOrderGeneration = True]

Inputs:
Numb_Shares(10), //[DisplayName="Number of Shares",ToolTip="Enter the number of shares per trade."],
Min_Range(.01), //[DisplayName="Minimum Range",ToolTip="Minimum range to trade."],
Max_Range(100), //[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)"],
BlTgt_Thres(.2), //[DisplayName="Bull Target Threshold",ToolTip="What target threshold do wish to trade with?"],
BlStp_Thres(.8), //[DisplayName="Bull Stop Threshold",ToolTip="What stop threshold do wish to trade with?"],
BrTgt_Thres(.4), //[DisplayName="Bear Target Threshold",ToolTip="What target threshold do wish to trade with?"],
BrStp_Thres(1); //[DisplayName="Bear Stop Threshold",ToolTip="What stop 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;
	Print(File("c:\testOrderExe.txt"),Date,Time,Close);
	If MarketPosition(0)=0 Then
	Begin
		If Bullish=1 And Bull
		Then
		Begin
			BuyTarget=Range*BlTgt_Thres;
			BuyStop=Range*BlStp_Thres;
			Print(File("c:\testOrderExe.txt"),Date,Time,Close," Bullish ",High,(High+BuyTarget),(High-BuyStop));
			Buy Numb_Shares Shares Next Bar At High Stop;
		End
		Else
		If Bearish=1 And Bear
		Then
		Begin
			SellTarget=Range*BrTgt_Thres;
			SellStop=Range*BrStp_Thres;
			Print(File("c:\testOrderExe.txt"),Date,Time,Close," Bearish ",Low,(Low-SellTarget),(Low+SellStop));
			SellShort Numb_Shares Shares Next Bar At Low Stop;
		End;
	End;	
End;
If MarketPosition(0)=1 Then
Begin
	Print(File("c:\testOrderExe.txt"),Date,Time,Close," Bullxxh ",High,(High+BuyTarget),(High-BuyStop));
	SetStopShare;
	SetProfitTarget(BuyTarget);
	SetStopLoss(BuyStop);
End;
If MarketPosition(0)=-1 Then
Begin
	Print(File("c:\testOrderExe.txt"),Date,Time,Close," Bearxxh ",Low,(Low-SellTarget),(Low+SellStop));
	SetStopShare;
	SetProfitTarget(SellTarget);
	SetStopLoss(SellStop);
End;


Follow me on Twitter Reply With Quote
Thanked by:
  #14 (permalink)
 DrRon 
Irvine CA
 
Experience: Advanced
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Trading: CL
Posts: 9 since Aug 2015
Thanks Given: 11
Thanks Received: 1

Thank you ABCTG. I have placed plenty of print statements inside conditions on the bars and am getting a very deep understanding of how orders are executed with EasyLanguage. I'm using AMZN-15M chart as a sample.

A problem I'm in the middle of, at the moment, is when MarketPosition becomes a 1, I push SetprofitTarget and SetStopLoss orders. When it is filled one way or another, what do I look for in order to know it has been filled?

Also, would you kindly provide a link for me to read about Intrabar "look inside bar" backtesting feature please?

Started this thread Reply With Quote
  #15 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

DrRon,

I would have to look it up in the Tradestation wiki, forum or helpfile, too. You should be able to find it in all three.
You can also use Google to find something.

Regards,

ABCTG


DrRon View Post
Also, would you kindly provide a link for me to read about Intrabar "look inside bar" backtesting feature please?


Follow me on Twitter Reply With Quote
Thanked by:
  #16 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

DrRon,

when your MarketPosition changes from 1 to 0 an exit took place. You can then check if the trade exited with a profit or loss and thus know if your target or stop was hit.
If you need more information you can obtain order names etc. via Object Oriented Easylanguage, but I would advise to only start using that once you have a solid EasyLanguage foundation to build onto.

Regards,

ABCTG


DrRon View Post
A problem I'm in the middle of, at the moment, is when MarketPosition becomes a 1, I push SetprofitTarget and SetStopLoss orders. When it is filled one way or another, what do I look for in order to know it has been filled?


Follow me on Twitter Reply With Quote
Thanked by:
  #17 (permalink)
 DrRon 
Irvine CA
 
Experience: Advanced
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Trading: CL
Posts: 9 since Aug 2015
Thanks Given: 11
Thanks Received: 1

[UPDATE] I created a flag that would indicate where we are in the process and after exhaustive troubleshooting I discovered that when I'm declaring this flag under variables, I must declare it as IntraBarPersist when IOG is true!

Started this thread Reply With Quote
  #18 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

DrRon,

this goes for all your variables that you want to update intrabar, otherwise they might not hold the correct values.

Regards,

ABCTG


DrRon View Post
[UPDATE] I created a flag that would indicate where we are in the process and after exhaustive troubleshooting I discovered that when I'm declaring this flag under variables, I must declare it as IntraBarPersist when IOG is true!


Follow me on Twitter Reply With Quote
Thanked by:
  #19 (permalink)
 DrRon 
Irvine CA
 
Experience: Advanced
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Trading: CL
Posts: 9 since Aug 2015
Thanks Given: 11
Thanks Received: 1

Thanks ABCTG! I wish someone had told me about this. After putting Print at every turn, I noticed that my flag was changing values (like it had a mind of its own). I dug deeper into declaring variables and discovered IntraBarPersist!

Started this thread Reply With Quote




Last Updated on November 24, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts