Orders Execution
Miscellaneous
0
Views
0
Downloads
0
Favorites
mm_buy
#include <stdlib.mqh>
#include <WinUser32.mqh>
int Risk = 10; // Percent of acount to risk in percents
int TakeProfit = 15; // Take Profit in Pips
int StopLoss = 65; // Stop Loss in pips
int Slippage = 3; // Slippage in pips
bool ConsiderSpread = true; // Consider spread when calculating stop loss and take profit.
double MinimumLotSize = 0.01; // Use minimum lotsize of 0.1 lots
double MaximumLotSize = 0.05; // Use maximum lotsize of 10 lots
bool AskForConfirmation = true;
int start()
{
double Lots = AutoLots(Risk,StopLoss,MinimumLotSize,MaximumLotSize);
if(AskForConfirmation)
{
if(MessageBox("BUY "+DoubleToStr(Lots,2)+" lots "+Symbol()+" Harga OK? ",
"Script Manual Entry",MB_YESNO|MB_ICONQUESTION)!=IDYES)
return(1);
}
double SL = 0;
double TP = 0;
double spread = 0;
if(ConsiderSpread)
spread = Ask-Bid;
SL = Bid-(StopLoss*Point)+spread;
TP = Bid+(TakeProfit*Point)+spread;
int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,"Manual Buy",255,0,CLR_NONE);
if(ticket<1)
{
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
return;
}
OrderPrint();
return(0);
}
double AutoLots(int Risk, int StopLossInPips, double MIN_lots = 0.01, double MAX_lots = 0.05)
{
int Decimals = 0;
double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
double LotSize = MarketInfo(Symbol(), MODE_LOTSIZE);
double LotTickValue = MarketInfo(Symbol(), MODE_TICKVALUE);
if(LotStep == 0.01)
Decimals = 2;
if(LotStep == 0.1)
Decimals = 1;
double LotsToRisk = ((AccountFreeMargin()*Risk)/100)/StopLossInPips;
double Lots = StrToDouble(DoubleToStr(LotsToRisk/LotTickValue,Decimals));
if (Lots < MIN_lots)
Lots = MIN_lots;
if (Lots > MAX_lots)
Lots = MAX_lots;
return(Lots);
}
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
---