ATR Trailer - Forex Forum - EarnForex
Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader Expert Advisors

MetaTrader Expert Advisors Post and discuss the MetaTrader expert advisors here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 20th October 2011, 07:05
Default Avatar
Junior Member
 
Join Date: Oct 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy ATR Trailer


Hi my ea on ATR trailer is not placing any order. please sole the problem. find attachment.
Attached Files
File Type: txt ATR EA.txt (5.3 KB, 29 views)
Reply With Quote
  #2 (permalink)  
Old 20th October 2011, 07:53
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 2,083
Thanks: 71
Thanked 109 Times in 66 Posts
Default

There's no point in attaching the EA's code (especially in a text file) here.

What version do you use - MT4 or MT5?
What settings do you use?
Does the smiling face appear in the top-right corner of the chart when you attach it?
Are there any errors in the Experts or Journal tabs of your terminal?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #3 (permalink)  
Old 20th October 2011, 08:06
Default Avatar
Junior Member
 
Join Date: Oct 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Post ea atr trailer is unable to place order

  • I am using MT4(demo account). I am attaching this EA with EURUSD, M1 with
  • ATR Period=10, Multiplier = 3.75,
  • Yes the smiling face is coming on chart top right corner.
  • No I am not getting any kind of error on both tab .
  • When I am testing it using strategy tester it showing me the result, but its not trading.

Please find the attachment of ea with my previous thread.
Reply With Quote
  #4 (permalink)  
Old 20th October 2011, 08:16
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 2,083
Thanks: 71
Thanked 109 Times in 66 Posts
Default

Did you make any other changes to the EA except for changing Multiplier type from int to double?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #5 (permalink)  
Old 20th October 2011, 08:20
Default Avatar
Junior Member
 
Join Date: Oct 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

MQL4 Code:
//+------------------------------------------------------------------+
//|                                                  ATR-Trailer.mq4 |
//|                                                    Andriy Moraru |
//|                                         [url]http://www.earnforex.com[/url] |
//|                                                                 2011 |
//+------------------------------------------------------------------+
#property copyright "www.EarnForex.com, 2011"
#property link      "http://www.earnforex.com"

// Plain trailing stop EA with ATR-based stop-loss.

#define LONG 1
#define SHORT 2

extern int ATR_Period = 10;
extern double ATR_Multiplier = 3.75;
extern int StartWith = 1; // 1 - Short, 2 - Long
extern int Slippage = 100;  // Tolerated slippage in pips
extern double Lots = 0.1;
   
extern int Magic = 123123123;

// Global variables
bool HaveLongPosition;
bool HaveShortPosition;
double StopLevel;
int LastPosition = 0;

int init()
{
   StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
   LastPosition = 3 - StartWith;
   return(0);
}

//+------------------------------------------------------------------+
//| Expert Every Tick Function                                       |
//+------------------------------------------------------------------+
int start()
{
    if (IsTradeAllowed() == false) return;
   
   // Getting the ATR values
   double ATR = iATR(NULL, 0, ATR_Period, 0);
   ATR *= ATR_Multiplier;

   if (ATR <= (MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD)) * Point) ATR = (MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD)) * Point;

    // Check what position is currently open
    GetPositionStates();
   
    // Adjust SL and TP of the current position
    if ((HaveLongPosition) || (HaveShortPosition)) AdjustSLTP(ATR);
   else
    {
    // Buy condition
    if (LastPosition == SHORT)
    {
            for (int i = 0; i < 10; i++)
            {
               RefreshRates();
                // Bid and Ask are swapped to preserve the probabilities and decrease/increase profit/loss size
             double SL = Bid - ATR;//NormalizeDouble(Bid - ATR, Digits);
             if (SL < StopLevel) SL = StopLevel;
                int result = OrderSend(Symbol(), OP_BUY, Lots, Ask, 100, SL,0, "ATR-Trader", Magic,0,Blue);
                Sleep(1000);
            if (result == -1)
            {
               int e = GetLastError();
               Print(e);
            }
           
                else return(0);
            }
    }
    // Sell condition
    else if (LastPosition == LONG)
    {
            for (i = 0; i < 10; i++)
            {
               RefreshRates();
                // Bid and Ask are swapped to preserve the probabilities and decrease/increase profit/loss size
              SL = Ask + ATR;//NormalizeDouble(Ask + ATR, Digits);
              if (SL < StopLevel) SL = StopLevel;
                result = OrderSend(Symbol(), OP_SELL, Lots, Bid, 100, SL, 0, "ATR-Trader", Magic,0,Red);
                Sleep(1000);
            if (result == -1)
            {
               e = GetLastError();
               Print(e);
            }
           
                else return(0);
            }
           
    }
     Print(MarketInfo(Symbol(), MODE_STOPLEVEL));
    }
   
    return(0);
}

