stoplosscalc

Author: Copyright 2016, MetaQuotes Software Corp.
Indicators Used
Indicator of the average true range
0 Views
0 Downloads
0 Favorites
stoplosscalc
//+------------------------------------------------------------------+
//|                                                 StopLossCalc.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property library
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

input    int      StopLoss = 0;
input string        ATRexp = "this function to calculate stoploss depend on iATR";
input   bool           ATR = false;
input    int ATRMultiplier = 3;
//+------------------------------------------------------------------+
//| StopLoss Calculations                                            |
//+------------------------------------------------------------------+
double StpLoss(int i)
  {
   double SL=0;
   if(StopLoss==0 && !ATR) SL=0;
   else if(StopLoss>0 && !ATR)
     {
      double MyPoint=Point;
      if(Digits==3 || Digits==5) MyPoint=Point*10;
      if(i==0) SL=Ask-(StopLoss*MyPoint);
      if(i==1) SL=Bid+(StopLoss*MyPoint);
     }
   else if(ATR)
     {
      double AvTR=iATR(Symbol(),30,14,0);
      if(i==0) SL=Ask-(ATRMultiplier*AvTR);
      if(i==1) SL=Bid+(ATRMultiplier*AvTR);
     }
   return(SL);
  }
//+------------------------------------------------------------------+
// for market excuting orders Buy(i=0)-->(StpLoss(0)) / Sell(i=1)-->(StpLoss(1))
// OR for OrderModify() you can put StopLoss= StpLoss(OrderType())

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 ---