NexusFi: Find Your Edge


Home Menu

 





Easylanguge Multicharts Help


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one guppy with 4 posts (2 thanks)
    2. looks_two Jura with 3 posts (8 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 MadTr8r with 1 posts (1 thanks)
    1. trending_up 4,099 views
    2. thumb_up 11 thanks given
    3. group 2 followers
    1. forum 8 posts
    2. attach_file 3 attachments




 
Search this Thread

Easylanguge Multicharts Help

  #1 (permalink)
 guppy 
Los Angeles, CA
 
Experience: Advanced
Platform: Tradestation
Broker: Tradestation
Trading: ES,HG,GC,YM,Nq,RB,NG
Posts: 52 since Aug 2011
Thanks Given: 11
Thanks Received: 8

I am having trouble implementing a stop loss in easy language. If someone can help that would be greatly appreciated. Below is the simple code. If i am short a position then i want my stop loss order to be the value of the highest high of the last 4 bars. Thats it! When i look at the results the stop order is not placed at the highest high of the last 4 bars. I also tried using 'stoplossposition' and i get an error.



vars:mystoploss(0);

mystoploss=highest(high,4)[1];


ifclose>close[1]then
begin
sellshort("SSS")1contractsnextbaratmarket;
setstoploss(mystoploss);

end;



Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #3 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


Try removing the SetStopLoss from the begin...end code block, something like this:
 
Code
vars: mystoploss(0);

mystoploss = Highest(high, 4)[1];

if close > close[1] then begin
    sellshort ("SSS") 1 contracts next bar at market;
end;

setstoploss(mystoploss);
Also see this post on the MC forum, and page 90 from the EasyLanguage Essentials manual.

Reply With Quote
Thanked by:
  #4 (permalink)
 guppy 
Los Angeles, CA
 
Experience: Advanced
Platform: Tradestation
Broker: Tradestation
Trading: ES,HG,GC,YM,Nq,RB,NG
Posts: 52 since Aug 2011
Thanks Given: 11
Thanks Received: 8

Hi Jura,

I tired this and it still does not work. It basically just makes my stoploss the same as my entry. Please see attached picture.







Jura View Post
Try removing the SetStopLoss from the begin...end code block, something like this:
 
Code
vars: mystoploss(0);
 
mystoploss = Highest(high, 4)[1];
 
if close > close[1] then begin
    sellshort ("SSS") 1 contracts next bar at market;
end;
 
setstoploss(mystoploss);
Also see this post on the MC forum, and page 90 from the EasyLanguage Essentials manual.


Attached Thumbnails
Click image for larger version

Name:	StopLossNotWorking.JPG
Views:	218
Size:	72.0 KB
ID:	50531  
Started this thread Reply With Quote
  #5 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


guppy View Post
I tired this and it still does not work. It basically just makes my stoploss the same as my entry. Please see attached picture.

What have you tried, copy-pasting the example code? Then it would indeed not work. That's why I said:


Jura View Post
Also see this post on the MC forum, and page 90 from the EasyLanguage Essentials manual.

If you look on the page of that manual, you'll see..

Quoting 
SetStopLoss - sets a stop loss order at a fixed dollar risk from entry.
(..)
By default these exits operate on a position basis and stop amounts are set in dollars.

Now, look at the example code:
 
Code
vars: mystoploss(0);

mystoploss = Highest(high, 4)[1];

if close > close[1] then begin
    sellshort ("SSS") 1 contracts next bar at market;
end;

setstoploss(mystoploss);
The SetStopLoss is here set to the value of 'mystoploss', a variable which contains the HIGH of the instrument that you trade. Since that high will be around 1.37, judging from your screenshot, with the example code above, you will exit the position if the unrealized loss is 1.37 dollar for the whole position. Which in practice would be indeed an instantaneous exit after entry, especially if commissions are considered.

Solution: calculate the loss, in dollars for the whole position, that would happen if the position reaches the Highest(high, 4)[1]. Or alternatively, manually set the stop loss at the price of the Highest(high, 4)[1].

Reply With Quote
Thanked by:
  #6 (permalink)
 guppy 
Los Angeles, CA
 
Experience: Advanced
Platform: Tradestation
Broker: Tradestation
Trading: ES,HG,GC,YM,Nq,RB,NG
Posts: 52 since Aug 2011
Thanks Given: 11
Thanks Received: 8

Thanks for sharing your knowledge Jura,

I now understand that its calculated in dollar 'amount' after reading your post and links. Im surprised there isnt a simple way to setstoploss by 'price'.

Do you have any suggestions how i can do it by 'price' without having to set it manuely.




Jura View Post
What have you tried, copy-pasting the example code? Then it would indeed not work. That's why I said:



If you look on the page of that manual, you'll see..
Now, look at the example code:
 
Code
vars: mystoploss(0);
 
mystoploss = Highest(high, 4)[1];
 
if close > close[1] then begin
    sellshort ("SSS") 1 contracts next bar at market;
end;
 
setstoploss(mystoploss);
The SetStopLoss is here set to the value of 'mystoploss', a variable which contains the HIGH of the instrument that you trade. Since that high will be around 1.37, judging from your screenshot, with the example code above, you will exit the position if the unrealized loss is 1.37 dollar for the whole position. Which in practice would be indeed an instantaneous exit after entry, especially if commissions are considered.

Solution: calculate the loss, in dollars for the whole position, that would happen if the position reaches the Highest(high, 4)[1]. Or alternatively, manually set the stop loss at the price of the Highest(high, 4)[1].


Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


guppy View Post
Thanks for sharing your knowledge Jura,

I now understand that its calculated in dollar 'amount' after reading your post and links. Im surprised there isnt a simple way to setstoploss by 'price'.

Do you have any suggestions how i can do it by 'price' without having to set it manuely.


You could use something like..

 
Code
vars: mystoploss(0);

mystoploss = Highest(high, 4)[1];

if close > close[1] then begin
    sellshort ("SSS") 1 contracts next bar at market;
end;

if MarketPosition = -1 then
    buytocover ("XS2") next bar at mystoploss stop;
..which submits a stoploss order at the 'mystoploss' level on every bar, as long there is a Short position (see also the first screenshot). That way you can use the price level instead of the dollar amount level.

Btw, if you look closely at the code example above, the 'mystoploss' variable is set with a new value on every bar. So, in a falling market, the value of 'mystoploss' will be lower on each update, since the Highest(high, 4) in a falling market is lower on each new bar. So, the code example above uses a trailing stop.

Good of course is that is what you intend it to do, but if you want a fixed stop-loss (that won't get updated with higher or lower Highest(High, 4)[1] values), you could use something like the following code:
 
Code
vars: mystoploss(0);

if MarketPosition = 0 and close > close[1] then begin
    mystoploss = Highest(high, 4)[1];
   sellshort ("SSS") 1 contracts next bar at market;
end;

if MarketPosition = -1 then
    buytocover ("XS2") next bar at mystoploss stop;
(See also the second attached image)

Good luck!

Attached Thumbnails
Click image for larger version

Name:	stopLoss.png
Views:	202
Size:	66.3 KB
ID:	50537   Click image for larger version

Name:	fixedStopLoss.png
Views:	198
Size:	76.3 KB
ID:	50542  
Reply With Quote
  #8 (permalink)
 guppy 
Los Angeles, CA
 
Experience: Advanced
Platform: Tradestation
Broker: Tradestation
Trading: ES,HG,GC,YM,Nq,RB,NG
Posts: 52 since Aug 2011
Thanks Given: 11
Thanks Received: 8

Jura,

Your a genius! and thanks for solving the issue along with postiing images which totally helped see the problem. I originally did what your first coding showed below, but i was stumped as to why multicharts kept showing the buytocovers and all different levels. Now i realize that it was calculating and changing every bar as you clearly specified, acting more like a trailing.

The second part of the code is exacly what i was in search for. Basically a proper way of a stoploss at a fixed price! I wish the easylanguage getting started maneul and EL essentianls had these complete examples in it. Im sure it would help many people out with the basics on

1.how to implement a fixed stop loss based on price
2.how to implement a trailing stop loss based on price
3.how to implement a fixed stop loss based on dollar
4.how to implement a trailing stop loss based on dollar






Jura View Post
You could use something like..

 
Code
vars: mystoploss(0);
 
mystoploss = Highest(high, 4)[1];
 
if close > close[1] then begin
    sellshort ("SSS") 1 contracts next bar at market;
end;
 
if MarketPosition = -1 then
    buytocover ("XS2") next bar at mystoploss stop;
..which submits a stoploss order at the 'mystoploss' level on every bar, as long there is a Short position (see also the first screenshot). That way you can use the price level instead of the dollar amount level.

Btw, if you look closely at the code example above, the 'mystoploss' variable is set with a new value on every bar. So, in a falling market, the value of 'mystoploss' will be lower on each update, since the Highest(high, 4) in a falling market is lower on each new bar. So, the code example above uses a trailing stop.

Good of course is that is what you intend it to do, but if you want a fixed stop-loss (that won't get updated with higher or lower Highest(High, 4)[1] values), you could use something like the following code:
 
Code
vars: mystoploss(0);
 
if MarketPosition = 0 and close > close[1] then begin
    mystoploss = Highest(high, 4)[1];
   sellshort ("SSS") 1 contracts next bar at market;
end;
 
if MarketPosition = -1 then
    buytocover ("XS2") next bar at mystoploss stop;
(See also the second attached image)

Good luck!


Started this thread Reply With Quote
Thanked by:
  #9 (permalink)
MadTr8r
Chicago
 
Posts: 12 since Dec 2010
Thanks Given: 6
Thanks Received: 3

Thanks for posting that very helpful as someone who has their own strategies with trail stops :-)

Reply With Quote
Thanked by:




Last Updated on October 11, 2011


© 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