Money Management Script

 

Hi,

I have a nice script which will automatically calculate lot sizing based on SL settings, % of account risked, and then open the order. It can open instant and pending orders. It works perfectly on 4 digit brokers but it does not do anything with 5 digit brokers. Can someone look over the code and see if this what can be done to make it 5 digit compatible? Thanks so much!

Buy Script:

#property show_inputs

extern double Lots = 1.0;

extern double Entry = 0.0;

extern double TakeProfit = 500.0;

extern double StopLoss = 40.0;

extern bool UseActualSlTp = TRUE;

extern double StopLossPrice = 0.0;

extern double TakeProfitPrice = 0.0;

extern int NumberOfOrders = 1;

extern bool MicroOrdersAllowed = TRUE;

extern bool MiniOrdersAllowed = TRUE;

extern bool UseMoneyMgmt = TRUE;

extern double RiskPercent = 5.0;

extern string Note = "0 in Entry field means Market Order Buy";

extern string Comments = "Buy (mm)";

int start() {

double ld_0 = RiskPercent / 100.0;

int li_8 = 0;

int l_cmd_12 = 4;

if (Ask > Entry && Entry > 0.0) l_cmd_12 = 2;

if (Entry == 0.0) {

Entry = Ask;

l_cmd_12 = 0;

}

double l_price_16 = Entry - StopLoss * Point;

double l_price_24 = Entry + TakeProfit * Point;

if (UseActualSlTp) {

StopLoss = (Entry - StopLossPrice) / Point;

l_price_16 = StopLossPrice;

l_price_24 = TakeProfitPrice;

}

if (MiniOrdersAllowed) li_8 = 1;

if (MicroOrdersAllowed) li_8 = 2;

if (UseMoneyMgmt) Lots = NormalizeDouble(AccountBalance() * ld_0 / StopLoss / MarketInfo(Symbol(), MODE_TICKVALUE), li_8);

if ((Lots < 0.01 && MicroOrdersAllowed) || (Lots < 0.1 && MiniOrdersAllowed && MicroOrdersAllowed == FALSE)) Comment("YOUR LOTS SIZE IS TOO SMALL TO PLACE!");

if (Lots > 0.0) for (int l_count_32 = 0; l_count_32 < NumberOfOrders; l_count_32++) OrderSend(Symbol(), l_cmd_12, Lots, Entry, 2, l_price_16, l_price_24, Comments, 0, 0, LimeGreen);

return (0);

}

Sell Script:

#property show_inputs

extern double Lots = 1.0;

extern double Entry = 0.0;

extern double TakeProfit = 500.0;

extern double StopLoss = 40.0;

extern bool UseActualSlTp = TRUE;

extern double StopLossPrice = 0.0;

extern double TakeProfitPrice = 0.0;

extern int NumberOfOrders = 1;

extern bool MicroOrdersAllowed = TRUE;

extern bool MiniOrdersAllowed = TRUE;

extern bool UseMoneyMgmt = TRUE;

extern double RiskPercent = 5.0;

extern string Note = "0 in Entry field means Market Order Sell";

extern string Comments = "Sell (mm)";

int start() {

double ld_0 = RiskPercent / 100.0;

int li_8 = 0;

int l_cmd_12 = 5;

if (Bid 0.0) l_cmd_12 = 3;

if (Entry == 0.0) {

Entry = Bid;

l_cmd_12 = 1;

}

double l_price_16 = Entry + StopLoss * Point;

double l_price_24 = Entry - TakeProfit * Point;

if (UseActualSlTp) {

StopLoss = (StopLossPrice - Entry) / Point;

l_price_16 = StopLossPrice;

l_price_24 = TakeProfitPrice;

}

if (MiniOrdersAllowed) li_8 = 1;

if (MicroOrdersAllowed) li_8 = 2;

if (UseMoneyMgmt) Lots = NormalizeDouble(AccountBalance() * ld_0 / StopLoss / MarketInfo(Symbol(), MODE_TICKVALUE), li_8);

if ((Lots < 0.01 && MicroOrdersAllowed) || (Lots < 0.1 && MiniOrdersAllowed && MicroOrdersAllowed == FALSE)) Comment("YOUR LOTS SIZE IS TOO SMALL TO PLACE!");

if (Lots > 0.0) for (int l_count_32 = 0; l_count_32 < NumberOfOrders; l_count_32++) OrderSend(Symbol(), l_cmd_12, Lots, Entry, 2, l_price_16, l_price_24, Comments, 0, 0, Red);

return (0);

}

 
stimuls:
Hi,

