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

Hide

IMPORTANT Announcement!

WARNING: Some Brokers are Stealing Traders Money! They are doing everything to hold back your earned money! They just don't like to pay you! If you are trading with a fraudulent forex broker and winning money, most likely you will not be paid. Some of the forex brokers making thousands of excuses to be able to decline your withdrawal request. If brokers declined your withdraw request, you can create a topic and discuss with other forum users at the Do you feel you've been scammed by a Forex Broker? forum.

We have found a true Broker who actually pays! We highly recommend that you try to withdraw all your money from other brokers and Open a New Forex Account with Libertex! - We found that, Libertex is 100% safe and trustable Forex Broker with 0 spreads, leverage up to 1:500! - Libertex also offer an Affiliate Program with monthly revenue sharing percentage up to 60% or cost per action up to $800 >> Start earning money referring new clients.


Login with Facebook Username:  Password:  Login  |  Register

Registered members can download over 5000 forex robots and over 8000 forex indicators!

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

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  
   SetIndexStyle(0,DRAW_LINE,EMPTY,2);
   SetIndexDrawBegin(0,ATRPeriod);
   SetIndexBuffer(0,ind_buffer1);
   SetIndexStyle(1,DRAW_LINE,EMPTY,2);
   SetIndexDrawBegin(1,ATRPeriod);
   SetIndexBuffer(1,ind_buffer2);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ATR Trailing Stop("+ATRPeriod+" * "+Factor+")");
   SetIndexLabel(0,"Support");
   SetIndexLabel(1,"Resistance");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| 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--;
   limit=Bars-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
   return(0);

Share

 

 

 

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

Best

Share

3 (edited by sonychen59 2015-08-11 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.

Share

Posts: 3

Pages 1

You must login or register to post a reply

Last Posts

  • 20/01: EA SPARTAN BOLT
  • 20/01: You must try on demo account first do not play on real account
  • 20/01: Time and date to play forex successfully
  • 20/01: How to understand how to use the signal in playing option
  • 20/01: which successfull forex robot
  • 20/01: Successfull signal in playing option
  • 20/01: Playing forex successfully by using robot
  • 20/01: Succeed in playing forex
  • 20/01: how to select forex broker?
  • 20/01: How to select option broker?
  • 20/01: Wanted to success in option?
  • 20/01: RULES OF TRADING
  • 20/01: Best martingale ea
  • 20/01: Ironfx is a total garbage. (SCAM)
  • 20/01: Hedging EA's here
  • 20/01: low latency vps
  • 20/01: AutoProfit set
  • 19/01: ASSAR v8
  • 19/01: 2000 pips daily
  • 19/01: Super Signal Scalping Profit Statement
  • Hot Topics

  • Profitable Scalper EA Free download!! (598)
  • Scalper_v5 (free) (534)
  • A highly profitable Ea (347)
  • spartan bolt V6 (319)
  • ASSAR v8 (297)
  • Assar_03_EA (296)
  • 2000 pips daily (286)
  • Trade-Arbitrage EA (192)
  • Fap Turbo Expert Advisor is now absolutely free! (174)
  • forex hacked pro (166)
  • Forex Earth Robot (157)
  • xmt scalper (151)
  • Rabbit3 £100 start Zero to Hero Updated EA (139)
  • Forex Math EA free for Mt4 (133)
  • Fracture 7.4.0 (132)
  • high profit EA (130)
  • EA SmartAssTrade. (128)
  • New to forex? (127)
  • Super Signal Scalping Profit Statement (126)
  • Ilan Expert Advisor for Metatrader 4 (120)
  • Popular Topics

  • Profitable Scalper EA Free download!! (47762)
  • Scalper_v5 (free) (20978)
  • A highly profitable Ea (20685)
  • Assar_03_EA (13484)
  • ASSAR v8 (12971)
  • spartan bolt V6 (12920)
  • Trade-Arbitrage EA (11162)
  • xmt scalper (10964)
  • 2000 pips daily (10868)
  • Super Signal Scalping Profit Statement (9886)
  • Fap Turbo Expert Advisor is now absolutely free! (9842)
  • forex hacked pro (9774)
  • Forex Earth Robot (9481)
  • Forex Math EA free for Mt4 (8897)
  • Ilan Expert Advisor for Metatrader 4 (8741)
  • WayGrow EA 1.7 (8640)
  • Fracture 7.4.0 (8567)
  • Rabbit3 £100 start Zero to Hero Updated EA (8101)
  • high profit EA (7983)
  • EA SmartAssTrade. (7964)

  • Forum statistics

    • Total number of registered users: 7,845
    • Newest registered user: kongkaparn
    • Total number of topics: 14,097
    • Total number of posts: 27,954

     


    By posting a message, you automatically agree to the Forum Rules and Privacy Policy.