Welcome to the Traders Laboratory Forums.
Coding Forum Collaborate, receive help, or discuss coding related issues.

Like Tree1Likes
  • 1 Post By Tams

Reply
Old 06-21-2011, 10:33 AM   #1

Join Date: Jul 2007
Location: Rivervale
Posts: 4
Ignore this user

Thanks: 0
Thanked 0 Times in 0 Posts

EL Code for Trailing Stop

I'm trying to create a simple strategy using EL using a trailing stop (actually reversal) based on the high(low) of the last bar. If I'm long, I want to exit and go short if price drops to 1 tick below the low of the last bar. If I'm short, I want to cover and go long if price rises to 1 tick above the high of the last bar. I'm applying this to futures and basically want to reverse position based on the break of the previous bar high or low. When applied to a chart, i get entries and exits, but not when they should be. The code skips many trades which should take place. Any ideas what I'm doing wrong?
Thanks in advance.


if Marketposition = 0 and date = 1110621 then begin
Buy ("long") 1 contract next bar at high[1] + 1 point stop;
Sell short ("short") 1 contract next bar at low[1] - 1 point stop;
end;

if Marketposition = -1 and last >= high[1] + 1 point then begin
Buy("Long") 1 contracts next bar at high[1] + 1 point stop;
end;

If marketposition = 1 and last <= low[1] -1 point then begin
Sell short("short") next bar at low[1] - 1 point stop;
end;
ksungela is offline  
Reply With Quote
Old 06-21-2011, 01:18 PM   #2

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: EL Code for Trailing Stop

Quote:
Originally Posted by ksungela »
I'm trying to create a simple strategy using EL using a trailing stop (actually reversal) based on the high(low) of the last bar. If I'm long, I want to exit and go short if price drops to 1 tick below the low of the last bar. If I'm short, I want to cover and go long if price rises to 1 tick above the high of the last bar. I'm applying this to futures and basically want to reverse position based on the break of the previous bar high or low. When applied to a chart, i get entries and exits, but not when they should be. The code skips many trades which should take place. Any ideas what I'm doing wrong?
Thanks in advance.


if Marketposition = 0 and date = 1110621 then begin
Buy ("long") 1 contract next bar at high[1] + 1 point stop;
Sell short ("short") 1 contract next bar at low[1] - 1 point stop;
end;

if Marketposition = -1 and last >= high[1] + 1 point then begin
Buy("Long") 1 contracts next bar at high[1] + 1 point stop;
end;

If marketposition = 1 and last <= low[1] -1 point then begin
Sell short("short") next bar at low[1] - 1 point stop;
end;

What you are describing is a very high level idea.
there are a lot of decisions and small operational steps in between the lines.
You should transfer your thoughts onto a flowchart first,
then fill in the blocks with detailed instructions.

BlueHorseshoe likes this.
__________________



Only an idiot would reply to a stupid post
Tams is offline  
Reply With Quote
Old 06-21-2011, 01:33 PM   #3

volumetrader's Avatar

Join Date: Apr 2011
Location: Melbourne
Posts: 1
Ignore this user

Thanks: 1
Thanked 0 Times in 0 Posts

Re: EL Code for Trailing Stop



sorry Ksungela, i shouldn't laugh, but Tams response is funny.

Hay Tam you really in Geelong? I'm in Geelong and I also use Multicharts.
volumetrader is offline  
Reply With Quote
Old 01-26-2012, 12:54 PM   #4

Join Date: Jan 2012
Posts: 365
Ignore this user

Thanks: 51
Thanked 72 Times in 56 Posts

Re: EL Code for Trailing Stop

Quote:
Originally Posted by ksungela »
I'm trying to create a simple strategy using EL using a trailing stop (actually reversal) based on the high(low) of the last bar. If I'm long, I want to exit and go short if price drops to 1 tick below the low of the last bar. If I'm short, I want to cover and go long if price rises to 1 tick above the high of the last bar. I'm applying this to futures and basically want to reverse position based on the break of the previous bar high or low. When applied to a chart, i get entries and exits, but not when they should be. The code skips many trades which should take place. Any ideas what I'm doing wrong?
Thanks in advance.
There are a few problems here:

One is that on the current bar[0] you are issuing an instruction to buy/sell on the next bar[-1] based on the previous bar[1]. What you should be doing is issuing an instruction to buy/sell on the next bar based on the high/low of the current one.

Another problem may be that you're not specifying the point size - for instance in the @ES you have a 'big point value' (a point), and a 'small point value' (a tick, or quarter point).

The 'begin . . . end' bracket seems redundant.

I am not sure why you are bothering to specify the number of contracts in the code if it remains fixed throughout your strategy - just issue a buy/sell order and use the default settings on the strategy's formatting to determine the fixed number of contracts to trade.

I am guessing that something like the following would produce the result you want:

If Marketposition = 0 and date = 1110621 then
Buy next bar at high+1 stop;

If Marketposition = 0 and date = 1110621 then
Sellshort next bar at low-1 stop;

if Marketposition = -1 then
Buy next bar at high+1 point stop;

If marketposition = 1 then
Sellshort next bar at low-1 stop;
BlueHorseshoe is offline  
Reply With Quote
Old 01-26-2012, 03:03 PM   #5

UrmaBlume's Avatar

Join Date: Apr 2008
Location: Las Vegas
Posts: 670
Ignore this user

Thanks: 87
Thanked 618 Times in 251 Posts

Re: EL Code for Trailing Stop

As you relate your stop to previous bars' extremes here is some simple code that will establish and move your stop:

If MasterBuyCondition1 = True and TimeCondition = True Then Begin
Buy TradeSize Contracts next bar at market;
SStop = Low[1] - StopF;
LongExitCondition = 0;
end;


If MarketPosition > 0 Then Begin
If Low[1] - StopF > SStop then SStop = Low[1] - StopF;
Sell CurrentShares Contracts Next Bar at SStop Stop;
end;

Cheers

UrmaBlume
__________________
Information = Equity
UrmaBlume is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
% Trailing Stop in Tradestation pimind Futures Trading Laboratory 0 04-26-2009 05:46 PM
Intraday Trading Trailing Stop for Emini S&P cowcool E-mini Futures Trading Laboratory 10 04-17-2009 10:09 AM
Looking for an ATR Trailing Stop Indicator Fredd Coding Forum 3 03-02-2009 02:03 AM
Stop Loss Stop Loss Trailing rod30 Beginners Forum 8 02-23-2008 10:49 AM
Optimal trailing stop percentage al_sellatmarket Beginners Forum 16 03-28-2007 08:04 PM

All times are GMT -4. The time now is 10:50 AM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.