NexusFi: Find Your Edge


Home Menu

 





Setting StopLosses and ProfitTargets without using actual dollar amounts


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Alex2013 with 2 posts (0 thanks)
    2. looks_two minntabo with 2 posts (0 thanks)
    3. looks_3 LogicalTrader with 1 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 5,952 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Setting StopLosses and ProfitTargets without using actual dollar amounts

(login for full post details)
  #1 (permalink)
minntabo
new york, ny
 
Posts: 5 since Sep 2013
Thanks Given: 1
Thanks Received: 0

Hi all,

I'm trying to write a strategy for trading the ES emini futures contract (e.g., ESZ3), but am having trouble setting Stop Losses and Profit Targets.

Many posts I've seen on the web focus on setting Stops and Profits based on actual dollar amounts. For example, Stopping out if the trade goes $200 against me, and Taking Profit if the trade goes $800 in my favor. The typical SetStopLoss (200) and SetProfitTarget (800) would be used.

However, what if I want to set my Stop and Profit based on values of previous bars?

1. For example, what if I want to set my Stop at High[1] (i.e., high of the previous bar)?

2. Also, what if I want to set my Target at Close[1] - 8 points of the contract? (That is, I want my Target to be hit after price goes 8 points (or $400) below the close of the previous bar?

I can't seem to figure out how to set this using the SetStopLoss and SetProfitTarget functions.

Any help is appreciated!
-K

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Looking for an MQL4 MetaTrader programmer/coder
The Elite Circle
Futures Close-Out Policy
Commodities
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Daytrading ES & NQ
32 thanks
Battlestations: Show us your trading desks!
30 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Retail Trading As An Industry
25 thanks

(login for full post details)
  #3 (permalink)
LogicalTrader
Houston, TX
 
Posts: 294 since Aug 2013
Thanks Given: 1,420
Thanks Received: 757


One way to do this would be to not use the setProfitTarget and setStopLoss methods. Instead just use sell next bar at n limit/stop etc. syntax.


Quoting 
1. For example, what if I want to set my Stop at High[1] (i.e., high of the previous bar)?

You could write:

 
Code
If (<your condition here, mostly the bar you entered at or whatever decides your stop>) then
Value1 = High[1];

Buy Cover next bar at Value1 stop;

Quoting 
2. Also, what if I want to set my Target at Close[1] - 8 points of the contract? (That is, I want my Target to be hit after price goes 8 points (or $400) below the close of the previous bar?

You could write:

 
Code
if (<my condition>) then
Value1 = Close[1] - 8;

Sell next bar at Value1 limit;


Of course, you would want additional checks like if you are in a position or not etc. before you direct your strategy to place an order. Hope this gives you some ideas.

There are some great free tutorials at Free Tutorials for [AUTOLINK]EasyLanguage[/AUTOLINK] Services for TradeStation if you want to take a look.

Hope this helps.

Reply With Quote
(login for full post details)
  #4 (permalink)
minntabo
new york, ny
 
Posts: 5 since Sep 2013
Thanks Given: 1
Thanks Received: 0

Thanks iNeo for the tips. Everything seems to be working. I'll keep posted on results.

Reply With Quote
(login for full post details)
  #5 (permalink)
Alex2013
London
 
Posts: 2 since Oct 2013
Thanks Given: 0
Thanks Received: 0

Hello,

I am completely new to EasyLanguage and programming in general. I am hoping someone could help me set a trailing stop loss which is not measured in $ but in %. In other words, I want to exit a long position if it falls by 1% from its highest point after entry, as opposed to it falling by 1$. Please note that it's different from 'SetPercentTrailing' as it allows you to specify a percentage stop loss only relative to a certain $ profit level. I have tried the following code to exit a long position but it doesn't work:

 
Code
[IntrabarOrderGeneration = False]
inputs: PositionBasis( false ), TrailStopPct ( 1 ) {enter in percentage points} ;

variables: StopCalc (0) ;

if PositionBasis then
    SetStopPosition
else
    SetStopShare ;

StopCalc = Close - Close * TrailStopPct * 0.01 ;

if Close < = StopCalc then
    Sell next bar at market ;
Also how would you do such a trailing stop loss to exit a short position?

Any help would be much appreciated!

Alex

Reply With Quote
(login for full post details)
  #6 (permalink)
Alex2013
London
 
Posts: 2 since Oct 2013
Thanks Given: 0
Thanks Received: 0

Hello again!

I have managed to find an extremely powerful stop loss strategy that does offer a % trailing stop loss, including many other sophisticated features. It looks quite exciting! However, as a user of MultiCharts, I can't use this code as it's written for TradeStation, which seems to be using a more up-to-date version of EasyLanguage than MultiCharts. For example, when I compile it in MultiCharts the editor doesn't understand "Method void", "#region", etc. I have already found on Big Mike forum how to deal with the 'method void' problem (bigmiketrading.com/easylanguage-programming/14181-tradestation-9-easylanguage-multi-charts-easy-language.html), but my programming skill is so poor that I don't really understand the suggested solution.

Would there be anyone kindhearted enough to help me out here please

The description and the code for the stop loss strategy I found is here: hightick.com/Tradestation/Strategy/StopsFlexible/index.html

Cheers!
Alex

Reply With Quote





Last Updated on October 3, 2013


© 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