You didn't post a topic yet. Let us show you how to make your first topic and upload your favorite forex robot. Guide me

Skip to forum content

The latest topics with attached files (Forex robots, Forex Indicators, etc..)


Forums in this category with details of Replies, Views, last post

Yellow Free EA

by t76ahmed

FOREX BONUS! >> Get $3500 STARTUP No Deposit Bonus!  

Don't need to deposit! With $3500 bonus you will be able to estimate our unsurpassed quality of order execution in real trading conditions with no risk and no personal investments


Best Forex VPS! - Virtual Servers for Forex Trading!

Instant provisioning of VPS Forex service after your payment is received! Locations: AMSTERDAM (Netherland), NEW YORK (USA), LONDON (United Kingdom)


[ Closed ]

Login with Facebook Username:  Password:  Login  |  Register

Download over 10,000 FREE Forex Robots!

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 3
Please rate this topic
Current rating: 0
Votes: 0

Embed topic to your site

ATR Trailing Stop.mq4 EA Source Code!

Topic: ATR Trailing Stop.mq4 EA Source Code!

ATR Trailing Stop.mq4 EA Source Code!

//|                                            ATR Trailing Stop.mq4 |
//|                                                                  |
//|                                                                   |
#property  copyright "Copyright Team Aphid"
#property  link      ""
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red

//---- indicator parameters
extern int BackPeriod   = 1000;
extern int ATRPeriod   = 3;
extern double Factor = 3;
extern bool TypicalPrice = false;

//---- indicator buffers
double     ind_buffer1[];
double     ind_buffer2[];

//| Custom indicator initialization function                         |
int init()
//---- drawing settings  

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ATR Trailing Stop("+ATRPeriod+" * "+Factor+")");
//---- initialization done
//| Moving Averages Convergence/Divergence                           |
int start()
   int limit;
   int counted_bars=IndicatorCounted();
   double PrevUp, PrevDn;
   double CurrUp, CurrDn;
   double PriceLvl;
   double LvlUp = 0;
   double LvlDn = 1000;
   int Dir = 1;
   int InitDir;
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
//---- fill in buffervalues
   InitDir = 0;
   for(int i=BackPeriod; i>=0; i--)
      if (TypicalPrice) PriceLvl = (High[i] + Low[i] + Close[i])/3;
      else PriceLvl = Close[i];  

      if(InitDir == 0) {
         CurrUp=Close[i] - (iATR(NULL,0,ATRPeriod,i) * Factor);
         PrevUp=Close[i-1] - (iATR(NULL,0,ATRPeriod,i-1) * Factor);
         CurrDn=Close[i] + (iATR(NULL,0,ATRPeriod,i) * Factor);
         PrevDn=Close[i-1] + (iATR(NULL,0,ATRPeriod,i-1) * Factor);
         if (CurrUp > PrevUp) Dir = 1;
         LvlUp = CurrUp;
         if (CurrDn < PrevDn) Dir = -1;
         LvlDn = CurrDn;
         InitDir = 1;
      CurrUp=PriceLvl - (iATR(NULL,0,ATRPeriod,i) * Factor);
      CurrDn=PriceLvl + (iATR(NULL,0,ATRPeriod,i) * Factor);

      if (Dir == 1) {
         if (CurrUp > LvlUp) {
            ind_buffer1[i] = CurrUp;
            LvlUp = CurrUp;
         else {
            ind_buffer1[i] = LvlUp;
         ind_buffer2[i] = EMPTY_VALUE;
         if (Low[i] < ind_buffer1[i]) {
            Dir = -1;
            LvlDn = 1000;
      if (Dir == -1) {
         if (CurrDn < LvlDn) {
            ind_buffer2[i] = CurrDn;
            LvlDn = CurrDn;
         else {
            ind_buffer2[i] = LvlDn;
         ind_buffer1[i] = EMPTY_VALUE;
         if (High[i] > ind_buffer2[i]) {
            Dir = 1;
            LvlUp = 0;

//---- done


Re: ATR Trailing Stop.mq4 EA Source Code!

Dear Admin,

Thank you, this trailing stop can it be use with an other EA ?

Second question : This code it be adding to an existing EA code ?

Thank you for your answer



Download profitable Forex robots with the MT4talk Chrome Extension! Install Now 

3 (edited by sonychen59 08-11-15 07:48:53)

Re: ATR Trailing Stop.mq4 EA Source Code!

ATR = Average True Range

Developed by J. Welles Wilder, the Average True Range (ATR) is an indicator that measures volatility. As with most of his indicators, Wilder designed ATR with commodities and daily prices in mind. Commodities are frequently more volatile than stocks. They were are often subject to gaps and limit moves, which occur when a commodity opens up or down its maximum allowed move for the session. A volatility formula based only on the high-low range would fail to capture volatility from gap or limit moves. Wilder created Average True Range to capture this “missing” volatility. It is important to remember that ATR does not provide an indication of price direction, just volatility.

Wilder features ATR in his 1978 book, New Concepts in Technical Trading Systems. This book also includes the Parabolic SAR, RSI and the Directional Movement Concept (ADX). Despite being developed before the computer age, Wilder's indicators have stood the test of time and remain extremely popular.


Posts: 3

Pages 1

You must login or register to post a reply

Download profitable Forex robots with the MT4talk Chrome Extension! Install Now 

NOTE: Cracks or other illegal versions of copyrighted forex robots are highly prohibited on If you upload any illegal version of any copyrighted forex robot, your forum account will be banned. No exceptions.

Forum statistics

  • Total number of registered users: 14,720
  • Newest registered user: Ferenic Skate Sikhitha
  • Total number of topics: 10,465
  • Total number of posts: 35,364

Copyright Forum Rules - Privacy Policy.