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.

GRANDEUR

Eliminating Repeated Trades

Recommended Posts

Recently, I tried to figure out how one can backtest day-strategy on smaller timeframes in order to eveluate an optimal stoploss. I was given a piece of advice to use a function 'entriestoday(date)<1'. It works fine to me.

Then I tried to implement something similar to an Hour-strategy. I tried to backtest it on 5-min timeframe. But, unfortunately, 'entriestoday(date)<1' doesn't work properly in that case.

Taking into account all written above, please help me to recode the following simple strategy so that I can backtest a stoploss amount:

 

inputs: x(100);

 

buy next bar at h stop;

setstopposition;

setstoploss(x);

 

sell short next bar at l stop;

setstopposition;

setstoploss(x);

 

Thank you in advance!

Share this post


Link to post
Share on other sites
...

Taking into account all written above, please help me to recode the following simple strategy so that I can backtest a stoploss amount:

...

Thank you in advance!

 

 

if you can rewrite the above in the following format, I might be able to give you a hand:

 

1. write out your thoughts ONE logic PER LINE

2. write out your logic ONE action per LINE

3. write out your action ONE sentence per LINE

4. start a NEW LINE for every sentence

Share this post


Link to post
Share on other sites

Sure)

 

There is a 60-min strategy:

Buy at the high of the previous 60-min bar on stop.

Sell at the low of the previous 60-min bar on stop.

Anytime there is an open position, place a stoploss.

That is it.

 

I want to eveluate the best stoploss value.

It's impossible to eveluate it on 60-min bars.

Various stoploss values must be tested on smaller timeframe bars.

What code will let eveluate an optimized stoploss value?

Share this post


Link to post
Share on other sites
Sure)

 

There is a 60-min strategy:

Buy at the high of the previous 60-min bar on stop.

Sell at the low of the previous 60-min bar on stop.

Anytime there is an open position, place a stoploss.

That is it.

 

I want to eveluate the best stoploss value.

It's impossible to eveluate it on 60-min bars.

Various stoploss values must be tested on smaller timeframe bars.

What code will let eveluate an optimized stoploss value?

 

 

h[1] = high of the previous bar

 

EasyLanguage works on bar-by-bar basis; it doesn't matter what is the bar resolution...

Share this post


Link to post
Share on other sites
...

 

I want to eveluate the best stoploss value.

It's impossible to eveluate it on 60-min bars.

Various stoploss values must be tested on smaller timeframe bars.

What code will let eveluate an optimized stoploss value?

 

 

what do you mean by "impossible" ?

 

your stop loss is too small?

it triggers too soon?

not triggered at all?

etc...

Share this post


Link to post
Share on other sites
Sure)

 

There is a 60-min strategy:

Buy at the high of the previous 60-min bar on stop.

Sell at the low of the previous 60-min bar on stop.

Anytime there is an open position, place a stoploss.

That is it.

 

I want to eveluate the best stoploss value.

It's impossible to eveluate it on 60-min bars.

Various stoploss values must be tested on smaller timeframe bars.

What code will let eveluate an optimized stoploss value?

 

You are using a position based stoploss, so if it is set to say $500 and the trade goes against you then it will be stopped when the total position has made $500 loss, regardless of the data compression (time period of bars used).

 

I suspect that what you are trying to do is to set the stoploss to be based upon the price movement expected in the time period (data compression) being used e.g. to base it upon the bar range or the ATR.

 

If that is what you are trying to do then it is probably easier (from a visualisation viewpoint) to use SETSTOPSHARE. This sets the amount per share or contract. The important point is that it does not need to be a fixed amount.

 

You can have an input or variable called, say, SL_AMOUNT. Then you have the code

 

SETSTOPSHARE;

SETSTOPLOSS(SL_AMOUNT);

 

This will set the stop loss per share/contract to be the amount the input or variable contains.

 

So you could set it to ATR

 

SL_AMOUNT = AvgTrueRange(10);

 

 

This would set it to the average true range based on 10 bars for the time interval (data compression) chosen in the plot. In other words the ATR and hence the SL_AMOUNT and hence the stop loss would vary according to the data compression.

 

You could also use an IF statement to set it to specific values based on bar type and interval

 

e;g. IF BARTYPE = 1 AND BARINTERVAL = 10 then SL_AMOUNT = 5;

 

This would set the stop loss amount to 5 for a 10 min intraday bar.

 

 

BARTYPE values are

 

0 = TickBar

1 = Intraday

2 = Daily

3 = Weekly

4 = Monthly

5 = Point & Figure

6 = (reserved)

7 = (reserved)

