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

    • I'm pretty sure that a Russian resident would say that recessions are real today. Their prime interest rate is 21%, their corporate military contractors are threatening to file bankruptcy, and sticks of butter are kept under lock and key in their grocery stores because shoplifters are stealing it in bulk so they can resell it on the black market. A downturn is cyclical until it turns into a collapse. I really don't think anyone will be buying-into this mess.😬
    • Well said. This principle is highly analogous to trading. Any human can easily click buy or sell when they "feel" that price is about to go up or down. The problem with feeling, commonly referred to as "instinctive" trading, is that it cannot be quantified. And because it cannot be quantified, it cannot be empirically tested. Instinctive trading has the lowest barrier to entry and therefore returns the lowest reward. As this is true for most things in life, this comes as no surprise. Unfortunately, the lowest barrier to entry is attractive to new traders for obvious reasons. This actually applied to me decades ago.🤭   It's only human nature to seek the highest amount of reward in exchange for the lowest amount of work. In fact, I often say that there is massive gray area between efficiency and laziness. Fortunately, losing for a living inspired me to investigate the work of Wall Street quants who refer to us as "fishfood" or "cannonfodder." Although I knew that we as retail traders cannot exploit execution rebates or queues like quants do, I learned that we can engage in automated scalp, swing, and trend trading. The thermonuclear caveat here, is that I had no idea how to write code (or program) trading algorithms. So I gravitated toward interface-based algorithm builders that required no coding knowledge (see human nature, aforementioned). In retrospect, I should never have traded code written by builder software because it's buggy and inefficient. However, my paid subscription to the builder software allowed me to view the underlying source code of the generated trading algo--which was written in MQL language. Due to a lack of customization in the builder software, I inevitably found myself editing the code. This led me to coding research which, in turn, led me to abandoning the builder software and coding custom algo's from scratch. Fast forward to the present, I can now code several trading strategies per day across 2 different platforms. Considering how inefficient manual backtesting is, coding is a huge advantage. When a new trading concept hits me, I can write the algo, backtest it, and optimize it within an hour or so--across multiple exchanges and symbols, and cycle through hundreds of different settings for each input. And then I get pages upon pages of performance metrics with the best settings pre-highlighted. Having said all of this, I am by no means an advanced programmer. IMHO, advanced programmers write API gateways, construct their own custom trading platforms, use high end computers with field programmable gateway array chips, and set up shop in close proximity to the exchanges. In any event, a considerable amount of work is required just to get toward the top of the "fishfood"/"cannonfodder" pool. Another advantage of coding is that it forces me to write trade entry and exit conditions (triggers) in black & white, thereby causing me to think microscopically about my precise trade trigger conditions. For example, I have to decide whether the algo should track the slope, angle, and level of each bar price and indicator to be used. Typing a hard number like 50 degrees of angle into code is a lot different than merely looking at a chart myself and saying, that's close enough.  Code doesn't acknowledge "maybe" nor "feelings." Either the math (code) works (is profitable) or doesn't work (is a loser). It doesn't get angry, sad, nor overly optimistic. And it can trade virtually 24 hours per day, 5 days per week. If you learn to code, you'll eventually reach a point where coding an algo that trades as you intended provides its own sense of accomplishment. Soon after, making money in the market merely becomes a side effect of your new job--coding. This is how I compete, at least for now, in this wide world of trading. I highly recommend it.  
    • VRA Vera Bradley stock watch, pull back to 5.08 support area at https://stockconsultant.com/?VRA
    • MU Micron stock watch, pull back to 102.83 gap support area with high trade quality at https://stockconsultant.com/?MU
    • ACLX Arcellx stock watch, trending at 84.6 support area with bullish indicators at https://stockconsultant.com/?ACLX
×
×
  • Create New...

Important Information

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