Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader Expert Advisors

MetaTrader Expert Advisors Post and discuss the MetaTrader expert advisors here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 20th March 2011, 07:34
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default decrease factor's algorithm

dear gurus:I am an newbie in MQL4,just find an method of cut positions when lossing, the code as follows:
extern double DecreaseFactor = 10;
int losses=0;
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==fals e) { 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);
}
however,I use it to backtrack,the results disorient me.
the follow are some trade log:
type order no size price profit balance
buy 1 2.00 1.3345 0.00 50000.00
close 1 2.00 1.3272 -1555.74 48444.26
sell 2 1.90 1.3297 0.00 48444.26
close 2 1.90 1.3361 -1292.00 47152.26
buy 3 1.50 1.3354 0.00 47152.26
close 3 1.50 1.3315 -656.81 46495.45
sell 4 1.30 1.3306 0.00 46495.45
close 4 1.30 1.2956 4436.60 50932.05

the question is :
2 is the default size in my EA,but what the "lot" stands for in the equation, 2 or the latest size?
why the order 4's size becomes 1.30?

PLs gurus show arithmetic process,TKS!
Reply With Quote
  #2 (permalink)  
Old 20th March 2011, 09:02
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

If that's the same EA that you've listed here, then your Lot size depends not only on this equation with the decrease factor but also on the amount of free margin available:
lot=NormalizeDouble(AccountFreeMargin()*MaximumRis k/100.0,1);

But it still doesn't make much sense... Care to attach this EA .mq4 file with all the input parameters you are using?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #3 (permalink)  
Old 24th March 2011, 09:16
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
If that's the same EA that you've listed here, then your Lot size depends not only on this equation with the decrease factor but also on the amount of free margin available:
lot=NormalizeDouble(AccountFreeMargin()*MaximumRis k/100.0,1);

But it still doesn't make much sense... Care to attach this EA .mq4 file with all the input parameters you are using?
it's the same equation,that just because I wanna when ordeprofit>0,the next order's positon should largen,when lossing the position should reduction.
however,some guys say the "losses" in the equation
"if (OrderProfit()<0) losses++;"
stands lossing amount of loss,others say it is the lossing order's N.O.
this is why I ask losses stands what,and in my log why the order 4's position is 1.3 pls gurus help me.
Reply With Quote
  #4 (permalink)  
Old 24th March 2011, 12:35
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

Please attach the whole EA (.mq4 file) if you want to get a definite answer.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #5 (permalink)  
Old 25th March 2011, 09:00
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
Please attach the whole EA (.mq4 file) if you want to get a definite answer.
I have attached the modifycc.mq4 in here
profitable ea couldn't increase position pls gurus point out method.
just the same file. TKS!
Reply With Quote
  #6 (permalink)  
Old 25th March 2011, 09:18
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

In the file attached there, DecreaseFactor = 3, not 10. So, what is it? And the starting balance is 5000, right?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #7 (permalink)  
Old 26th March 2011, 12:14
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
In the file attached there, DecreaseFactor = 3, not 10. So, what is it? And the starting balance is 5000, right?
the trade log is produced by DecreaseFactor=10,and the starting balance is 50,000. lot=NormalizeDouble(AccountFreeMargin()*MaximumRis k/500.0,1);

My question I have listed in 3# tks!
Reply With Quote
  #8 (permalink)  
Old 26th March 2011, 20:55
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

The it's all correct. The cycle inside LotsOptimized() calculates the number of losing orders met in a row. Initially we have 50,000 free margin and DecreaseFactor = 10:

1. lot = 50000 * 0.02 / 500 = 2
since losses <= 1, we don't do anything else.
2. lot = 48444.26 * 0.02 / 500 = 1.93 = 1.9 after normalizing
since losses <= 1, we don't do anything else.
3. lot = 47152.26 * 0.02 / 500 = 1.88 = 1.9 after normalizing
losses > 1, lot = 1.9 - 1.9 * 2 / 10 = 1.52 = 1.5 after normalizing
4. lot = 46495.45 * 0.02 / 500 = 1,85 = 1,9 after normalizing
losses > 1, lot = 1.9 - 1.9 * 3 / 10 = 1,33 = 1,3 after normalizing
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #9 (permalink)  
Old 27th March 2011, 10:28
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you for your help to show the cycle correctly,but now when I backtracking EURUSD on 01.01.2011-03.26.2011 M5 the starting balance is 50,000 by add.mq4,it produce some results amazing me again.
I modified the decrease factor=3,and
if(losses>=1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);

my question is why the third order's lot is 2?
I think it should count like this,
lot=50180*0.02/500=2,
since losses=1,lot=2-2*1/3=1.34=1.3 after normalizing
confused:
Attached Files
File Type: mq4 add.mq4 (5.5 KB, 11 views)
File Type: htm add.htm (49.4 KB, 17 views)
Reply With Quote
  #10 (permalink)  
Old 27th March 2011, 12:18
Default Avatar
Junior Member
 
Join Date: Mar 2011
Location: china
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

unconsciously, I found just the model will affect order's lots.
using the add.mq4,all other factors are same,(eurusd, m5 ,01.01.2011-26.03.2011)but under each tick model, the log's 77-78 line will get as the attachment.(lot is 2.1)
gurus can contrast the openprice model 's report I attached in the 9#(77-78line the order's lot is 1.0),I am appeciating for explain this.add another question:when living trading,it will follow which model?each tick or open price and other?
I have this equation code
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
I think it would limit only openprice model taking effect.
but why the demo backtracketing test have differernt result under differernt model?
I am an newbie,so don't laugh at me.confused:
Attached Images
File Type: jpg eachtickmodel.jpg (5.4 KB, 4 views)

Last edited by univetsity; 27th March 2011 at 14:10.
Reply With Quote
Reply

Bookmarks


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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Genetic Algorithm for EA, how? lumanauw MetaTrader Expert Advisors 5 30th June 2011 07:51
MDT's Daily Forex Analysis and FX-Market Algorithm mdtforex Advertisements 12 11th March 2009 07:45


All times are GMT. The time now is 02:43.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Inactive Reminders By Icora Web Design

SEO by vBSEO 3.3.2