Welcome to the Traders Laboratory Forums.
Coding Forum Collaborate, receive help, or discuss coding related issues.

Reply
Old 12-11-2009, 07:27 AM   #1

Join Date: Nov 2008
Location: Orel
Posts: 33
Ignore this user

Thanks: 5
Thanked 4 Times in 2 Posts

Eliminating Repeated Trades

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!
GRANDEUR is offline  
Reply With Quote
Old 12-11-2009, 08:29 AM   #2

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Eliminating Repeated Trades

Quote:
Originally Posted by GRANDEUR »
...
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
__________________



Only an idiot would reply to a stupid post
Tams is offline  
Reply With Quote
Old 12-11-2009, 08:57 AM   #3

Join Date: Nov 2008
Location: Orel
Posts: 33
Ignore this user

Thanks: 5
Thanked 4 Times in 2 Posts

Re: Eliminating Repeated Trades

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?
GRANDEUR is offline  
Reply With Quote
Old 12-11-2009, 09:14 AM   #4

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Eliminating Repeated Trades

Quote:
Originally Posted by GRANDEUR »
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...
__________________



Only an idiot would reply to a stupid post
Tams is offline  
Reply With Quote
Old 12-11-2009, 09:17 AM   #5

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Eliminating Repeated Trades

Quote:
Originally Posted by GRANDEUR »
...

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...
__________________



Only an idiot would reply to a stupid post
Tams is offline  
Reply With Quote
Old 12-11-2009, 09:56 AM   #6

Join Date: May 2008
Location: London
Posts: 44
Ignore this user

Thanks: 26
Thanked 21 Times in 15 Posts

Re: Eliminating Repeated Trades

Quote:
Originally Posted by GRANDEUR »
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
Charlton is offline  
Reply With Quote
The Following 2 Users Say Thank You to Charlton For This Useful Post:
aaa (12-12-2009), Tams (12-11-2009)
Old 12-11-2009, 01:33 PM   #7

Join Date: Nov 2008
Location: Orel
Posts: 33
Ignore this user

Thanks: 5
Thanked 4 Times in 2 Posts

Re: Eliminating Repeated Trades

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.
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.
GRANDEUR is offline  
Reply With Quote
Old 12-11-2009, 01:46 PM   #8

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Eliminating Repeated Trades

a picture is worth a thousand words !
__________________



Only an idiot would reply to a stupid post
Tams is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
To Eliminate Repeated Trades (EL) GRANDEUR Coding Forum 1 11-02-2009 04:28 AM
Stevenvegas Trades Stevenvegas Traders Log 62 04-21-2009 08:50 AM
B&B Trades B&Btrades Beginners Forum 0 03-31-2009 12:43 PM
What Do You Do in Between Trades? Szymon General Discussion 21 02-24-2009 06:05 AM
My trades Pippy23 Forex Trading Laboratory 13 04-03-2007 07:10 PM

All times are GMT -4. The time now is 02:17 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.