I have a nice script which will automatically calculate lot sizing based on SL settings, % of account risked, and then open the order. It can open instant and pending orders. It works perfectly on 4 digit brokers but it does not do anything with 5 digit brokers. Can someone look over the code and see if this what can be done to make it 5 digit compatible? Thanks so much!

Buy Script:

#property show_inputs

extern double Lots = 1.0;

extern double Entry = 0.0;

extern double TakeProfit = 500.0;

extern double StopLoss = 40.0;

extern bool UseActualSlTp = TRUE;

extern double StopLossPrice = 0.0;

extern double TakeProfitPrice = 0.0;

extern int NumberOfOrders = 1;

extern bool MicroOrdersAllowed = TRUE;

extern bool MiniOrdersAllowed = TRUE;

extern bool UseMoneyMgmt = TRUE;

extern double RiskPercent = 5.0;

extern string Note = "0 in Entry field means Market Order Buy";

extern string Comments = "Buy (mm)";

int start() {

double ld_0 = RiskPercent / 100.0;

int li_8 = 0;

int l_cmd_12 = 4;

if (Ask > Entry && Entry > 0.0) l_cmd_12 = 2;

if (Entry == 0.0) {

Entry = Ask;

l_cmd_12 = 0;

}

double l_price_16 = Entry - StopLoss * Point;

double l_price_24 = Entry + TakeProfit * Point;

if (UseActualSlTp) {

StopLoss = (Entry - StopLossPrice) / Point;

l_price_16 = StopLossPrice;

l_price_24 = TakeProfitPrice;

}

if (MiniOrdersAllowed) li_8 = 1;

if (MicroOrdersAllowed) li_8 = 2;

if (UseMoneyMgmt) Lots = NormalizeDouble(AccountBalance() * ld_0 / StopLoss / MarketInfo(Symbol(), MODE_TICKVALUE), li_8);

if ((Lots < 0.01 && MicroOrdersAllowed) || (Lots < 0.1 && MiniOrdersAllowed && MicroOrdersAllowed == FALSE)) Comment("YOUR LOTS SIZE IS TOO SMALL TO PLACE!");

if (Lots > 0.0) for (int l_count_32 = 0; l_count_32 < NumberOfOrders; l_count_32++) OrderSend(Symbol(), l_cmd_12, Lots, Entry, 2, l_price_16, l_price_24, Comments, 0, 0, LimeGreen);

return (0);

}

Sell Script:

#property show_inputs

extern double Lots = 1.0;

extern double Entry = 0.0;

extern double TakeProfit = 500.0;

extern double StopLoss = 40.0;

extern bool UseActualSlTp = TRUE;

extern double StopLossPrice = 0.0;

extern double TakeProfitPrice = 0.0;

extern int NumberOfOrders = 1;

extern bool MicroOrdersAllowed = TRUE;

extern bool MiniOrdersAllowed = TRUE;

extern bool UseMoneyMgmt = TRUE;

extern double RiskPercent = 5.0;

extern string Note = "0 in Entry field means Market Order Sell";

extern string Comments = "Sell (mm)";

