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.


  • Topics

  • Posts

    • I'm still a dove regarding crypto trading. Not because of the instruments traded, but because of the lack of market centralization. It reminds me of the early days of forex trading where no broker-dealers offered trade clearing via the interbank market. This is basically betting against "the house" which is its own captive market-maker, has its own one-off price feed, and has its own one-off trade execution policies. As a side note, I always opt out of broker-dealers' arbitration clauses within 30 days of account opening pursuant to the U.S. Federal Arbitration Act. Unscrupulous broker-dealers and platform sellers don't even provide opt-out terms in their trading/subscription agreements, but it still exists pursuant to federal statutes and federal court precedent. Sierra Chart also collects unspent platform subscription deposits from traders in their website's online "wallet." This subjects them not only to FINRA liability but CFPB liability as well. I figuratively atom bombed Sierra Chart with this info and they refunded all platform fees and data fees that I ever paid to them before I closed my Sierra Chart account. On a more general note, virtually all broker-dealers are either partnered with, or straight up are, Wall Street investment banks and hedge funds. These are the folks that refer to retail traders as "cannon fodder" and "fish food." To me, any broker-dealer is nothing more than a counterparty to a series of my transactions. If I find any reason not to trust a broker-dealer, I'm out. Crypto trading, as it presently exists, fits the bill. Crypto owning/investment might be a different story, but I'm strictly a trader.
    • Consider this... While a human trader has emotions, a bot does not. All a human trader needs to do to code a statistically profitable strategy on a good emotional day. And it can be coded for any timeframe, intraday or overnights.
    • Well said. Broker-dealers that aren't connected to centralized exchanges or the prime interbank exchanges are, in fact, casinos--where nothing extends beyond "the house."
    • My latest trick... After successfully live trading forex for years, switch to trading futures in the U.S. Chicago Mercantile Exchanges. Futures spreads are generally 1 or 2 ticks with no swaps, and data fees and commission fees are fixed. As a caveat, leverage changes throughout every day based on international sessions, so this is not for small accounts. 
    • @analyst75, I am just dying for you to write a sequel... Why Some Young People Prefer to Live Alone.😂
×
×
  • Create New...

Important Information

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