8 = Kagi

9 = Kase

10 = Line Break

11 = Momentum

12 = Range

13 = Renko

 

Personally however I would recommend using something like a volatility based stopped such as ATR which would automatically select stoploss levels at a basis appropirate to the time interval being traded. You don't have to think about it then.

 

Finally another possibility of course is to set a stop loss based on 1 time interval but to use it in a stategy based on another interval. For example you could have a strategy entered onto a 1 min chart, which uses an ATR taken from a 10 min chart, but that's a whole new thread on multiple data feeds and potentially GVs, ADEs and so on, which I don't want to go into at present.

 

 

Charlton

Share this post


Link to post
Share on other sites

Thank you for your replies!

But it seems to me that you haven't understood what I was asking for. Let me express my question by images. Image.gif?tsid=20091211-133231-9ec08099&forceAttachmentDownload=true

On the first chart there are 60-min bars. And the code for the strategy used is:

buy next bar at h stop;

setstopposition;

setstoploss(500);

sell short next bar at l stop;

setstopposition;

setstoploss(500);

 

On the second chart there are two data feeds: 5-min and 60-min. The code for the strategy is:

buy next bar at h of data2 stop;

setstopposition;

setstoploss(300);

sell short next bar at l of data2 stop;

setstopposition;

setstoploss(300);

 

So I want to trade on 60-min bars but I want also to verify wether my stoplosses are not executed inside 60-min bars.

 

On the third chart is a magnification of chart #2. One can see there that there were several trades inside one 60-min bar that shouldn't take place.

Share this post


Link to post
Share on other sites

Tams, thank you for your reply! But it seems to me, there is still some misunderstanding.

'Position limits' is used when you don't want to make buy #1 and afterwards buy #2, for examle. It doesn't solve the problem in my case: buy #1 then comes a stoploss (so there are no positions at the time), then comes another buy #1 and there comes another stoploss and so on ALL INSIDE ONE 60-MIN BAR.

I want that there would be no more than one buy/sell trade and one cover-trade inside a 60-min bar.

Share this post


Link to post
Share on other sites
Tams, thank you for your reply! But it seems to me, there is still some misunderstanding.

'Position limits' is used when you don't want to make buy #1 and afterwards buy #2, for examle. It doesn't solve the problem in my case: buy #1 then comes a stoploss (so there are no positions at the time), then comes another buy #1 and there comes another stoploss and so on ALL INSIDE ONE 60-MIN BAR.

I want that there would be no more than one buy/sell trade and one cover-trade inside a 60-min bar.

 

 

I would suggest you to draw a flow chart to illustrate your logic.

 

the branches should include ALL THE PERMUTATIONS.

 

324px-LampFlowchart.svg.png

Share this post


Link to post
Share on other sites
Tams, thank you for your reply! But it seems to me, there is still some misunderstanding.

'Position limits' is used when you don't want to make buy #1 and afterwards buy #2, for examle. It doesn't solve the problem in my case: buy #1 then comes a stoploss (so there are no positions at the time), then comes another buy #1 and there comes another stoploss and so on ALL INSIDE ONE 60-MIN BAR.

I want that there would be no more than one buy/sell trade and one cover-trade inside a 60-min bar.

 

If you follow Tams advice of drawing out the logic think about:

 

(a) How you might count whether an initiating trade took place during a bar

(b) How you reset the count to zero when a new bar forms

© How you know if there are currently any open positions in play during this bar

 

 

Charlton

Share this post


Link to post
Share on other sites
Guys, I'm sorry for my incomprehensible style of writing. I thought I expressed myself clearly but seems it was not.

So, here is another attempt of mine.

7f6a3e4ac8fbe6bc14763edc3e87c2eb

 

 

your picture is not showing.

 

you can load the picture directly to TradersLaboratory.

Just click the Manage Attachments button under the Advanced reply window.

Share this post


Link to post
Share on other sites

For TradeStation, get the ebook EasyLanguage Essentials Programmers Guide (free)

 

read up on Look-Inside-Bar-Back-testing (LIBB).

 

 

 

For MultiCharts, use Backtesting Precision. (same function as LIBB)

 

You are back testing on 60 min bars,

and using a finer resolution (e.g. 1 tick data) as back testing precision.

 

 

attachment.php?attachmentid=16585&stc=1&d=1260795941

Backtesting_Precision.gif.8d5de67b56a6a445e83b4515f630b33f.gif

Edited by Tams

Share this post


Link to post
Share on other sites
Tams, I am using Multicharts but I don't see the 'Backtesting Precision' tab in my 'Strategy Properties'.