int start() {

double ld_0 = RiskPercent / 100.0;

int li_8 = 0;

int l_cmd_12 = 5;

if (Bid 0.0) l_cmd_12 = 3;

if (Entry == 0.0) {

Entry = Bid;

l_cmd_12 = 1;

}

double l_price_16 = Entry + StopLoss * Point;

double l_price_24 = Entry - TakeProfit * Point;

if (UseActualSlTp) {

StopLoss = (StopLossPrice - Entry) / Point;

l_price_16 = StopLossPrice;

l_price_24 = TakeProfitPrice;

}

if (MiniOrdersAllowed) li_8 = 1;

if (MicroOrdersAllowed) li_8 = 2;

if (UseMoneyMgmt) Lots = NormalizeDouble(AccountBalance() * ld_0 / StopLoss / MarketInfo(Symbol(), MODE_TICKVALUE), li_8);

if ((Lots < 0.01 && MicroOrdersAllowed) || (Lots < 0.1 && MiniOrdersAllowed && MicroOrdersAllowed == FALSE)) Comment("YOUR LOTS SIZE IS TOO SMALL TO PLACE!");

if (Lots > 0.0) for (int l_count_32 = 0; l_count_32 < NumberOfOrders; l_count_32++) OrderSend(Symbol(), l_cmd_12, Lots, Entry, 2, l_price_16, l_price_24, Comments, 0, 0, Red);

return (0);

}

They should now automatically work on any broker!

 

Thanks everyone. I'll test it out and let you know how it works out. It turns out that I was able to get the original script working on another 5 digit broker, but not FXCM. Thanks again.

 

Hi,

So, it seems like my original script works with my broker, just not with FXCM. The revised script does not require me to add an extra zero for the tp/sl settings but the calculations are off by a decimal to the right.

Since finding out that the original script will work with my particular 5 digit broker, I'm a happy camper. I also know it will work with FXDD. If you guys want to develop it further to allow to it be compatible with all brokers, feel free. It's a great tool which allows quick calculations and order entry.

Thanks again for all your efforts.

stimuls:
Thanks everyone. I'll test it out and let you know how it works out. It turns out that I was able to get the original script working on another 5 digit broker, but not FXCM. Thanks again.
 

just my small piece of comment (rather than the whole re-work)

---- ooh, if there is a willingly helpful PROGRAM coding experts help you --- my suggestion is you try the program , if it seems to work fine

2 weeks later, you could PM the programmers what he want and maybe send a present to his friends destinated address -- lot of reliable site for you to purchase Something -- to show your gratitude --

if (UseActualSlTp) {

StopLoss = (StopLossPrice - Entry) / Point;

l_price_16 = StopLossPrice;

l_price_24 = TakeProfitPrice;

}

.....

f (Lots > 0.0) for (int l_count_32 = 0; l_count_32 < NumberOfOrders; l_count_32++) OrderSend(Symbol(), l_cmd_12, Lots, Entry, 2, l_price_16, l_price_24, Comments, 0, 0, LimeGreen);

in your concept , does MM mean what this formulae state

to many people MM mean different thing, it took everyone a while -- to find HIS/ HER definition

i.e. installed MM, you should understand what is your ideaology of MM-- if you have some statistic background, it helps too

oooh, will leave the code for real helper to take a look

 
stimuls:
Hi, So, it seems like my original script works with my broker, just not with FXCM.

Ah, in this case it might be the ECN-like problem, where you can't open trade with SL/TP attached. EA/script have to open trade without TP/SL, then modify the order by attaching TP/SL to it. It is quite common, FXCM and a number of other brokers have such requirement.

Autodetecting 5 digits to avoid unnecessary 0 in the parameters, is another story of course, and I think you get it solved already..

 

this is jealousy -- huh ?? chinese whisper , we don't like their expertise in LOG

cool , your Expert Advisor getting you through already -- and we got about 5 advertiser sponsors here and about 30 good proactive programmers here

(oops copy the wrong thing -- jealousy thing is just meant for another teacher forum)

how to trade -- you guys use MM that is very highly sophistication EA -- but don't use it to learn , EA is not freebie study period

and I use TF --- and I am ready to gain +300 or -200 everyday, that is about right

and our top notch team is working on this (as attached dig)

you can PM your favorite programmer -- and we have a follower and reputable list here

-- so if you are new to our forum -- don't bother to PM the reputable ones-- busy --

as we could have 40 to 80 USD easily , if we PM the newbies

Reason: