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.

mctaff

Easy Language Stop Loss Problem

Recommended Posts

Hi,

 

I'm just starting to learn Easy Language, yet am having problems with stop loss setting when testing strategies.

 

Although the stop loss is set in the code, it seems it isn't always acted upon.

 

Not sure what I'm doing wrong... any ideas most appreciated!

 

Code sample:

 

if Condition11 and Condition12 then

begin

Buy 1 contracts next bar at market ;

SetProfitTarget(3000) ;

SetStopLoss( 100);

end;

 

 

In the most recent test, the first trade closed $100.78 down, the second is $16,091 down and still open!

 

Ideally I'd like to set a pip based stop loss (that works!), but it doesn't seem clear how to do this looking at the docs...

 

 

Thanks!

Share this post


Link to post
Share on other sites
What happens if you pull

SetProfitTarget(3000) ;

SetStopLoss( 100);

outside the block?

 

Yes spot on zdo !

 

the code should read like this:

 

if Condition11 and Condition12 then Buy 1 contracts next bar at market ;

 

SetProfitTarget(3000) ;

SetStopLoss( 100);

 

 

Cheers

 

Blu-Ray

Share this post


Link to post
Share on other sites

Thanks for the advice guys, I'll try that this evening.

 

However, I'd sincerely hope that doesn't work, otherwise I'm questioning the language designers competancy! Surely the idea of a code block is that the entire contents of it get executed when the conditions are met?! I don't want to be setting stop losses etc unless the order has been executed, although I suppose it makes little difference...

 

Enough ranting, I'll try it out, cheers!

Share this post


Link to post
Share on other sites
Thanks for the advice guys, I'll try that this evening.

 

However, I'd sincerely hope that doesn't work, otherwise I'm questioning the language designers competancy! Surely the idea of a code block is that the entire contents of it get executed when the conditions are met?! I don't want to be setting stop losses etc unless the order has been executed, although I suppose it makes little difference...

 

Enough ranting, I'll try it out, cheers!

 

 

It will work, the fault in the code is that Easy Language will only read that block of code if Condition11 and Condition12 are true. So it will read it at the time of execution.. but in a couple of bars time, for example, Condition11 and Condition12 are false it will therefore not read that block of code.

 

Also "SetStopLoss" will only come into force if a Position is filled.

 

Hope this helps

 

Blu-Ray

Share this post


Link to post
Share on other sites

It worked - thanks again!

 

I think I must be misunderstanding how the stop loss code works then - I assumed at the time of the order being placed, the stop would be associated with the order. Looking at the code, that clearly can't be the case, as the stop loss command doesn't reference the order.

 

I'm now slightly confused how to open multiple orders, and have different profit and stop values for different orders!

 

Is this possible? Is it possible to link the profit / stop commands to the order?

Share this post


Link to post
Share on other sites
...I think I must be misunderstanding how the stop loss code works then - I assumed at the time of the order being placed, the stop would be associated with the order. Looking at the code, that clearly can't be the case, as the stop loss command doesn't reference the order.

 

I'm now slightly confused how to open multiple orders, and have different profit and stop values for different orders!

 

Is this possible? Is it possible to link the profit / stop commands to the order?

 

First, 'get it' that (exit) orders are continously 'cancelled' and re-entered in TS. :doh:

 

Then re multiple orders and linking exits to that position

you can name posititions and use the names in the exits

and / or

you can use reserve words like SetStopContract

and / or

run separate / stand alone exit strategies

and / or ...

 

hth... this post only cost me $3000 so far...:cool:

Share this post


Link to post
Share on other sites
First, 'get it' that (exit) orders are continously 'cancelled' and re-entered in TS.

 