//+------------------------------------------------------------------+
//| Check What Position is Currently Open                                       |
//+------------------------------------------------------------------+
void GetPositionStates()
{
   int total = OrdersTotal();
   for (int cnt = 0; cnt < total; cnt++)
   {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) == false) continue;
      if (OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() != Symbol()) continue;

      if (OrderType() == OP_BUY)
      {
            HaveLongPosition = true;
            HaveShortPosition = false;
        }
      else if (OrderType() == OP_SELL)
      {
            HaveLongPosition = false;
            HaveShortPosition = true;
        }
    if (HaveLongPosition) LastPosition = LONG;
    else if (HaveShortPosition) LastPosition = SHORT;
    return;
    }

   HaveLongPosition = false;
    HaveShortPosition = false;
}

//+------------------------------------------------------------------+
//| Adjust Stop-Loss and TakeProfit of the Open Position                    |
//+------------------------------------------------------------------+
void AdjustSLTP(double SLparam)
{
   int total = OrdersTotal();
   for (int cnt = 0; cnt < total; cnt++)
   {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) == false) continue;
      if (OrderMagicNumber() != Magic) continue;
      if (OrderSymbol() != Symbol()) continue;

      if (OrderType() == OP_BUY)
        {
           RefreshRates();
            double SL =Bid - SLparam;
            if (SL < StopLevel) SL = StopLevel;
            if (SL > OrderStopLoss())
            {
                for (int i = 0; i < 10; i++)
                {
               bool result = OrderModify(OrderTicket(), OrderOpenPrice(), SL, 0, 0);
               if (result) return;
                }
            }
        }
      else if (OrderType() == OP_SELL)
        {
           RefreshRates();
            SL = Ask + SLparam;
             if (SL < StopLevel) SL = StopLevel;
            if (SL < OrderStopLoss())
            {
                for (i = 0; i < 10; i++)
                {
               result = OrderModify(OrderTicket(), OrderOpenPrice(), SL, 0, 0);
               if (result) return;
                }
            }
        }
    }
}
//+------------------------------------------------------------------+

this is my complete EA ...
pleas check this
Reply With Quote
  #6 (permalink)  
Old 20th October 2011, 09:04
Default Avatar
Junior Member
 
Join Date: Oct 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Its very Important EA for me. So please sir try to solve it out.. Waiting for your reply..
Reply With Quote
  #7 (permalink)  
Old 20th October 2011, 13:08
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 2,083
Thanks: 71
Thanked 109 Times in 66 Posts
Default

Please use attachments to attach long files. If not attachment, then at least use code highlighting.

I've asked what changes have you done to the original EA (that can be found here)? I have no time for searching for your changes myself.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #8 (permalink)  
Old 21st October 2011, 04:23
Default Avatar
Junior Member
 
Join Date: Oct 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Changes made by me to the original EA are:

1. ATR period has changed from int to double .
2. double SL = Bid - ATR; instead of NormalizeDouble(Bid - ATR, Digits);//in Buy Condition.
3. SL = Ask + ATR; instead of NormalizeDouble(Ask + ATR, Digits);//in sell condition.
4. result = OrderSend(Symbol(), OP_SELL, Lots, Bid, 100, SL, 0, "ATR-Trader", Magic,0,Red);
instead of
result = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, SL, 0, "ATR-Trader", Magic);
5. In AdjustSLTP() function I have change
double SL = NormalizeDouble(Bid - SLparam, Digits);
to
double SL =Bid - SLparam;// for buy
SL = Ask + SLparam;// for sell
6. and lastly If condition used before OrderModify changes made is
if (SL < OrderStopLoss()) instead of if (SL < NormalizeDouble(OrderStopLoss(), Digits))

Thanks in advance.
Reply With Quote
  #9 (permalink)  
Old 21st October 2011, 19:49
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 2,083
Thanks: 71
Thanked 109 Times in 66 Posts
Default

Heh... You forgot to mention two important things:

1. Your EA gives OrderSend Error 130.
2. Very important changes of yours:

MQL4 Code:
StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);

and

MQL4 Code:
if (SL < StopLevel) SL = StopLevel;

The first piece of code sets StopLevel to something like 30 (at least with my broker), because you forget to multiply it with Point.

The second piece compares the valid stop-loss of about 1.3xxx with 30. Of course 30 is greater than the valid stop-loss and SL becomes = 30.

I think you know how to fix that now .
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #10 (permalink)  
Old 13th November 2011, 12:17
Default Avatar
nix nix is offline
Junior Member
 
Join Date: Oct 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi guys, i new using atr trailer. cud anyone add in a TP at 60 pips in the ea, much appreciated , cheers
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:20.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Inactive Reminders By Icora Web Design

SEO by vBSEO 3.3.2