0
Views
0
Downloads
0
Favorites
MM
//+------------------------------------------------------------------+
//| MM.mq4 |
//| Copyright 2015, mrak297 |
//| http://www.mql5.com/ru/users/mrak297 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, mrak297."
#property link "http://www.mql5.com/ru/users/mrak297"
#property description "Ðàñ÷¸ò ðàçìåðà ëîòà."
#property version "1.00"
#property strict
input double Risk = 15.0;
input color LabelColor = clrSilver; //Color
input int FontSize = 10;
input ENUM_BASE_CORNER CORNER = CORNER_LEFT_LOWER;
double Lots = 0.01;
ENUM_ANCHOR_POINT ANCHOR = ANCHOR_LEFT_LOWER;
//+------------------------------------------------------------------+
int OnInit()
{
if (CORNER == CORNER_LEFT_LOWER) ANCHOR = ANCHOR_LEFT_LOWER;
else if (CORNER == CORNER_LEFT_UPPER) ANCHOR = ANCHOR_LEFT_UPPER;
else if (CORNER == CORNER_RIGHT_LOWER) ANCHOR = ANCHOR_RIGHT_LOWER;
else if (CORNER == CORNER_RIGHT_UPPER) ANCHOR = ANCHOR_RIGHT_UPPER;
ObjectCreate(0, "Lot", OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, "Lot", OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, "Lot", OBJPROP_YDISTANCE, 20);
ObjectSetInteger(0, "Lot", OBJPROP_CORNER, CORNER);
ObjectSetString(0, "Lot", OBJPROP_FONT, "Arial");
ObjectSetInteger(0, "Lot", OBJPROP_FONTSIZE, FontSize);
ObjectSetInteger(0, "Lot", OBJPROP_ANCHOR, ANCHOR);
ObjectSetInteger(0, "Lot", OBJPROP_COLOR, LabelColor);
ObjectSetInteger(0, "Lot", OBJPROP_HIDDEN, true);
ObjectSetInteger(0, "Lot", OBJPROP_SELECTABLE, false);
//---
ObjectCreate(0, "Risk", OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, "Risk", OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, "Risk", OBJPROP_YDISTANCE, 40);
ObjectSetInteger(0, "Risk", OBJPROP_CORNER, CORNER);
ObjectSetString(0, "Risk", OBJPROP_FONT, "Arial");
ObjectSetInteger(0, "Risk", OBJPROP_FONTSIZE, FontSize);
ObjectSetInteger(0, "Risk", OBJPROP_ANCHOR, ANCHOR);
ObjectSetInteger(0, "Risk", OBJPROP_COLOR, LabelColor);
ObjectSetInteger(0, "Risk", OBJPROP_HIDDEN, true);
ObjectSetInteger(0, "Risk", OBJPROP_SELECTABLE, false);
//---
ObjectCreate(0, "Spread", OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, "Spread", OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, "Spread", OBJPROP_YDISTANCE, 60);
ObjectSetInteger(0, "Spread", OBJPROP_CORNER, CORNER);
ObjectSetString(0, "Spread", OBJPROP_FONT, "Arial");
ObjectSetInteger(0, "Spread", OBJPROP_FONTSIZE, FontSize);
ObjectSetInteger(0, "Spread", OBJPROP_ANCHOR, ANCHOR);
ObjectSetInteger(0, "Spread", OBJPROP_COLOR, LabelColor);
ObjectSetInteger(0, "Spread", OBJPROP_HIDDEN, true);
ObjectSetInteger(0, "Spread", OBJPROP_SELECTABLE, false);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnTick()
{
double Spread = MarketInfo(Symbol(), MODE_SPREAD);
string TxtLot = "Lot = " + DoubleToString(Lots, 2);
string TxtRisk = "Risk = " + DoubleToString(Risk, 2) + "%";
string TxtSpread = "Spread = " + DoubleToString(Spread,0);
Lots = calculate_lot();
if (ObjectFind(0, "Lot") == 0 ) ObjectSetString(0, "Lot", OBJPROP_TEXT, TxtLot);
if (ObjectFind(0, "Risk") == 0 ) ObjectSetString(0, "Risk", OBJPROP_TEXT, TxtRisk);
if (ObjectFind(0, "Spread") == 0 ) ObjectSetString(0, "Spread", OBJPROP_TEXT, TxtSpread);
}
//+------------------------------------------------------------------+
double calculate_lot()
{
double Free = AccountFreeMargin();
double One_Lot = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
double Step = MarketInfo(Symbol(), MODE_LOTSTEP);
double MaxLot = MarketInfo(Symbol(), MODE_MAXLOT);
double MinLot = MarketInfo(Symbol(), MODE_MINLOT);
double result = MathFloor(Free * Risk / 100 / One_Lot / Step) * Step;
if (result > MaxLot) result = MaxLot;
else if (result < MinLot) result = MinLot;
return(result);
}
//+-------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete("Lot");
ObjectDelete("Risk");
ObjectDelete("Spread");
}
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
---