Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

ksungela

EL Code for Trailing Stop

Recommended Posts

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?:crap:

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;

Share this post


Link to post
Share on other sites
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?:crap:

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.

 

324px-LampFlowchart.svg.png

Share this post


Link to post
Share on other sites
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?:crap:

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;

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.