script to automatic calculate stop loss and lot size

MPTM's new home
Post Reply
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: script to automatic calculate stop loss and lot size

Post by SteveHopwood »

zalezny wrote:HI,

I`m looking for a script which will help me to open position with proper MM settings.
Maybe somebody knows script which can support open position process. I would like to automatic calculate stop loss, lot size regarding MM rule - risk maximum 1% per trade.

Would be perfect is somebody could support me.


Cheers

Zalezny
Give it a few days to see if someone posts a script. If not, get in touch with me via pm. Or maybe someone else can knock this script together. The code is all in my shell ea.

You will need to tell us how to calculate your stop loss.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
matt_32
Trader
Posts: 204
Joined: Tue Apr 03, 2012 8:51 am
Location: Crete, Greece

Re: script to automatic calculate stop loss and lot size

Post by matt_32 »

zalezny wrote:HI,

I`m looking for a script which will help me to open position with proper MM settings.
Maybe somebody knows script which can support open position process. I would like to automatic calculate stop loss, lot size regarding MM rule - risk maximum 1% per trade.

Would be perfect is somebody could support me.


Cheers

Zalezny

Check out this tool (Easy Order) in http://www.forexfactory.com/showthread.php?t=281772
I hope this is what you are looking for

Matt
"Wise men speak because they have something to say; Fools because they have to say something." - Plato 347 BC
joswald
Trader
Posts: 31
Joined: Sat Jan 07, 2012 4:57 pm
Location: Australia

Re: script to automatic calculate stop loss and lot size

Post by joswald »

jago25
Trader
Posts: 89
Joined: Fri Oct 25, 2013 5:23 am

Re: script to automatic calculate stop loss and lot size

Post by jago25 »

Are there any more solutions out there for risk/money management that you've found?
If it's really good I don't mind paying a reasonable amount for a small tool. Any more words to help me search?

My broker is currently FXCM. Ideally I'd like something standalone so I'm not tied to a platform. Ideally it would be cross platform. It could even run on android - I'd be happy to chart on the desktop but actually execute trades on a phone.

There are a few manual out there but you have to type in the numbers yourself - too slow.
Track'n'Trade does MoneyManagement really well but it's subscription based, overkill for this little job. I like this program rather a lot but I'm not ready to start spending money on such things just yet - need to learn more and practice first.
EasyOrder uses a dll that doesn't seem to work under linux.
mt4trademanager works but the buttons flash on screen update.

The FXCM windows desktop app converts the stake per pip to $ but it doesn't on the web frontend or Android app.

Can I use Usd Mr (used margin) as a rough guide?
joswald
Trader
Posts: 31
Joined: Sat Jan 07, 2012 4:57 pm
Location: Australia

Post by joswald »

Try this... I removed all the unnecessary stuff. It's a tad slow calculating the position size but works fine.
You do not have the required permissions to view the files attached to this post.
User avatar
fxdaytrader
Trader
Posts: 190
Joined: Sun Jun 10, 2012 7:03 am
Location: Poon-Town (germany, se-asia, se-europe) ...

Re: script to automatic calculate stop loss and lot size

Post by fxdaytrader »

Last year I published on ordersend-script which computes the lotsize based on risk.

In the meantime I have found a nicer way of doing the same, so I decided to use jmw1970's way in my stuff (cui honorem, honorem ;) ).

Attached you will find a mql4-file. This file consists all parts you have to insert to your existing EA or ordersend-script to computed lots based on risk and stoploss (not pips, the price!).
If you do not know the price and want to deal with fixed pips, change the external variable "CalcWithSlPipsIfNoSlGiven" to your needs.

That are the external vars, find the functions / instructions in the attached mql4-file (in fact you only have to copy&paste all to your exisiting ea) 8-)

Code: Select all

//calculate lots based on risk and stoploss, fxdaytrader (calclots function by jmw1970, other parts by WHRoeder, mod./adapted by fxdaytrader, see code for details)
extern double lots = 0.1;
extern string rbclh0="Use risk based lotsize, instead of fixed lots?";
extern string rbclh1="   if no SL is specified, the script calculates with that pips";
extern bool   UseLotsPerRiskCalculation=TRUE;
extern double RiskPercentage=2.5;
extern string rbclh2="----: advanced lotsize calculation settings:";
extern double CalcWithSlPipsIfNoSlGiven = 30.0;//calc with this stoploss-pips distance if no sl-price is given
extern bool   DoFreeMarginCheck=true;          //should check if there is enough free margin to open the trade
extern bool   DoFreeMarginForSlAlsoCheck=true;//checks if there is also enough free margin for a (potentially) SL-hit
To compute the lotsize based on risk and SL, you could insert right before the ordersend(-command:

lots = CalcLotsAndCheckMargin(Symbol(),OP_BUY,lots,RiskPercentage,Bid,0.0);

if the last var is 0, then a distance of price-CalcWithSlPipsIfNoSlGiven pips will be used, if you want to specify a certain price it goes analogue, for example:

double stoplossprice=1.3590;
lots = CalcLotsAndCheckMargin(Symbol(),OP_BUY,lots,RiskPercentage,Bid,stoplossprice);

please try :)
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Utilities Indicators and Scripts”