Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. Its absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
Right I'm just starting to code money management for my EA and I've come across the standard LotsOptimized() function that chooses the appropriate lot size for a certain maximum risk percentage. Now thats all well and good and it makes sure the lot size is correct and maximises profit quite nicely. However I wanted to vary my risk percentage based on my short term win percentage (last 20 trades say). Now I've come up with this formula that plots a nice curve increasing as my short-term win ratio increases.
Maximum Risk %= (2/300)*(1/(1-STWP))
Where STWP is the short term win ratio. I'm sure you're all thinking what happens in the rare occassion that you get 20 straight successive trades (STWP=1 division by 0)? Well I modified it so that if STWP>0.85 then MaxRisk%=0.05 otherwise it risks over 13% of your equity. Anyone use this or similar approaches to increase your risk when on a winning streak? Here's my code so far, any thoughts? It should hopefully have a built in decrease factor thou it would be easy to say half MaxRisk after your first loss.
Code:
double KellyLot()
{
double lot=Lots;
double orders=HistoryTotal();
double STW=1;
double STWP=0;
if(orders>20)
{
int i,j;
for(i=orders;i>=(orders-20);i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderProfit()>0) STW=STW+1;
}
STWP=STW/20;
if(STWP==1) {STWP=0.995;} //Prevents division by 0
double KRC=(2/300)*(1/(1-STWP));
if(KRC>=0.05) MaximumRisk=0.05;
if(KRC<0) MaximumRisk=MaximumRisk;
else MaximumRisk=KRC;
}
return(MaximumRisk);
}
double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*KellyLot()/1000.0,1);
//---- calcuulate number of losses orders without a break
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
}
if(lot<0.1) lot=0.1;
return(lot);
}
Trouble usually comes in small packages ...
From official mql site and its translation (if I got something wrong, then please do correct me - original posts are here ’оп€ос по mql4 и mql5 - MQL4 „о€ƒм)
Question : Since mql5 release is closer, will it support experts and indicators from mql4?
Answer : No
Trouble usually comes in small packages ...
From official mql site and its translation (if I got something wrong, then please do correct me - original posts are here ’оп€ос по mql4 и mql5 - MQL4 „о€ƒм)
Question : Since mql5 release is closer, will it support experts and indicators from mql4?
Answer : No
Hi everyone!!!
My name's Luca, i am new of this forum.
I have a big problem...i am not able to write my trading system in metatrader because i don't know how to express mathematically the concept of divergence and the concept of maximum and minimum.
Can you help me, please? If someone wants to contact me, it is possibile to write me
Last edited by Linuxser; 03-17-2009 at 03:24 AM.
Reason: @
Not Just opening and closing but Verifying that the order has been opened or closed.
I open 2 orders at a time..one with TP and one without.
I need to make sure 1 or both get closed before opening opposite 2 orders.
I've been having random problems with 2 orders NOT getting opened or 2 of the SAME orders getting opened(both with TP).
I do use a while loop to close the orders but don't have any verification for the OPEN orders commands.
I look at the code i have and i think i'm making this Far more difficult than it needs to be. Experienced programmers will know the shortcuts.
Summary- need to open 2 separate orders and verify each one individually AND
Close ALL orders and verify all have been closed. (I'm guessing the CLOSEALL command or something)
THANKS ALOT ALL!
if you happen to know how to ADD Trailing STOP in the code for opening orders..I'd REALLY appreciate that too.
THANKS again
Last edited by SPACECHIMP; 03-20-2009 at 07:11 PM.
Al fin!!Encontre un sitio para aprender de MQL4. Thanks.
Quote:
Originally Posted by rbowles
I have been working on an EA the last few days and with the help of this forum I have made some progress. I want to know how I would print an arrow or sometime of graphic that indicates where It is getting in a trade and where it is getting out. I no how to do it for an indicator but not for an EA.
I am new to programming with MQL4 and so far I have done some testing.
In some tests I have made note that it is relatively simple to make an EA to get some regular income, the problem is that suddenly it have a big lose that cancels my earnings.
What techniques that exist to prevent large loses?