stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

TRADE Run-up and Drawdown
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=104
Page 1 of 2
Author:  gaheitman [ Wed Nov 30, 2011 9:17 am ]
Post subject:  Re: TRADE Run-up and Drawdown

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
Author:  DING [ Wed Nov 30, 2011 4:00 pm ]
Post subject:  Re: TRADE Run-up and Drawdown

it is better that export CSV could include order pips, duration and comment, thanks a lot.
Author:  dusktrader [ Sat Dec 03, 2011 6:40 pm ]
Post subject:  Re: TRADE Run-up and Drawdown

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.
Author:  gaheitman [ Sat Dec 03, 2011 9:00 pm ]
Post subject:  Re: TRADE Run-up and Drawdown

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
Author:  gaheitman [ Sun Dec 04, 2011 8:52 am ]
Post subject:  Re: TRADE Run-up and Drawdown

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
Author:  gaheitman [ Sun Dec 04, 2011 12:16 pm ]
Post subject:  Re: TRADE Run-up and Drawdown

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
Author:  markft [ Sun Dec 18, 2011 1:27 pm ]
Post subject:  Re: TRADE Run-up and Drawdown

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
Author:  gaheitman [ Sun Dec 18, 2011 2:03 pm ]
Post subject:  Re: TRADE Run-up and Drawdown

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
Author:  markft [ Sun Dec 18, 2011 9:28 pm ]
Post subject:  Re: TRADE Run-up and Drawdown

No problems George. That's what is good about open source, it gives all a chance to benefit and contribute. :)
Author:  AnotherBrian [ Fri Dec 30, 2011 4:54 am ]
Post subject:  Re: TRADE Run-up and Drawdown

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
All times are UTC Page 1 of 2