0
Views
0
Downloads
0
Favorites
SAMPLE
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| SAMPLE.mq4 |
//| Copyright © 2005, tageiger aka fxid10t@yahoo.com |
//| http://www.metatrader.org |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, tageiger aka fxid10t@yahoo.com"
#property link "http://www.metatrader.org"
extern double MaximumRisk =0.02; //%account balance to risk per position
extern double DecreaseFactor =3; //lot size divisor(reducer) during loss streak
extern double Lot.Margin =50; //Margin for 1 lot
int init(){return(0);}
int deinit(){return(0);}
int start(){
return(0);}
//+---------------------------FUNCTIONS------------------------------+
double LotsOptimized() {
double lot;
int orders=HistoryTotal();
int losses=0;
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/Lot.Margin,2);
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,2); }
if(lot<0.01) lot=0.01;
return(lot); }//end LotsOptimized
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---