logo
ads
سفارش طراحی انواع اکسپرت و اندیکاتور
search

از بین هزاران مقاله ما جستجو کنید...

مجموعه آموزشی جامع فارکس

اندیکاتور های MTF

اندیکاتور های MTF
اندیکاتور های MTF

فرمت اندیکاتور : MQL5ابزار تحلیلی برای بررسی بازار #define EXPERT_MAGIC 1234502 //— #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> #include <Trade\PositionInfo.mqh> #include <Trade\AccountInfo.mqh> #include <Trade\OrderInfo.mqh> //+——————————————————————+ enum compTF   {    A, //m1-m5-m15    B, //m5-m15-h1    C, //m15-h1-h4    E  //h1-h4-d1   }; //+——————————————————————+ //|                                                                  | //+——————————————————————+ input string s0=”//— input parameters Lots+Trailing —//”; input double InpLots          =0.1; // Lots input int    InpTakeProfit    =150; […]

اندیکاتور های MTF

اندیکاتور های MTF

اندیکاتور های MTF

اندیکاتور های MTF
نمونه ای از تصویر اندیکاتور

فرمت اندیکاتور : MQL5
ابزار تحلیلی برای بررسی بازار

#define EXPERT_MAGIC 1234502
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\OrderInfo.mqh>
//+------------------------------------------------------------------+
enum compTF
  {
   A, //m1-m5-m15
   B, //m5-m15-div style="font-size:1.5rem" 
   C, //m15-div style="font-size:1.5rem" -h4
   E  //div style="font-size:1.5rem" -h4-d1
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
input string s0="//--- input parameters Lots+Trailing ---//";
input double InpLots          =0.1; // Lots
input int    InpTakeProfit    =150; // Take Profit (in pips)
input int    InpStopLoss      =60;  // StopLoss (in pips)
input int    InpLevel_S       =20;  // Level Signal
input compTF InpTFreg         =2;
input string s1="//--- input parameters MA ---//";
input int                Signal_MA_PeriodMA      =21;                             // Period of averaging
input string s2="//--- input parameters MACD ---//";
input int                Signal_MACD_PeriodFast  =12;                             // Period of fast EMA
input int                Signal_MACD_PeriodSlow  =26;                             // Period of slow EMA
input string s3="//--- input parameters Stochastic ---//";
input int                Signal_Stoch_PeriodK    =5;                              //  K-period
input int                Signal_Stoch_PeriodD    =3;                              //  D-period
input string s4="//--- input parameters Trailing ---//";
//--- inputs for trailing
input int    InpTrailingStop  =25;  // Trailing Stop Level (in pips)
input int    InpOffset        =5;   // Distance from the price (in pips)
//---
int ExtTimeOut=10; // time interval between trading operations in seconds
int barsCalculated=3;
datetime t=0;
datetime time[];
//+------------------------------------------------------------------+
//| AC Sample expert class                                           |
//+------------------------------------------------------------------+
class CSampleExpert
  {
protected:
   double            m_adjusted_point;             // 3- or 5-digit value
   CTrade            m_trade;                      // trading object
   CSymbolInfo       m_symbol;                     // symbol information
   CPositionInfo     m_position;                   // trading position
   CAccountInfo      m_account;                    // account information
   COrderInfo        m_order;                      // order information 
   //--- indicators
   ENUM_TIMEFRAMES   mas_tf[3];                   // array of timeframes
   int               handle_MACD;                 // MACD indicator handle
   int               handle_MA;                   // MA indicator handle
   int               handle_Stochastic;           // Stochastic indicator handle
   //--- indicator buffers
   double            macd_buff[];           // MACD indicator main buffer
   double            ma_buff[];             // MA indicator main buffer
   double            stoch_buff[];          // Stochastic indicator main buffer
   //---
   double            close[];
   double            open[];
   double            low[];
   double            high[];
   //--- indicator data to process
   double            macd_ind_0;
   double            macd_ind_1;
   double            ma_ind;
   double            stoch_ind_0;
   double            stoch_ind_1;
   int               level_stoch;
   //--- trailing stop data to process
   double            m_traling_stop;
   double            m_take_profit;
   double            m_stop_losse;
public:
                     CSampleExpert(void);
                    ~CSampleExpert(void);
   bool              Init(void);
   void              Deinit(void);
   bool              Processing(void);

protected:
   bool              InitCheckParameters(const int digits_adjust);
   bool              Copy(void);              // 
   bool              InitIndicators(void);
   bool              LongModified(void);
   bool              ShortModified(void);
   bool              LongOpened(void);          // check Long condition
   bool              ShortOpened(void);         // check Short condition
   bool              OpenSellStop(void);        // place the SELLSTOP order
   bool              OpenBuyStop(void);         // place the BUYSTOP order
   bool              OrderModifySellStop(void); // modify the SELLSTOP order
   bool              OrderModifyBuyStop(void);  // modify the BUYSTOP order
   bool              DellSellStop(void);        // delete the SELLSTOP order
   bool              DellBuyStop(void);         // delete the BUYSTOP order
  };
//--- global expert
CSampleExpert ExtExpert;
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CSampleExpert::CSampleExpert(void) : m_adjusted_point(0),
                                     handle_MACD(INVALID_HANDLE),
                                     handle_Stochastic(INVALID_HANDLE),
                                     handle_MA(INVALID_HANDLE),
                                     macd_ind_0(0),
                                     macd_ind_1(0),
                                     stoch_ind_0(0),
                                     stoch_ind_1(0),
                                     ma_ind(0),
                                     m_traling_stop(0),
                                     m_take_profit(0)
  {
   ArraySetAsSeries(macd_buff,true);
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CSampleExpert::~CSampleExpert(void)
  {
  }
//+------------------------------------------------------------------+
//| Initialization and verification of input parameters              |
//+------------------------------------------------------------------+
bool CSampleExpert::Init(void)
  {
//--- initializing general information
   m_symbol.Name(Symbol());                  // symbol
   m_trade.SetExpertMagicNumber(EXPERT_MAGIC); // magic
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(Symbol());
//--- tuning for 3 or 5 digits
   int digits_adjust=1;
   if(m_symbol.Digits()==3 || m_symbol.Digits()==5)
      digits_adjust=10;
   m_adjusted_point=m_symbol.Point()*digits_adjust;
//--- setting the default deviation for trading 
   m_traling_stop    =InpTrailingStop*m_adjusted_point;
   m_take_profit     =InpTakeProfit*m_adjusted_point;
   m_stop_losse      =InpStopLoss*m_adjusted_point;
//--- set default deviation for trading in adjusted points
   m_trade.SetDeviationInPoints(3*digits_adjust);
//---
   int x=InpTFreg;
   switch(x)
     {
      case 0: {mas_tf[0]=PERIOD_M1;mas_tf[1]=PERIOD_M5;mas_tf[2]=PERIOD_M15;}
      break;
      case 1: {mas_tf[0]=PERIOD_M5;mas_tf[1]=PERIOD_M15;mas_tf[2]=PERIOD_H1;}
      break;
      case 2: {mas_tf[0]=PERIOD_M15;mas_tf[1]=PERIOD_H1;mas_tf[2]=PERIOD_H4;}
      break;
      case 3: {mas_tf[0]=PERIOD_H1;mas_tf[1]=PERIOD_H4;mas_tf[2]=PERIOD_D1;}
      break;
     }
//---
   if(!InitCheckParameters(digits_adjust))
      return(false);
   if(!InitIndicators())
      return(false);
//--- result
   return(true);
  }
//+------------------------------------------------------------------+
//| Verification of input parameters                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::InitCheckParameters(const int digits_adjust)
  {
//--- checking source data
   if(InpTakeProfit*digits_adjust<m_symbol.StopsLevel())
     {
      printf("Take Profit must be greater than %d",m_symbol.StopsLevel());
      return(false);
     }
   if(InpTrailingStop*digits_adjust<m_symbol.StopsLevel())
     {
      printf("Trailing Stop must be greater than %d",m_symbol.StopsLevel());
      return(false);
     }
//--- checking the lot value
   if(InpLots<m_symbol.LotsMin() || InpLots>m_symbol.LotsMax())
     {
      printf("Lots must be in the range between %f and %f",m_symbol.LotsMin(),m_symbol.LotsMax());
      return(false);
     }
   if(MathAbs(InpLots/m_symbol.LotsStep()-MathRound(InpLots/m_symbol.LotsStep()))>1.0E-10)
     {
      printf("The amount does not correspond to the lot step %f",m_symbol.LotsStep());
      return(false);
     }
//--- warning
   if(InpTakeProfit<=InpTrailingStop)
      printf("Warning: Trailing Stop must be less than Take Profit");
//--- result
   return(true);
  }
//+------------------------------------------------------------------+
//| Initialization of indicators                                     |
//+------------------------------------------------------------------+
bool CSampleExpert::InitIndicators(void)
  {
//--- create the MACD indicator
   if(handle_MACD==INVALID_HANDLE)
     {
      //---
      handle_MACD=iCustom(NULL,0,"MTF\\Oscillators\\MTF_MACD",mas_tf[2],Signal_MACD_PeriodFast,Signal_MACD_PeriodSlow);
      //---
      if(handle_MACD==INVALID_HANDLE)
        {
         printf("Error occurred while creating MACD");
         return(false);
        }
     }
//--- create the MA indicator
   if(handle_MA==INVALID_HANDLE)
     {
      //---
      handle_MA=iCustom(NULL,0,"MTF\\Trend\\MA_MultiTF",mas_tf[2],Signal_MA_PeriodMA,0,MODE_EMA,PRICE_CLOSE);
      //---
      if(handle_MA==INVALID_HANDLE)
        {
         printf("Error occurred while creating MA");
         return(false);
        }
     }
//--- create the Stochastic indicator
   if(handle_Stochastic==INVALID_HANDLE)
     {
      //---
      handle_Stochastic=iCustom(NULL,0,"MTF\\Oscillators\\MTF_Stochastic",mas_tf[1],Signal_Stoch_PeriodK,Signal_Stoch_PeriodD);
      //---
      if(handle_Stochastic==INVALID_HANDLE)
        {
         printf("Error occurred while creating Stochastic");
         return(false);
        }
     }
//--- result
   return(true);
  }
//+------------------------------------------------------------------+
//|          Modifying the long position                             |
//+------------------------------------------------------------------+
bool CSampleExpert::LongModified(void)
  {
   bool res=false;
//--- checking the trailing stop
   if(InpTrailingStop>0)
     {
      if(m_symbol.Bid()-m_position.PriceOpen()>m_adjusted_point*InpTrailingStop)
        {
         double sl=NormalizeDouble(m_symbol.Bid()-m_traling_stop,m_symbol.Digits());
         double tp=m_position.TakeProfit();
         if(m_position.StopLoss()<sl || m_position.StopLoss()==0.0)
           {
            //--- modifying the position
            if(m_trade.PositionModify(Symbol(),sl,tp))
               printf("Long position by %s to be modified",Symbol());
            else
              {
               printf("Error modifying position by %s : '%s'",Symbol(),m_trade.ResultComment());
               printf("Modify parameters : SL=%f,TP=%f",sl,tp);
              }
            //--- was modified and must exit the Expert Advisor
            res=true;
           }
        }
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//|                    Modifying the short position                  |
//+------------------------------------------------------------------+
bool CSampleExpert::ShortModified(void)
  {
   bool   res=false;
//--- checking the trailing stop
   if(InpTrailingStop>0)
     {
      if((m_position.PriceOpen()-m_symbol.Ask())>(m_adjusted_point*InpTrailingStop))
        {
         double sl=NormalizeDouble(m_symbol.Ask()+m_traling_stop,m_symbol.Digits());
         double tp=m_position.TakeProfit();
         if(m_position.StopLoss()>sl || m_position.StopLoss()==0.0)
           {
            //--- modifying the position
            if(m_trade.PositionModify(Symbol(),sl,tp))
               printf("Short position by %s to be modified",Symbol());
            else
              {
               printf("Error modifying position by %s : '%s'",Symbol(),m_trade.ResultComment());
               printf("Modify parameters : SL=%f,TP=%f",sl,tp);
              }
            //--- was modified and must exit the Expert Advisor
            res=true;
           }
        }
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//| Checking conditions for opening a long position                  |
//+------------------------------------------------------------------+
bool CSampleExpert::LongOpened(void)
  {
   bool res=false;
   level_stoch=InpLevel_S;
//--- checking the possibility to open a long (BUY) position
   if(stoch_ind_1<level_stoch && stoch_ind_0>level_stoch && macd_ind_1>macd_ind_0 && ma_ind<close[1] && ma_ind<open[1])//&& ma_ind<close[1] && ma_ind<open[1]
     {
      //--- exit the EA
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//|         Opening a Buy Stop order                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::OpenBuyStop(void)
  {
   bool res=false;
   double tp=0,sl=0;
//---
   if(LongOpened())
     {
      res=true;
      //--- declare and initialize the trade request and result
      MqlTradeRequest request={0};
      MqlTradeResult  result={0};
      //--- pending order placing parameters
      request.action   =TRADE_ACTION_PENDING;                             // trading operation type
      request.symbol   =Symbol();                                         // symbol
      request.deviation=5;                                                // allowed deviation from the price
      request.volume   =InpLots;                                          // volume in lots
      request.magic    =EXPERT_MAGIC;                                     // order MagicNumber
      double offset=InpOffset;                                            // point distance from the current price to place the order
      double price;                                                       // order trigger price
      double point=SymbolInfoDouble(_Symbol,SYMBOL_POINT);                // point size
      int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);           // number of decimal places (digits)
      //--- operation type
      request.type=ORDER_TYPE_BUY_STOP;                                   // order type
      price=high[1]+offset*m_adjusted_point;                              // open price
      request.price=NormalizeDouble(price,digits);                        // normalized open price
      tp=price+m_take_profit;
      sl=price-m_stop_losse;
      request.sl       =NormalizeDouble(sl,_Digits);                       // add the new Stop Loss value to the structure
      request.tp       =NormalizeDouble(tp,_Digits);                       // add the new Take Profit value to the structure
      //--- sending a request
      if(!OrderSend(request,result))
        {res=false;printf("OrderSend error %d",GetLastError());}           // if unable to send the request, output the error code
      //--- information about the operation
      printf("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
      //--- exit the EA
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//| Checking conditions for opening a short position                 |
//+------------------------------------------------------------------+
bool CSampleExpert::ShortOpened(void)
  {
   bool res=false;
   level_stoch=100-InpLevel_S;
//--- checking the possibility of a short position (SELL) 
   if(stoch_ind_1>level_stoch && stoch_ind_0<level_stoch && macd_ind_1<macd_ind_0 && ma_ind>close[1] && ma_ind>open[1])
     {
      //--- exit the EA
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//|         Opening a Sell Stop order                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::OpenSellStop(void)
  {
   bool res=false;
   double tp=0,sl=0;
//---
   if(ShortOpened())
     {
      res=true;
      //--- declare and initialize the trade request and result
      MqlTradeRequest request={0};
      MqlTradeResult  result={0};
      //--- pending order placing parameters
      request.action   =TRADE_ACTION_PENDING;                             // trading operation type
      request.symbol   =Symbol();                                         // symbol
      request.deviation=5;                                                // allowed deviation from the price
      request.volume=InpLots;                                             // volume in lots
      request.magic=EXPERT_MAGIC;                                         // order MagicNumber
      int offset=InpOffset;                                                // point distance from the current price to place the order
      double price;                                                       // order trigger price
      int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);           // number of decimal places (digits)
      request.type=ORDER_TYPE_SELL_STOP;                                  // order type
      price=low[1]-offset*m_adjusted_point;                                          // open price
      request.price=NormalizeDouble(price,digits);                        // normalized open price
      tp=price-m_take_profit;
      sl=price+m_stop_losse;
      request.sl       =NormalizeDouble(sl,_Digits);                       // add the new Stop Loss value to the structure
      request.tp       =NormalizeDouble(tp,_Digits);                       // add the new Take Profit value to the structure
      //--- sending a request
      if(!OrderSend(request,result))
        {res=false;printf("OrderSend error %d",GetLastError());}     // if unable to send the request, output the error code
      //--- information about the operation
      printf("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
      //--- exit the EA
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//| The main function returns true if any of the positions           |
//| is being processed                                               |
//+------------------------------------------------------------------+
bool CSampleExpert::Processing(void)
  {
//   MqlDateTime dt;
//--- Update frequency
   if(!m_symbol.RefreshRates())
      return(false);
//--- Update indicators
   if(BarsCalculated(handle_Stochastic)<barsCalculated)
      return(false);
   if(CopyBuffer(handle_Stochastic,0,0,barsCalculated,stoch_buff)!=barsCalculated)
      return(false);
//---
   if(BarsCalculated(handle_MACD)<barsCalculated)
      return(false);
   if(CopyBuffer(handle_MACD,0,0,barsCalculated,macd_buff)!=barsCalculated)
      return(false);
//---
   if(BarsCalculated(handle_MA)<barsCalculated)
      return(false);
   if(CopyBuffer(handle_MA,0,0,barsCalculated,ma_buff)!=barsCalculated)
      return(false);
//---
   if(!Copy())return(false);
//--- to simplify programming and provide a faster access
//--- data are located in internal variables
   macd_ind_0   = macd_buff[1];
   macd_ind_1   = macd_buff[0];
   ma_ind       = ma_buff[1];
   stoch_ind_0  = stoch_buff[1];
   stoch_ind_1  = stoch_buff[0];

//--- it is important to correctly exit it ...   
//--- First check if the position exists - try to select it
   bool bord=false,sord=false;
   ulong ticket;
//+--- There are open positions and trailing stop is enabled --------+
   if(m_position.Select(Symbol()) && PositionsTotal()>0 && m_traling_stop!=0)
     {
      if(m_position.PositionType()==POSITION_TYPE_BUY)
        {
         bord=true;
         //--- modifying the long position
         if(LongModified())
            return(true);
        }
      else
        {
         sord=true;
         //--- modifying the short position
         if(ShortModified())
            return(true);
        }
     }
//+--------- trading STOP orders ------------------------------------+
// In this cycle, check all placed pending orders one by one
   for(int i=0;i<OrdersTotal();i++)
     {
      // select each of orders and getting its ticket
      ticket=OrderGetTicket(i);
      // handling Buy Stop orders
      if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)
        {
         // setting the flag indicating that there is a Buy Stop order
         bord=true;
         //--- It is important to enter the market correctly, move the order if necessary 
         if(bord)OrderModifyBuyStop(); // modify the BUYSTOP order
        }
      // handling Sell Stop orders
      if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
        {
         // setting the flag indicating that there is a Sell Stop order
         sord=true;
         //--- It is important to enter the market correctly, move the order if necessary 
         if(sord)OrderModifySellStop(); // modify the SELLSTOP order
        }
     }
//--- If there are no orders, place --------------------------------+
   if(!sord)if(OpenSellStop()){sord=true;return(true);}
   if(!bord)if(OpenBuyStop()){bord=true;return(true);}
//--- exit without position handling
   return(false);
  }
//+------------------------------------------------------------------+
//|Changing parameters of the earlier placed Sell Stop trading order |
//+------------------------------------------------------------------+
bool CSampleExpert::OrderModifySellStop(void)
  {
   bool res=true;
   ulong ticket;
   double tp=0,sl=0;
   double offset=InpOffset;                                            // point distance from the current price to place the order
   double price;                                                       // order trigger price
   int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);           // number of decimal places (digits)
                                                                       // declare and initialize the trade request and result
   MqlTradeRequest request={0};
   MqlTradeResult  result={0};
   int total=OrdersTotal(); // number of pending orders
//--- iterate over all placed pending orders
   for(int i=total-1; i>=0; i--)
     {
      // select each of orders and getting its ticket
      ticket=OrderGetTicket(i);
      // handling Sell Stop orders
      if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
        {
         ulong  magic=OrderGetInteger(ORDER_MAGIC);               // order MagicNumber
         //--- if MagicNumber matches
         if(magic==EXPERT_MAGIC)
           {
               price=low[1]-offset*m_adjusted_point;                         // open price
            if(price>m_order.PriceOpen()) // check the conditions
            if(low[1]>low[2]) // check the conditions
              {
               request.action=TRADE_ACTION_MODIFY;                           // trading operation type
               request.order = OrderGetTicket(i);                            // order ticket
               request.symbol   =Symbol();                                   // symbol
               request.deviation=InpOffset;                                  // allowed deviation from the price
               price=low[1]-offset*m_adjusted_point;                         // open price
               request.price=NormalizeDouble(price,digits);                  // normalized open price 
               tp=price-m_take_profit;
               sl=price+m_stop_losse;
               request.sl       =NormalizeDouble(sl,_Digits);                // add the new Stop Loss value to the structure
               request.tp       =NormalizeDouble(tp,_Digits);                // add the new Take Profit value to the structure
               //--- sending a request
               if(!OrderSend(request,result))
                 {
                  // setting the flag indicating that the Sell Stop order has not been deleted
                  res=true; printf("OrderSend error %d",GetLastError());
                 }  // if unable to send the request, output the error code
               //--- information about the operation   
               printf("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
              }
           }
        }
     }
   return(res);
  }
//+------------------------------------------------------------------+
//|Changing parameters of the earlier placed Buy Stop trading order  |
//+------------------------------------------------------------------+
bool CSampleExpert::OrderModifyBuyStop(void)
  {
   bool res=true;
   ulong ticket;
   double tp=0,sl=0;
   double offset=InpOffset;                                            // point distance from the current price to place the order
   double price;                                                       // order trigger price
   int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);           // number of decimal places (digits)
                                                                       //--- declare and initialize the trade request and result
   MqlTradeRequest request={0};
   MqlTradeResult  result={0};
   int total=OrdersTotal(); // number of pending orders
//--- iterate over all placed pending orders
   for(int i=total-1; i>=0; i--)
     {
      // select each of orders and getting its ticket
      ticket=OrderGetTicket(i);
      // handling Buy Stop orders
      if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)
        {
         ulong  magic=OrderGetInteger(ORDER_MAGIC);               // order MagicNumber
         //--- if MagicNumber matches
         if(magic==EXPERT_MAGIC)
           {
               price=high[1]+offset*m_adjusted_point;                        // open price
            if(price<m_order.PriceOpen()) // check the conditions
              {
               request.action=TRADE_ACTION_MODIFY;                           // trading operation type
               request.symbol   =Symbol();                                   // symbol
               request.action=TRADE_ACTION_MODIFY;                           // trading operation type
               request.order = OrderGetTicket(i);                            // order ticket
               request.symbol   =Symbol();                                   // symbol
               request.deviation=InpOffset;                                  // allowed deviation from the price
               //--- set the price level, take profit and stop loss 

               request.price=NormalizeDouble(price,digits);                  // normalized open price 
               tp=price+m_take_profit;
               sl=price-m_stop_losse;
               request.sl       =NormalizeDouble(sl,_Digits);                       // add the new Stop Loss value to the structure
               request.tp       =NormalizeDouble(tp,_Digits);                       // add the new Take Profit value to the structure
               //--- sending a request
               if(!OrderSend(request,result))
                 {
                  // setting the flag indicating that the Buy Stop order has not been deleted
                  res=true;
                  printf("OrderSend error %d",GetLastError());
                 }  // if unable to send the request, output the error code
               //--- information about the operation   
               printf("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
              }
           }
        }
     }
   return(res);
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- creating all required object
   if(!ExtExpert.Init())
      return(INIT_FAILED);
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Tick processing function                                         |
//+------------------------------------------------------------------+
void OnTick(void)
  {
   static datetime limit_time=0; // the last trade processing time + timeout
//--- do not handle is timeout
   if(TimeCurrent()>=limit_time)
     {
      //--- checking data
      if(Bars(Symbol(),Period())>barsCalculated)
        {
         //--- checking the limit time in terms of timeout in seconds, if processed
         if(ExtExpert.Processing())
            limit_time=TimeCurrent()+ExtTimeOut;
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CSampleExpert::Copy(void)
  {
//--- amount to copy 
   int copied=3;
//---
   ArrayResize(high,copied);
   ArrayResize(low,copied);
   ArrayResize(close,copied);
   ArrayResize(open,copied);
//+------- Setting the array indexing direction ---------------------+
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(open,true);
//--- copying bar prices 
   if(CopyHigh(NULL,mas_tf[0],0,copied,high)<0)
     {printf("No copied High",GetLastError());return(false);}
//---
   if(CopyLow(NULL,mas_tf[0],0,copied,low)<0)
     {printf("No copied Low",GetLastError());return(false);}
//---
   if(CopyClose(NULL,mas_tf[2],0,copied,close)<0)
     {printf("No copied Close",GetLastError());return(false);}
//---
   if(CopyOpen(NULL,mas_tf[2],0,copied,open)<0)
     {printf("No copied Open",GetLastError());return(false);}
//---
   return(true);
  }
//+------------------------------------------------------------------+

 

برچسب‌ها:

بخش دانلود
  • عنوان اندیکاتور : MTF
  • نوع فایل : ZIP
  • حجم فایل : 1 مگابایت

دانلود اندیکاتور