Orders Execution
It automatically opens orders when conditions are reached
Miscellaneous
It opens Message Boxes to the user
0 Views
0 Downloads
0 Favorites
mm_sell

#include <stdlib.mqh>
#include <WinUser32.mqh>

//+------------------------------------------------------------------+
//| GLOBAL VARIABLES                                                 |
//+------------------------------------------------------------------+

int Risk = 10;                // Percent of acount to risk in percents
int TakeProfit = 10;          // Take Profit in Pips
int StopLoss   = 95;          // 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;

//+------------------------------------------------------------------+
//| Don't modify below this line !!!                                 |
//+------------------------------------------------------------------+

int start()
{

   double Lots = AutoLots(Risk,StopLoss,MinimumLotSize,MaximumLotSize);

   if(AskForConfirmation)
   {
      if(MessageBox("SELL "+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 = Ask+(StopLoss*Point)-spread;
   TP = Ask-(TakeProfit*Point)-spread;
      
   int ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,"Manual Sell",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 supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---