Yeah I figured that from the solution. I was under the impression that if you ticked the "send stop to server" checkbox (or whatever it's called) on the strategies automation tab, that you only needed to send it once and it would be held on TS servers - so if I lose my connection I don't lose 10k as well!

 

Is that not the case? Or does that not work with back testing?

 

Cheers,

 

David.

Share this post


Link to post
Share on other sites

i have a current issue atm and i was wondering if anyone could help me.

 

scaling in:

 

If condition3 and Condition4 and MarketPosition = 0 then begin;

Sell ("sell") Cts contracts at Market;

End;

 

If (Condition3 and Condition4) AND MarketPosition = -1 AND C < EntryPrice-0.0010 then Begin

sell ("Sell2") Cts contracts Market;

End;

 

If (Condition3 and Condition4) AND MarketPosition = -2 AND C < EntryPrice-0.0010 then Begin

sell ("Sell3") Cts contracts Market;

End;

 

but id also like to beable to scale out. if for instance the price went above the third order by X amount id like to close it but still keep the remaining 2 open.

 

someone above mentioned NAMING your orders. how exactly would i go about doing this.

 

thanks again for your help

Share this post


Link to post
Share on other sites
i have a current issue atm and i was wondering if anyone could help me.

 

scaling in:

 

If condition3 and Condition4 and MarketPosition = 0 then begin;

Sell ("sell") Cts contracts at Market;

End;

 

If (Condition3 and Condition4) AND MarketPosition = -1 AND C < EntryPrice-0.0010 then Begin

sell ("Sell2") Cts contracts Market;

End;

 

If (Condition3 and Condition4) AND MarketPosition = -2 AND C < EntryPrice-0.0010 then Begin

sell ("Sell3") Cts contracts Market;

End;

 

but id also like to beable to scale out. if for instance the price went above the third order by X amount id like to close it but still keep the remaining 2 open.

 

someone above mentioned NAMING your orders. how exactly would i go about doing this.

 

thanks again for your help

 

You have named them.

 

You've called them: "Sell" "Sell2" and "Sell3"

 

I you want to scale out you need to set a target price and Buy to Cover (for a Short) or Sell (for a Long) at a LIMIT price:

 

Example:

Inputs: EXITatTarget (TRUE),

Target1Qty(1);

 

vars: EXITPrice(0);

 

// Calc ExitPrice

add some logic to calc your exit based on a target or whatever...

 

if Marketposition=-1 and EXITatTarget =TRUE then Begin

Sell ("Target1") Target1Qty Contracts total next bar at ExitPrice Limit;

end;

Share this post


Link to post
Share on other sites

Hi, thanks for replying to my post. unfortunately i still cant get it to work. when i input "EXITPrice(0) in the variables it doesnt like it.

 

i was trying to get the following:

 

if marketposition = -2 AND the price of"sell2" < CURRENTPRICE+0.0005 then begin:

 

obviously easy language doesnt like that though + i had a look at EXITprice and it says the following:

 

If last trade exited at 455.75 then ExitPrice(1) = $455.75

 

im not sure thats what im looking for

Share this post


Link to post
Share on other sites

thanks for your reply but i cant get it to work. im looking to compare the price of "sell2" to the current price + or - a certain amount. if this is then true id like to close one of my positions.

 

the definition of exit price i got said it returned the value of the last exit.... if u placed[1] at the end and that it could be used to compute the last 10 prices. im not sure thats what i was looking for.

 

any other ideas??

Share this post


Link to post
Share on other sites

Whenever I am debugging a strategy I use the EasyLanguage Output Bar and a Print line to help understand what is going on.

 

Example:

 

PRINT Barnumber," Date ",Date," Time ",Time," MarketPosition ",MarketPosition," EntryPrice ", EntryPrice," ExitPrice ",ExitPrice);

 

Then I would consider how to best retain or refer to the value you are looking for.

Share this post


Link to post
Share on other sites

If I wanted to use the Hull Moving Average (jtHMA) for a crossover strategy instead of a simple or exponential moving average crossover strategy, how would it be coded in Easy Language for a fast length jtHMA(10) and a slow length jtHMA (20) with parameters that if fast avg jtHMA crosses above slow avg jtHMA then BuyLong 100 shares next bar at market, and SellShort if reverse, and would like to be able to displace the jtHMAs + or -1, 2, or 3, and will be using this on a 30 or 60 min. timeframe?

 

Also, is it possible, or even necessary, to put within the strategy a buy/sellshort order with a pre-set stoploss? Possibly something like:

 

