| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Code to calculate TP/SL based on lot size? https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4991 |
Page 1 of 1 |
| Author: | aclyeh [ Fri Nov 18, 2016 2:02 am ] |
| Post subject: | Code to calculate TP/SL based on lot size? |
Hi all, I am trying to write a piece of code but struggling for days on a seemingly simple calculation. The EA does the following: - Takes as user input the Profit_Target and Drawdown_Target, which are equity targets based in the same currency as the account. Default is USD, and $10,200 / $9,800, which means a target profit of $200 and loss of $200, assuming a starting equity of $10,000 (typical default for Empty4's strategy tester) - If profit or drawdown target is reached, close all trades - Calculates the price targets for TP and SL based on the number of lot positions and displays it in the comments The goal is so that the user knows the new TP/SL price after adding or closing traded lots. The code assumes there is only one pair traded, and is trading long. ------------------ The EA automatically adds 0.01 lots long every 2 hours (up to the predefined limit) to allow testing, but the trading part is just used for testing the main code here, which is to calculate TP/SL is as follows: Code: Select all Currently the TP/SL calculations seems a bit off, but I can't quite figure out why. Would be glad to get some of your help, or if someone already has a similar method in their EA shell, please share or advise! Many thanks |
|
| Author: | afeudale [ Sat Dec 03, 2016 6:30 pm ] |
| Post subject: | Code to calculate TP/SL based on lot size? |
What the hell...I just typed out my response and then went to preview and it deleted it... Oh well, this is my first time posting my code, so it's a bit messy, but hopefully you can use the relevant parts. My code calculates lot size based on SL, account free margin, open lots, etc. It's a grid system, so L1UP, etc are grid levels. TopLevel and BottomLevel are the SL values being used. Code: Select all |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|