Use ATR as stop loss?

 

I'm currrently build an auto trade system and kinda stuck here. All I want is just to get the ATR value at bid price and use this value * 2 as my stop loss. Any input? Sorry for bad script, I just started to get to know mql5 for a few days.


      double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK),_Digits);
      
      //Appropriate SL/TP 
      double SL = 0;
      double TP = 0;
      if()
      {
         
      }
          
      
      if (OpenPos() < MaxTradesAllowed && Equity >= Balance && ATRValue<0.0018)
         {  Tradable = true;
            //if(Equity >= Balance) {Tradable = true;}
            if(FastMA > SlowMA && ATRValue > 0.0008)
            {
               trade.Buy(0.01, NULL, Ask, (Ask-90*_Point), (Ask+75*_Point), 0);
            }
            if(FastMA < SlowMA && ATRValue < 0.0006)
            {
               trade.Sell(0.01, NULL, Ask, (Ask-00*_Point), (Ask+75*_Point), 0);
            }
            if(FastMA < SlowMA && ATRValue > 0.0008)
            {
               trade.Sell(0.01, NULL, Ask, (Ask-90*_Point), (Ask+75*_Point), 0);
            }
            if(FastMA > SlowMA && ATRValue < 0.0006)
            {
               trade.Sell(0.01, NULL, Ask, (Ask-90*_Point), (Ask+75*_Point), 0);
            }
            
         }
 
chaungo: I want is just to get the ATR value at bid price and use this value * 2 as my stop loss.
  1. There is no ATR at bid. There is just the ATR.
  2. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help
              urgent help.

  3. trade.Buy(0.01, NULL, Ask, (Ask-90*_Point), (Ask+75*_Point), 0);
    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)
 
chaungo:

I'm currrently build an auto trade system and kinda stuck here. All I want is just to get the ATR value at bid price and use this value * 2 as my stop loss. Any input? Sorry for bad script, I just started to get to know mql5 for a few days.


extern double atrSL = 2.0;//Atr stop/take multiplier
//--
int StopLoss,TakeProfit;
//--
double atr = iATR(NULL, 0, 3, 0);
StopLoss = (int)(atr * atrSL / Point);
//--
TakeProfit = StopLoss;

quick example using ATR to calculate Stop loss and Take profit, not tested!

Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...