If conditions are met for fast jtHMAavg crosses slow jtHMAavg, then begin;

buy/sellshort 100 shares next bar at market;

SetProfitTarget(1000);

SetStopLoss( 100);

end;

 

This is going to be my first time using a strategy for Tradestation, and want to backtest it, haven't tried that and not sure how to figure it in for possible flaws and slippage for backtesting. I'm going to use it on a 2x or 3x Proshares or Direxion index fund, and the position will reverse immediately when the jtHMAs cross on the next bar after the cross, from long to sellshort, or vice-versa. Not sure if that brings more problems, the instant reversal.

 

 

Thanks for any help.

 

Curtis

Share this post


Link to post
Share on other sites

dont know anything about this moving average thing ur talking about so cant help there... sorry

 

 

Inputs: inputa,

inputb,

inputc;

 

Variables: vara,

varb,

varc;

 

Condition1: jtHMAavg1[1] > jtHMAavg2[1]

 

Condition2: jtHMAavg1[1] < jtHMAavg2[1]

 

If condition1 then begin;

Buy ("buy long") 100 Cts contracts next bar at market;

End;

 

If condition2 then begin;

sell ("sell short") 100 Cts contracts next bar at market;

End;

 

SetProfitTarget(1000);

SetStopLoss( 100);

 

that SHOULD be right but i havent checked it in easy language as im just going out but it should give u an idea of how it possibly should look.

 

hope that helps

Share this post


Link to post
Share on other sites

First post! :cool:

 

Did you ever get this to work ?

You're forgetting one important statement. I believe the order system is configured for equities by default. you have to specify that you're trading contracts...

 

From the EasyLanguage manual:

SetStopShare or SetStopContract - exits are calculated per share or contract.

 

So your could would need to be something like:

 

Inputs: StopAmt(1), ProfitAmt(1);

SetStopContract;

SetStopLoss(StopAmt);

SetProfitTarget(ProfitAmt);

Share this post


Link to post
Share on other sites

Can you use a

 

SetProfitTarget(33%);

SetStopLoss(8%);

 

using a % instead of a number, and is that how you code it, and how do you code an ATR trailing stop I've seen several authors refer to using to implement a stop loss?

 

Thanks for any help.

Share this post


Link to post
Share on other sites

So why wouldn't this work?

 

If MarketPosition = 1 then

Begin

SetStopShare ;

SetStopLoss ( LongEntryPrice - (0.002 * LongEntryPrice) ) ;

End ;

 

If MarketPosition = -1 then

Begin

SetStopShare ;

SetStopLoss ( ShortEntryPrice + (0.002 * ShortEntryPrice) ) ;

End ;

Share this post


Link to post
Share on other sites
So why wouldn't this work?

 

If MarketPosition = 1 then

Begin

SetStopShare ;

SetStopLoss ( LongEntryPrice - (0.002 * LongEntryPrice) ) ;

End ;

 

If MarketPosition = -1 then

Begin

SetStopShare ;

SetStopLoss ( ShortEntryPrice + (0.002 * ShortEntryPrice) ) ;

End ;

 

 

 

SetProfitTarget and SetStopLoss orders

are posted to broker when there is an open position.

 

The target and stop will be automatically* withdrawn

if the position is closed.

 

* automatic means you do not need to code a logic to withdraw the orders,

they are done automatically as soon as the position is closed.

Edited by Tams

Share this post


Link to post
Share on other sites

A few weeks ago I had occasion to chat with the leadership of the TS development team and they acknoledged certain issues with the TS Trade Manager.

 

They say that TS v 9.0 will be out this summer and among the changes will be a millisecond time stamp and EL orders will become "smart objects."

 

As their oldest customer I was about to bail on them which would have meant a major migration effort as over the years we have written over 2k EL code modules.

Share this post


Link to post
Share on other sites
Hi, thanks for replying to my post. unfortunately i still cant get it to work. when i input "EXITPrice(0) in the variables it doesnt like it.i was trying to get the following:

 

if marketposition = -2 AND the price of"sell2" < CURRENTPRICE+0.0005 then begin:

 