Maybe, this tab appeared in a new version? I have 5.0 Beta.

 

 

.......... time to upgrade !

Share this post


Link to post
Share on other sites

I' m sorry for delays in my replies. I got a newer version of MultiCharts. It's become much easier with that new feature but it's not all obvious though. It doesn't work properly with some of my strategies. Now I'm trying to figure it all out for myself.

Tams, thank you very much for your help!

Share this post


Link to post
Share on other sites
I' m sorry for delays in my replies. I got a newer version of MultiCharts. It's become much easier with that new feature but it's not all obvious though. It doesn't work properly with some of my strategies. Now I'm trying to figure it all out for myself.

Tams, thank you very much for your help!

 

 

.......... you are welcome !

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

    • LLY Lilly stock bull flag breakout watch above 818.53, https://stockconsultant.com/?LLY
    • GKOS Glaukos stock narrow range breakout watch, https://stockconsultant.com/?GKOS
    • AMZN Amazon stock back to 181.72 support area with bullish stats, https://stockconsultant.com/?AMZN
    • Date: 30th May 2024.   Market News – Yields jump; Stocks under pressure.   Economic Indicators & Central Banks:   The FOMC’s high-for-longer stance, along with some increasing fears of a rate hike, continue to weigh on Treasuries. That’s taking a toll on Wall Street too with profit taking from recent record highs knocking stocks down further. There was weakness in EGBs after stronger German inflation and wage data. US Yields have risen since the market breathed a sigh of relief after cooler CPI and retail sales, and are back near the highs since November. Global equities are headed for their worst week since mid-April. In New Zealand, the new government delivered on its election promise to cut taxes in its first budget even as the Treasury forecast bigger deficits and a delayed return to surplus. Asian & European Open: Wall Street dropped, led by the Dow’s -1.06% decline. The S&P500 declined -0.74%, with the NASDAQ -0.58% lower. Several earnings reports have been less than stellar as well. Salesforce disappointed today, while HP beat. Meanwhile, retailers are coming into the spotlight and there are fears of weakness. Financial Markets Performance: The USDIndex has been benefiting from the hawkish outlooks. It has bounced back over 105. The USDJPY fell, with the Yen advancing after weakening to beyond 157.50 on Wednesday, falling through a level that had prompted the latest round of suspected action. The Rand extended losses as South Africa’s election vote count gathers pace. Gold and Oil steadied. USOIL is well below the week’s high however it has been ranging since  yesterday afternoon as traders look to US stockpile data later today and an OPEC+ meeting at the weekend for more clarity on the supply and demand outlook. 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 HFM 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 HFMarkets 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.
    • Date: 29th May 2024. Market News – Stocks drop with bonds.Economic Indicators & Central Banks:   The NASDAQ was the star as the markets, of it rallied 0.59% to close at 17,019.88 for a fresh record high. And it is its first time over the 17,000 level. A 7% pop from Nvidia supported. Fed Kashkari said he wants to see “many more months” of positive inflation data before a rate cut. German GfK consumer confidence improves further. All signs are that consumption trends should improve with the rise in real-disposable income as falling inflation, rising wages and the prospect of rate cuts boost sentiment. US consumer confidence beat assumptions. Confidence has displayed only a slight updraft since mid-2022, after a prior deterioration from mid-2021 peaks. Asian & European Open: European & US stocks slipped earlier today against a backdrop of rising government bond yields. DAX fell 0.2% and FTSE lost 0.06%. Traders are pricing in that the ECB will lower its deposit rate when policymakers meet next week. Asia stock market dipped as Chinese tech and property companies declined. The Hang Seng Tech index shed 2.3%. Financial Markets Performance: The USDIndex is steady and Treasury yields also held firm ahead of key inflation data, which could offer more clarity on the Fed rate trajectory. The USDJPY fell to 156.88 nearing levels that prompted suspected interventions by Tokyo in late April and early May. Currently rebounded again above 157. Japanese officials might issue verbal warnings again, but without tangible action, the USDJPY could march towards late April levels The EURUSD dipped to 1.0830 but still marked its first monthly gain in 2024. Meanwhile, the GBPUSD was last at 1.2760. Gold steadied at $2350 per ounce as markets wait for key US PCE numbers at the end of the week. Bullion hit a record high early last week, only to post the sharpest weekly correction this year as the Fed reiterated the “high-for-longer” message. Oil broke the $80 barrier as Middle East tensions have picked up again. Markets are now looking ahead to the release of key US inflation data and the OPEC+ meeting on June 2. 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 HFM 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 HFMarkets 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.