TRADE Run-up and Drawdown

User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: TRADE Run-up and Drawdown

Post by gaheitman »

Khalaad wrote:A request to all programmers.

Is it possible to calculate, and also add to a Trade History CSV.ex4, the fololowing:
maximum run-up before a trade closes; and
maximum drawdown before a trade closes;

as in the attached Excel file?

Thank you.

Khalid
Khalid,

I took a look at modifying a script I wrote years ago to do what you want. However, there are some problems with giving you good data. The best granularity we have is a minute, so while we know when within that minute you entered/exited a trade, we don't know where the price extremes fall within the minute. It could be that you exit in the last 20 seconds of a bar, but the bar could continue to move either for or against your trade. If this movement is at the extreme of the trade's movement, we'll overstate either the run up or draw down by including the High/Low of that end bar.

Do you want to skip the entry and exit bars in the calculations?

It won't be as pretty as your example, I'm simply creating a CSV file to be imported. :D

George
User avatar
DING
Trader
Posts: 103
Joined: Wed Nov 16, 2011 11:53 am

Re: TRADE Run-up and Drawdown

Post by DING »

it is better that export CSV could include order pips, duration and comment, thanks a lot.
dusktrader
Trader
Posts: 13
Joined: Tue Nov 22, 2011 3:52 pm
Location: North Carolina

Re: TRADE Run-up and Drawdown

Post by dusktrader »

I've also been searching for something similar to what you are asking for, but so far have not found a tool. The purpose of the tool (at least in my case) would be to help optimize a trading strategy. For example, in my current strategy I use a takeprofit level of 20 pips. I only picked that as a starting point and really no other special reason. However, it sure would be nice to have a way to gather the following, for example:
At a given hard TP and SL level:
  • % of winning trades
  • max profit level potential beyond TP level
  • max drawdown without hitting SL level
If you had a way to gather this information while you traded, you could optimize your strategy as you trade. For example if you review trades weekly, you might find that you could tighten your stop and still maintain a satisfactory win%. That would be the same effect as improving your R:R ratio.

I feel pretty sure that there must be a tool out there that does this, or something similar. It's probably not as critical for EA traders because they can simply run through the iterations in Strategy Tester I think. But for discretionary traders or those developing new strategies, it could really be helpful.
Image
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: TRADE Run-up and Drawdown

Post by gaheitman »

OK, here's what I have so far.
pic_08 2011-12-03 15.51.gif
I've run into the issue where there is not enough M1 history to display the trades. I'm trying to decide if I want to blank out that data via "N/A", or keep looking at higher time frames until I have enough data to calculate the run up/draw down. Any preferences?

Also, would you prefer the sign of the draw down to be consistent with the state of the trade at the time (negative) or consistent with the name (positive). For me, saying "draw down was 20 pips" is more natural than saying "draw down was -20 pips"

Finally, run up and draw down do not take into account spread. The problem is spread changes all the time, especially after hours and I don't want the calculations to be different every time you run the script.

George
You do not have the required permissions to view the files attached to this post.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: TRADE Run-up and Drawdown

Post by gaheitman »

Khalaad wrote: George,

This is GREAT.

I would:
keep looking at higher time frames until I have enough data to calculate the run up/draw down;
write drawdown any way you prefer -- "20 pips" is as good a way as any; and
not worry about the not-including-spread calculations; at most, if possible, annotate somewhere the run-up and drawdown calculations do not take spread into account.

Thank you so very much.

Khalid
OK, here's a test version for you to take a look at. In the top of the script is a define for the filename, it is currently "OrdersReport.csv". Remember it will be placed in your Experts\Files directory.

Code: Select all

#define FileName "OrdersReport.csv"

//globals 
bool Debug = false;
Also notice the Debug flag. If you turn it on, it will write to the log each ticket number, the timeframe it is looking at and the beg/end candle times so you can see what the application is using to evaluate the run up and run down. Looks like this:

Code: Select all

03:39:11 DumpHistory EURUSD,M5: Candle usage for Ticket # 103944436 | Period: 5 | 2011.11.22 08:50 |  2011.11.22 09:15
03:39:11 DumpHistory EURUSD,M5: Candle usage for Ticket # 103944672 | Period: 1 | 2011.11.22 09:04 |  2011.11.22 11:15
03:39:11 DumpHistory EURUSD,M5: Candle usage for Ticket # 103944920 | Period: 5 | 2011.11.22 09:10 |  2011.11.22 09:25
03:39:11 DumpHistory EURUSD,M5: Candle usage for Ticket # 103944926 | Period: 1 | 2011.11.22 09:14 |  2011.11.22 09:22
[/size]

From an ugly code standpoint, I wrote much of this in 2006 when I first started in Forex and Empty4, so be kind. :D

If you'd like different column headings or order, let me know.

EDIT: Updated code to include Comment and Magic Number.

EDIT: Update to fix defect in offset logic for RunUp.
George
You do not have the required permissions to view the files attached to this post.
Last edited by gaheitman on Sun Dec 04, 2011 12:14 pm, edited 1 time in total.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: TRADE Run-up and Drawdown

Post by gaheitman »

Khalaad wrote:
gaheitman wrote:
From an ugly code standpoint, I wrote much of this in 2006 when I first started in Forex and Empty4, so be kind. :D

If you'd like different column headings or order, let me know.

George
Thank you, George.

You are talking to a MQL illiterate!

I know you are a coding connoisseur; but when an 'ugly' code delivers, it's beautiful. Will run this, and get back to you Monday afternoon, your time.

Thank you once again.

Khalid
I have updated the script in my previous post to include Comment and Magic Number. See: http://www.stevehopwoodforex.com/phpBB3 ... 1762#p1760
markft
Trader
Posts: 82
Joined: Thu Dec 08, 2011 12:06 pm
Location: Sydney, Australia

Re: TRADE Run-up and Drawdown

Post by markft »

Hi George,

I have been using the script and believe I found what I think were a couple of minor bugs causing incorrect run-up/dd calculations in some cases.

I updated the script to resolve these; please see attached. I am an MQL newbie (but a coding veteran in others) so I might have been missing some MQL specific stuff.

Thank you again for preparing the script. I have been juggling between mt4i and myfxbook for similar functionality but your script is much more useful than both.

Kind Regards,
Mark
DumpHistory.mq4
You do not have the required permissions to view the files attached to this post.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: TRADE Run-up and Drawdown

Post by gaheitman »

markft wrote:Hi George,

I have been using the script and believe I found what I think were a couple of minor bugs causing incorrect run-up/dd calculations in some cases.

I updated the script to resolve these; please see attached. I am an MQL newbie (but a coding veteran in others) so I might have been missing some MQL specific stuff.

Thank you again for preparing the script. I have been juggling between mt4i and myfxbook for similar functionality but your script is much more useful than both.

Kind Regards,
Mark
DumpHistory.mq4
I believe you are right! I can't believe I was confused about the direction of the indicator "number line". Thanks for finding the issue, fixing it and bringing it to my attention!

I'm replacing the first post with your version.

George
markft
Trader
Posts: 82
Joined: Thu Dec 08, 2011 12:06 pm
Location: Sydney, Australia

Re: TRADE Run-up and Drawdown

Post by markft »

No problems George. That's what is good about open source, it gives all a chance to benefit and contribute. :)
AnotherBrian

Re: TRADE Run-up and Drawdown

Post by AnotherBrian »

This stuff is GOLD. Because I know I'll forget where I got this just after I lose the file, is it possible to post in the first post with some instruction (for new readers) by perhaps giving George the first post?
Just a suggestion.

Thanks for the script!

Brian
Post Reply

Return to “Scripts”