obviously easy language doesnt like that though + i had a look at EXITprice and it says the following:If last trade exited at 455.75 then ExitPrice(1) = $455.75im not sure thats what im looking for

 

MarketPosition will never be -2. MarketPosition can only be 1 or 0 or -1, however MarketPosition * CurrentShares could be -2.

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

    • Forex trading is the best way to make some good money online, but you need to have proper skills to achieve success and for that you should practice trading with small capitals.
    • Forex Trading is the best way to make some good money online, but it could only work if you have the proper experience and skills, and knowledge which requires to achieve success in their trades.
    • MASTER TRADER JOE ROSS PASSES ON Dear Traders, We are sad to inform you of the passing of Master Trader Joe Ross on the morning of Tuesday, September 7, 2021 at the age of 87. He went peacefully doing what he loved, by taking care of Loretta, his wife of 62 years of marriage and teaching his students from every continent how to trade. Joe has always been a free spirit and loved the trading world being his own boss. He quickly learned that teaching others was his true passion. The joy of educating those about a system in which he had true confidence and to see others come into their own. That was his greatest pleasure. He was proud to be a devoted Christian and combined spirituality with trading. Our condolences to our traders and students for the loss of a mentor and close friend, some would even go as far as saying a “father-figure” and he wore that title proudly. Master Trader Joe Ross’ passing came upon us unexpectedly and suddenly. Again, we would like to send our condolences to those who lost a mentor and a friend. Joe, you will forever be in our hearts. Who is Joe Ross? Joe Ross is the creator of the Ross hook™, and has set new standards for low-risk trading with his concepts of “The Law of Charts™” and the “Traders Trick Entry™.” Joe was a private trader and investor for much of his life, but a serious health situation in the late 80’s caused him to shift his focus, and that is when he decided to share his knowledge. After his recovery, he founded Trading Educators in 1988, to teach aspiring traders how to make profits using his trading approach. Joe Ross has written twelve major books and countless articles and essays about trading. All his books have become classics, and have been translated into many different languages. His students from around the world number in the thousands. His file of letters containing thanks and appreciation from students on every continent is huge: As one student, a successful trader, wrote: “Your mastery of teaching is even greater than my mastery of trading.” Joe Ross holds a Bachelor of Science degree in Business Administration from the University of California at Los Angeles. He did his Masters work in Computer Sciences at the George Washington University extension in Norfolk, Virginia. He is listed in “Who’s Who in America.” After 5 decades of trading and investing, Joe Ross still tutors, teaches, writes, and trades regularly. Joe is an active and integral part of Trading Educators. He is the founder and contributor of the company’s newsletter Chart Scan™. “Master Traders Joe Ross was one of the most eclectic traders in the world. And he remains one of the few best mentors I have, alongside, Dr. Van. K. Tharp (may he live long), and one or two others. His teachings and insights into the markets have contributed to making me who I am today. He also talks about the spiritual side of trading, concluding that trading is no sin.” – Azeez M. “The trading world has lost a unique and passionate trader. He explained to me that his material will never go out of date, only the technology. Recently, we updated several of his hardback books into eBooks and he was right. From making trades over the phone to the “pit” then to opening an online account, my how things have changed. But he is correct about his methods, they will continue to apply to the markets regardless of how technolgy advances.” – Martha Ross-Edmunds (Joe’s daughter) Joe Ross’ Trading Philosophy: “Teach our students the truth in trading — teach them how to trade,” and “Give them a way to earn while they learn — realizing that it takes time to develop a successful trader.”   IN MEMORIAM: Joe Ross (RIP)   Source: https://learn2.trade   
    • BITCOIN PRICE ANALYSIS: LONG-TERM HOLDERS REMAIN UNSHAKEN BY PRICE ACTIONBITCOIN PRICE ANALYSIS: LONG-TERM HOLDERS REMAIN UNSHAKEN BY PRICE ACTION Azeez Mustapha 14 October 2021 | Updated: 14 October 2021 New reports from Glassnode show that despite the recent price surge in Bitcoin (BTC), long-term holders have shown no intention to liquidate and realize profits yet. The blockchain analytics provider also revealed that the percentage of BTC supply held for at least three months reached 85%, a new all-time high. Citing data from Glassnode, famous Chinese crypto analyst Colin Wu illustrated the recent behavior of Bitcoin holders and their attitude towards the benchmark cryptocurrency. The analyst detailed that the percentage of long-term holders that have not moved their coins in over ten years stands at 12.3%. These tokens are deemed dormant for this reason. The analyst further noted that the percentage of long-term holders that have not transferred their coins between two to three years and three to five years stands at 10% and 12.26%, respectively. Finally, the highest percentage of long-term holders were those who have refused to move their coins between the last six months to twelve months, standing at 19.5%. That said, 85.14% of BTCs have not exchanged hands for at least three months, a new record high. In July, Bitcoin struggled to keep its head above the $30,000 mark. Today, it has almost doubled this number, but investors remain steadfast in holding their coins. Key Bitcoin Levels to Watch — October 14 As predicted in our previous analysis, BTC witnessed a sharp correction to the $55,000 – $54,000 pivot axis from the $57,500 level over the last 48 hours. This correction found immediate support from the $54,000 level, which triggered a rebound to a new five-month high at $58,500 earlier today. BTCUSD – 4-Hour Chart While the price currently rests around $57,500, we expect a bull run to the $59,000 resistance over the coming hours and days. Meanwhile, our resistance levels are at $58,000, $59,000, and $60,000, and our key support levels are at $56,700, $56,000, and $55,000. Total Market Capitalization: $2.40 trillion Bitcoin Market Capitalization: $1.07 trillion Bitcoin Dominance: 44.9% Market Rank: #1 Source: https://learn2.trade 
    • Date : 15th October 2021. Market Update – October 15 – Stronger equities dampened the safe-havens! Q3 earnings season has gotten off to a strong start, with big banks largely shooting the lights out on revenues and earnings. Incoming data was constructive as well, with jobless claims coming in at pandemic lows, while the rate of PPI growth slowed. All 11 S&P sectors are higher. Bulls are in control, both in the bond market and on Wall Street. – Overlooked the hawkish Fed implications from the record strength in PPI and the lowest claims readings since before the pandemic. Yields declined and Treasuries are in the green on short covering and dip buying, recovering from the recent aggressive selloff. US Treasury yield has lifted 1.8 bp to 1.53%. China: will loosen restrictions on home loans and boost lending & bank added enough medium term funds to keep liquidity in the system steady. Equities up. JPN225 managed a 1.6% gain and US futures are also higher, led by a 0.4% rise in the USA100. Oil lifted above $81.99. – Prices quickly backed up after a larger than expected stock build in the US. Improved market sentiment, which has lifted global stocks, commodity prices and bond yields, is also weighing on the safe-haven Dollar. FX markets – USD dropped, Yen declined. EURUSD retests 1.1600 mark, Cable at 1.3689, USDJPY touched 114.16. European Open – The December 10-year Bund future is slightly higher, US Treasury futures slightly in the red, as stock futures move higher in both Europe and North America after a good session for equities across Asia overnight. Market sentiment improved and GER30 and UK100 futures are currently up 0.4% and 0.3% respectively, while a 0.4% rise in the USA100 is leading US futures. EGB yields had dropped back markedly yesterday, but in the UK money markets are still bracing for an earlier than expected lift off on rates, which ironically is actually helping long rates to come down. Today – Today’s data calendar is unlikely to change the overall picture, with only eurozone trade data for August and some final HICP readings on the agenda. Biggest FX Mover @ (06:30 GMT) NZDJPY (+0.60%) Breached 80.55. Up for 7 days in a row. Currently faster MAs keep pointing up, MACD signal line is at 0 & histogram trending higher. RSI at 82 & Stochastic at 94 but both sloping down, all indicating further upwards move in the medium term but possible pullback in the short term. H1 ATR 0.123, Daily ATR 0.810. Always trade with strict risk management. Your capital is the single most important aspect of your trading business. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HotForex Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Andria Pichidi Market Analyst HotForex Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
×
×
  • Create New...

Important Information

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