Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
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.
See more

Reply
 
Thread Tools Display Modes
  #641 (permalink)  
Old 03-12-2009, 02:58 PM
Member
 
Join Date: Feb 2009
Posts: 86
mrwobbles is on a distinguished road
Optimising Risk percentage

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);
  }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #642 (permalink)  
Old 03-14-2009, 09:41 AM
mladen's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,270
mladen is on a distinguished road
...

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

__________________________________________________ ______________

Oh well,...
Attached Images
File Type: jpg untitled.JPG (44.6 KB, 148 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #643 (permalink)  
Old 03-14-2009, 11:51 AM
Big Joe's Avatar
Senior Member
 
Join Date: May 2006
Location: In the trading room !
Posts: 764
Big Joe is an unknown quantity at this point
Quote:
Originally Posted by mladen View Post
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

__________________________________________________ ______________

Oh well,...
That's not a good news. For those who are happy with mt4 and their indicators.

I hope they will do a converter or something like this. Could you imagine the number of indicators in mql4 ? This incompatility is incomprehensible.

I think the work of developpers is to make their new program compatible with old ones, but apparently russians are different ...
__________________
Picasso is the best !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #644 (permalink)  
Old 03-16-2009, 07:47 PM
Junior Member
 
Join Date: Mar 2009
Posts: 6
luca1982 is on a distinguished road
Help please with programmation of Trading System

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: @
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #645 (permalink)  
Old 03-20-2009, 05:25 PM
quest's Avatar
Junior Member
 
Join Date: Sep 2008
Posts: 23
quest is on a distinguished road
Script MAE and MFE

Hello

I download script MAE-MFE. I compile and fail-error.
link A Script to Calculate MAE and MFE - A Script to Calculate MAE and MFE - MQL4 Code Base

Do you tell me what's wrong?

thank you very much
Attached Files
File Type: mqh MAE_MFE_DrawDowns.mqh (32.7 KB, 23 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #646 (permalink)  
Old 03-20-2009, 07:07 PM
SPACECHIMP's Avatar
Member
 
Join Date: Feb 2006
Location: West Michigan, USA.
Posts: 86
SPACECHIMP is on a distinguished road
Example for coding opening and closing orders..

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #647 (permalink)  
Old 03-21-2009, 12:21 AM
Junior Member
 
Join Date: Mar 2009
Posts: 1
germanslobo is on a distinguished road
Al fin!!Encontre un sitio para aprender de MQL4. Thanks.

Quote:
Originally Posted by rbowles View Post
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.

Thanks in advance

Randy
Gracias

Gracias por todo, al fin!!!!!!!!!!!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #648 (permalink)  
Old 03-21-2009, 11:43 AM
Junior Member
 
Join Date: Aug 2008
Posts: 2
remote is on a distinguished road
Prevent big loses

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #649 (permalink)  
Old 03-21-2009, 02:25 PM
Senior Member
 
Join Date: Oct 2007
Posts: 117
mudar is on a distinguished road
Money Management
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #650 (permalink)  
Old 03-21-2009, 08:15 PM
Junior Member
 
Join Date: Aug 2008
Posts: 2
remote is on a distinguished road
Money Management

In a scalp system the money manegement is more dificult, right?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
automated close order, close, eas, forex, learn mql4, learn mql4 video, learning mql4, mini std lotsize risk, mql4 ima, mql4 learning, mql4 video, OrderCloseBy, profit, reach, secure profit function, T101_v1.11_orest_IBFXm.mq4


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning Cycles For New Traders Dan7974 General Discussion 350 01-18-2008 07:04 PM
Learning to code for autotrading GoatT MetaTrader 8 01-10-2007 09:55 PM
Self learning expert mrtools Expert Advisors - Metatrader 4 32 10-22-2006 06:29 PM


All times are GMT. The time now is 02:31 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.