B 밴드와 B 너비를 기반으로 하는 EA, 긴급 도움이 필요합니다!!

 

여러분 모두에게,

B 밴드 및 B 너비와 함께 작동하는 ea를 프로그래밍 중입니다. B 너비의 경우 사용자 지정 EA를 추가했습니다. 컴파일할 때 오류가 발생하지 않습니다.

그러나 Custom Indicator 호출에 몇 가지 문제가 있음을 확신합니다.

그래서 나는 그것을 수정하기 위해 일부 프로그래머의 도움이 필요합니다. 나는 항상 이번에는 나를 도와주는 감사합니다.

 //+------------------------------------------------------------------+
//|                                            Bolinger_Width_EA.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link       "http://www.mql5.com"
#property version   "1.00"

//--- input parameters
input int bands_period= 20 ;         // Bollinger Bands period
input int bands_shift = 0 ;         // Bollinger Bands shift
input double deviation= 2 ;         // Standard deviation
input double    Lot= 1 ;             // Lots to trade
//-----------------------
input uint ibands_period= 15 ; //smoothing depth                    
input double ideviation= 1.5 ; //deviation
input ENUM_APPLIED_PRICE   iapplied_price= PRICE_CLOSE ; //type of price or handle
input int ibands_shift= 0 ; //horizontal shift of the indicator in bars
//--- global variables
int BolBandsHandle;                 // Bolinger Bands handle
double BBUp[],BBLow[],BBMidle[];   // dynamic arrays for numerical values of Bollinger Bands
//------------
double i_BB_Width[];
int BB_Handle;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- Do we have sufficient bars to work
   if ( Bars ( _Symbol , _Period )< 60 ) // total number of bars is less than 60?
     {
       Alert ( "We have less than 60 bars on the chart, an Expert Advisor terminated!!" );
       return (- 1 );
     }
//--- get handle of the Bollinger Bands and Width indicators
   BolBandsHandle= iBands ( NULL , PERIOD_M1 ,bands_period,bands_shift,deviation, PRICE_CLOSE );
   BB_Handle= iCustom ( NULL , PERIOD_M1 , "i-BB-Width" ,ibands_period,ibands_shift,ideviation, PRICE_CLOSE );
//--- Check for Invalid Handle
   if ((BolBandsHandle< 0 ) || (BB_Handle< 0 ))
     {
       Alert ( "Error in creation of indicators - error: " , GetLastError (), "!!" );
       return (- 1 );
     }

   return ( 0 );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- release indicator handles
   IndicatorRelease (BolBandsHandle);
   IndicatorRelease (BB_Handle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
//--- we will use the static Old_Time variable to serve the bar time.
//--- at each OnTick execution we will check the current bar time with the saved one.
//--- if the bar time isn't equal to the saved time, it indicates that we have a new tick.

   static datetime Old_Time;
   datetime New_Time[ 1 ];
   bool IsNewBar= false ;

//--- copying the last bar time to the element New_Time[0]
   int copied= CopyTime ( _Symbol , _Period , 0 , 1 ,New_Time);
   if (copied> 0 ) // ok, the data has been copied successfully
     {
       if (Old_Time!=New_Time[ 0 ]) // if old time isn't equal to new bar time
        {
         IsNewBar= true ;   // if it isn't a first call, the new bar has appeared
         if ( MQL5InfoInteger ( MQL5_DEBUGGING )) Print ( "We have new bar here " ,New_Time[ 0 ], " old time was " ,Old_Time);
         Old_Time=New_Time[ 0 ];             // saving bar time
        }
     }
   else
     {
       Alert ( "Error in copying historical times data, error =" , GetLastError ());
       ResetLastError ();
       return ;
     }

//--- EA should only check for new trade if we have a new bar
   if (IsNewBar== false )
     {
       return ;
     }

//--- do we have enough bars to work with
   int Mybars= Bars ( _Symbol , _Period );
   if (Mybars< 60 ) // if total bars is less than 60 bars
     {
       Alert ( "We have less than 60 bars, EA will now exit!!" );
       return ;
     }

   MqlRates mrate[];           // To be used to store the prices, volumes and spread of each bar   

/*
     Let's make sure our arrays values for the Rates and Indicators 
     is stored serially similar to the timeseries array
*/

// the rates arrays
   ArraySetAsSeries (mrate, true );
   ArraySetAsSeries (i_BB_Width, true );
// the indicator arrays
   ArraySetAsSeries (BBUp, true );
   ArraySetAsSeries (BBLow, true );
   ArraySetAsSeries (BBMidle, true );

//--- Get the details of the latest 3 bars
   if ( CopyRates ( _Symbol , _Period , 0 , 3 ,mrate)< 0 )
     {
       Alert ( "Error copying rates/history data - error:" , GetLastError (), "!!" );
       return ;
     }

//--- Copy the new values of our indicators to buffers (arrays) using the handle
   if ( CopyBuffer (BolBandsHandle, 0 , 0 , 3 ,BBMidle)< 0 || CopyBuffer (BolBandsHandle, 1 , 0 , 3 ,BBUp)< 0
      || CopyBuffer (BolBandsHandle, 2 , 0 , 3 ,BBLow)< 0 )
     {
       Alert ( "Error copying Bollinger Bands indicator Buffers - error:" , GetLastError (), "!!" );
       return ;
     }

   if ( CopyBuffer (BB_Handle, 0 , 0 , 3 ,i_BB_Width)< 0 )
     {
       Alert ( "Error copying BB indicator buffer - error:" , GetLastError ());
       return ;
     }

   double Ask = SymbolInfoDouble ( _Symbol , SYMBOL_ASK );   // Ask price
   double Bid = SymbolInfoDouble ( _Symbol , SYMBOL_BID );   // Bid price

//--- Declare bool type variables to hold our Buy and Sell Conditions
   bool Buy_Condition =(mrate[ 1 ].close > BBUp[ 1 ] && mrate[ 1 ].open < BBUp[ 1 ] &&   // White (bull) candle crossed the Lower Band from below to above
                        i_BB_Width[ 0 ]>i_BB_Width[ 1 ] && i_BB_Width[ 1 ]>i_BB_Width[ 2 ]); // and Width is growing up

   bool Sell_Condition = (mrate[ 1 ].close < BBLow[ 1 ] && mrate[ 1 ].open > BBLow[ 1 ] &&   // Black (bear) candle crossed the Upper Band from above to below
                          i_BB_Width[ 0 ]>i_BB_Width[ 1 ] && i_BB_Width[ 1 ]>i_BB_Width[ 2 ]); // and Width is falling down

   bool Buy_Close=(mrate[ 1 ].close<BBMidle[ 1 ] && mrate[ 1 ].open>BBMidle[ 1 ]);               // Black candle crossed the Upper Band from above to below

   bool Sell_Close=(mrate[ 1 ].close>BBMidle[ 1 ] && mrate[ 1 ].open<BBMidle[ 1 ]);           // White candle crossed the Lower Band from below to above

   if (Buy_Condition && ! PositionSelect ( _Symbol ))     // Open long position
     {                                               // Width is growing up
      LongPositionOpen();                           // and white candle crossed the Lower Band from below to above
     }

   if (Sell_Condition && ! PositionSelect ( _Symbol ))   // Open short position
     {                                               // Width is falling down
      ShortPositionOpen();                           // and Black candle crossed the Upper Band from above to below
     }

   if (Buy_Close && PositionSelect ( _Symbol ))         // Close long position
     {                                               // Black candle crossed the Upper Band from above to below
      LongPositionClose();
     }

   if (Sell_Close && PositionSelect ( _Symbol ))         // Close short position
     {                                               // White candle crossed the Lower Band from below to above
      ShortPositionClose();
     }

   return ;
  }
//+------------------------------------------------------------------+
//| Open Long position                                               |
//+------------------------------------------------------------------+
void LongPositionOpen()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory (mrequest);
   ZeroMemory (mresult);
   
   double Ask = SymbolInfoDouble ( _Symbol , SYMBOL_ASK );     // Ask price
   double Bid = SymbolInfoDouble ( _Symbol , SYMBOL_BID );     // Bid price

   if (! PositionSelect ( _Symbol ))
     {
      mrequest.action = TRADE_ACTION_DEAL ;               // Immediate order execution
      mrequest.price = NormalizeDouble (Ask, _Digits );     // Lastest Ask price
      mrequest.sl = 0 ;                                   // Stop Loss
      mrequest.tp = 0 ;                                   // Take Profit
      mrequest.symbol = _Symbol ;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0 ;                                 // Magic Number
      mrequest.type = ORDER_TYPE_BUY ;                     // Buy Order
      mrequest.type_filling = ORDER_FILLING_FOK ;         // Order execution type
      mrequest.deviation= 5 ;                               // Deviation from current price
       OrderSend (mrequest,mresult);                       // Send order
     }
  }
//+------------------------------------------------------------------+
//| Open Short position                                              |
//+------------------------------------------------------------------+
void ShortPositionOpen()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory (mrequest);
   ZeroMemory (mresult);
   
   double Ask = SymbolInfoDouble ( _Symbol , SYMBOL_ASK );     // Ask price
   double Bid = SymbolInfoDouble ( _Symbol , SYMBOL_BID );     // Bid price

   if (! PositionSelect ( _Symbol ))
     {
      mrequest.action = TRADE_ACTION_DEAL ;               // Immediate order execution
      mrequest.price = NormalizeDouble (Bid, _Digits );     // Lastest Bid price
      mrequest.sl = 0 ;                                   // Stop Loss
      mrequest.tp = 0 ;                                   // Take Profit
      mrequest.symbol = _Symbol ;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0 ;                                 // Magic Number
      mrequest.type= ORDER_TYPE_SELL ;                     // Sell order
      mrequest.type_filling = ORDER_FILLING_FOK ;         // Order execution type
      mrequest.deviation= 5 ;                               // Deviation from current price
       OrderSend (mrequest,mresult);                       // Send order
     }
  }
//+------------------------------------------------------------------+
//| Close Long position                                              |
//+------------------------------------------------------------------+
void LongPositionClose()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory (mrequest);
   ZeroMemory (mresult);
   
   double Ask = SymbolInfoDouble ( _Symbol , SYMBOL_ASK );     // Ask price
   double Bid = SymbolInfoDouble ( _Symbol , SYMBOL_BID );     // Bid price

   if ( PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_BUY )
     {
      mrequest.action = TRADE_ACTION_DEAL ;               // Immediate order execution
      mrequest.price = NormalizeDouble (Bid, _Digits );     // Lastest Bid price
      mrequest.sl = 0 ;                                   // Stop Loss
      mrequest.tp = 0 ;                                   // Take Profit
      mrequest.symbol = _Symbol ;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0 ;                                 // Magic Number
      mrequest.type= ORDER_TYPE_SELL ;                     // Sell order
      mrequest.type_filling = ORDER_FILLING_FOK ;         // Order execution type
      mrequest.deviation= 5 ;                               // Deviation from current price
       OrderSend (mrequest,mresult);                       // Send order
     }
  }
//+------------------------------------------------------------------+
//| Close Short position                                             |
//+------------------------------------------------------------------+
void ShortPositionClose()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory (mrequest);
   ZeroMemory (mresult);
   
   double Ask = SymbolInfoDouble ( _Symbol , SYMBOL_ASK );     // Ask price
   double Bid = SymbolInfoDouble ( _Symbol , SYMBOL_BID );     // Bid price

   if ( PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_SELL )
     {
      mrequest.action = TRADE_ACTION_DEAL ;               // Immediate order execution
      mrequest.price = NormalizeDouble (Ask, _Digits );     // Latest ask price
      mrequest.sl = 0 ;                                   // Stop Loss
      mrequest.tp = 0 ;                                   // Take Profit
      mrequest.symbol = _Symbol ;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0 ;                                 // Magic Number
      mrequest.type = ORDER_TYPE_BUY ;                     // Buy order
      mrequest.type_filling = ORDER_FILLING_FOK ;         // Order execution type
      mrequest.deviation= 5 ;                               // Deviation from current price
       OrderSend (mrequest,mresult);                       // Send order
     }
  }
//+------------------------------------------------------------------+
미리 감사드립니다
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
 
surubabs :

여러분 모두에게,

B 밴드 및 B 너비와 함께 작동하는 ea를 프로그래밍 중입니다. B 너비의 경우 사용자 지정 EA를 추가했습니다. 컴파일할 때 오류가 발생하지 않습니다.

그러나 Custom Indicator 호출에 몇 가지 문제가 있음을 확신합니다.

그래서 나는 그것을 수정하기 위해 일부 프로그래머의 도움이 필요합니다. 나는 항상 이번에는 나를 도와주는 감사합니다.

미리 감사드립니다

iBand Width의 입력 매개변수 순서에 주의하십시오.

BB_Handle= iCustom ( NULL , PERIOD_M1 , "i-BB-Width" ,ibands_period,ibands_shift,ideviation, PRICE_CLOSE );

표시기의 입력 순서에 따라 다음과 같아야 합니다.

BB_Handle= iCustom ( NULL , PERIOD_M1 , "i-BB-Width" ,ibands_period,ideviation,iapplied_price,ibands_shift);
 

사용자 지정 표시기 가 필요하지 않습니다.

bbands가 있으면 bbands의 봉투를 빼십시오.

Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
 
achidayat :

iBand Width의 입력 매개변수 순서에 주의하십시오.

표시기의 입력 순서에 따라 다음과 같아야 합니다.

사용자 지정 표시기 를 추가하고 있습니다. 이 표시기의 올바른 호출 방법을 알려주세요.

당신의 도움을 주셔서 감사합니다.

 //+------------------------------------------------------------------+
//|                                                   i-BB-Width.mq5 | 
//|                         Copyright © 2007, Kim Igor V. aka KimIV. | 
//|                                             http://www.kimiv.ru/ | 
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, Kim Igor V. aka KimIV."
#property link "http://www.kimiv.ru/"
#property description "The width of the Bollinger Bands"
//---- indicator version number
#property version   "1.00"
//---- drawing indicator in a separate window
#property indicator_separate_window 
//---- number of indicator buffers
#property indicator_buffers 1 
//---- only one plot is used
#property indicator_plots   1
//+-----------------------------------+
//|  Parameters of indicator drawing  |
//+-----------------------------------+
//---- drawing the indicator as a line
#property indicator_type1   DRAW_LINE
//---- blue color is used for the indicator line
#property indicator_color1 Blue
//---- the indicator line is a continuous curve
#property indicator_style1  STYLE_SOLID
//---- Indicator line width is equal to 1
#property indicator_width1   2
//---- displaying the indicator label
#property indicator_label1   "i-BB-Width"
//+-----------------------------------+
//|  Declaration of constants         |
//+-----------------------------------+
#define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal
//+-----------------------------------+
//|  Input parameters of the indicator|
//+-----------------------------------+
input uint bands_period= 20 ; //smoothing depth                    
input double deviation= 2.0 ; //deviation
input ENUM_APPLIED_PRICE   applied_price= PRICE_CLOSE ; //type of price or handle
input int Shift= 0 ; //horizontal shift of the indicator in bars
//+-----------------------------------+

//---- declaration of a dynamic array that further 
// will be used as an indicator buffer
double IndBuffer[];

//---- declaration of integer variables for the indicators handles
int BB_Handle;
//---- declaration of the integer variables for the start of data calculation
uint min_rates_total;
//+------------------------------------------------------------------+   
//| i-BB-Width indicator initialization function                     | 
//+------------------------------------------------------------------+ 
void OnInit ()
  {
//---- Initialization of variables of the start of data calculation
   min_rates_total=bands_period;

//---- getting handle of the iBearsPower indicator
   BB_Handle= iBands ( NULL , 0 , int (bands_period), 0 ,deviation,applied_price);
   if (BB_Handle== INVALID_HANDLE ) Print ( " Failed to get handle of the iBands indicator" );

//---- set dynamic array as an indicator buffer
   SetIndexBuffer ( 0 ,IndBuffer, INDICATOR_DATA );
//---- moving the indicator 1 horizontally
   PlotIndexSetInteger ( 0 , PLOT_SHIFT ,Shift);
//---- performing the shift of beginning of indicator drawing
   PlotIndexSetInteger ( 0 , PLOT_DRAW_BEGIN ,min_rates_total);
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble ( 0 , PLOT_EMPTY_VALUE , EMPTY_VALUE );
//---- indexing elements in the buffer as in timeseries
   ArraySetAsSeries (IndBuffer, true );

//---- initializations of variable for indicator short name
   string shortname;
   StringConcatenate (shortname, "i-BB-Width(" ,
                     bands_period, ", " ,deviation, ", " , EnumToString (applied_price), ", " ,Shift, ")" );
//--- creation of the name to be displayed in a separate sub-window and in a pop up help
   IndicatorSetString ( INDICATOR_SHORTNAME ,shortname);

//---- determination of accuracy of displaying the indicator values
   IndicatorSetInteger ( INDICATOR_DIGITS , 0 );
//---- end of initialization
  }
//+------------------------------------------------------------------+ 
//| i-BB-Width iteration function                                    | 
//+------------------------------------------------------------------+ 
int OnCalculate (
                 const int rates_total,     // amount of history in bars at the current tick
                 const int prev_calculated, // amount of history in bars at the previous tick
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[]
                )
  {
//---- checking the number of bars to be enough for calculation
   if ( BarsCalculated (BB_Handle)<rates_total || rates_total< int (min_rates_total)) return (RESET);

//---- declaration of variables with a floating point  
   double UpBB[],DnBB[];
//---- Declaration of integer variables and getting already calculated bars
   int limit,bar,to_copy;

//--- calculations of the necessary amount of data to be copied and
//the "limit" starting index for loop of bars recalculation
   if (prev_calculated>rates_total || prev_calculated<= 0 ) // checking for the first start of the indicator calculation
     {
      limit= int (rates_total-min_rates_total- 1 ); // starting index for calculation of all bars
     }
   else limit=rates_total-prev_calculated; // starting index for calculation of new bars
   to_copy=limit+ 1 ;

//---- indexing elements in arrays as time series  
   ArraySetAsSeries (UpBB, true );
   ArraySetAsSeries (DnBB, true );

//---- copy newly appeared data into the arrays  
   if ( CopyBuffer (BB_Handle, UPPER_BAND , 0 ,to_copy,UpBB)<= 0 ) return (RESET);
   if ( CopyBuffer (BB_Handle, LOWER_BAND , 0 ,to_copy,DnBB)<= 0 ) return (RESET);

//---- Main cycle of calculation of the indicator
   for (bar=limit; bar>= 0 && ! IsStopped (); bar--) IndBuffer[bar]=(UpBB[bar]-DnBB[bar])/ _Point ;
//----     
   return (rates_total);
  }
//+------------------------------------------------------------------+
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
 
graziani :

사용자 지정 표시기 가 필요하지 않습니다.

bbands가 있으면 bbands의 봉투를 빼십시오.

귀하의 의견에 감사드립니다. 여기에 표시기 코드를 추가하고 있습니다.
 //+------------------------------------------------------------------+
//|                                                   i-BB-Width.mq5 | 
//|                         Copyright © 2007, Kim Igor V. aka KimIV. | 
//|                                             http://www.kimiv.ru/ | 
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, Kim Igor V. aka KimIV."
#property link "http://www.kimiv.ru/"
#property description "The width of the Bollinger Bands"
//---- indicator version number
#property version   "1.00"
//---- drawing indicator in a separate window
#property indicator_separate_window 
//---- number of indicator buffers
#property indicator_buffers 1 
//---- only one plot is used
#property indicator_plots   1
//+-----------------------------------+
//|  Parameters of indicator drawing  |
//+-----------------------------------+
//---- drawing the indicator as a line
#property indicator_type1   DRAW_LINE
//---- blue color is used for the indicator line
#property indicator_color1 Blue
//---- the indicator line is a continuous curve
#property indicator_style1  STYLE_SOLID
//---- Indicator line width is equal to 1
#property indicator_width1   2
//---- displaying the indicator label
#property indicator_label1   "i-BB-Width"
//+-----------------------------------+
//|  Declaration of constants         |
//+-----------------------------------+
#define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal
//+-----------------------------------+
//|  Input parameters of the indicator|
//+-----------------------------------+
input uint bands_period= 20 ; //smoothing depth                    
input double deviation= 2.0 ; //deviation
input ENUM_APPLIED_PRICE   applied_price= PRICE_CLOSE ; //type of price or handle
input int Shift= 0 ; //horizontal shift of the indicator in bars
//+-----------------------------------+

//---- declaration of a dynamic array that further 
// will be used as an indicator buffer
double IndBuffer[];

//---- declaration of integer variables for the indicators handles
int BB_Handle;
//---- declaration of the integer variables for the start of data calculation
uint min_rates_total;
//+------------------------------------------------------------------+   
//| i-BB-Width indicator initialization function                     | 
//+------------------------------------------------------------------+ 
void OnInit ()
  {
//---- Initialization of variables of the start of data calculation
   min_rates_total=bands_period;

//---- getting handle of the iBearsPower indicator
   BB_Handle= iBands ( NULL , 0 , int (bands_period), 0 ,deviation,applied_price);
   if (BB_Handle== INVALID_HANDLE ) Print ( " Failed to get handle of the iBands indicator" );

//---- set dynamic array as an indicator buffer
   SetIndexBuffer ( 0 ,IndBuffer, INDICATOR_DATA );
//---- moving the indicator 1 horizontally
   PlotIndexSetInteger ( 0 , PLOT_SHIFT ,Shift);
//---- performing the shift of beginning of indicator drawing
   PlotIndexSetInteger ( 0 , PLOT_DRAW_BEGIN ,min_rates_total);
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble ( 0 , PLOT_EMPTY_VALUE , EMPTY_VALUE );
//---- indexing elements in the buffer as in timeseries
   ArraySetAsSeries (IndBuffer, true );

//---- initializations of variable for indicator short name
   string shortname;
   StringConcatenate (shortname, "i-BB-Width(" ,
                     bands_period, ", " ,deviation, ", " , EnumToString (applied_price), ", " ,Shift, ")" );
//--- creation of the name to be displayed in a separate sub-window and in a pop up help
   IndicatorSetString ( INDICATOR_SHORTNAME ,shortname);

//---- determination of accuracy of displaying the indicator values
   IndicatorSetInteger ( INDICATOR_DIGITS , 0 );
//---- end of initialization
  }
//+------------------------------------------------------------------+ 
//| i-BB-Width iteration function                                    | 
//+------------------------------------------------------------------+ 
int OnCalculate (
                 const int rates_total,     // amount of history in bars at the current tick
                 const int prev_calculated, // amount of history in bars at the previous tick
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[]
                )
  {
//---- checking the number of bars to be enough for calculation
   if ( BarsCalculated (BB_Handle)<rates_total || rates_total< int (min_rates_total)) return (RESET);

//---- declaration of variables with a floating point  
   double UpBB[],DnBB[];
//---- Declaration of integer variables and getting already calculated bars
   int limit,bar,to_copy;

//--- calculations of the necessary amount of data to be copied and
//the "limit" starting index for loop of bars recalculation
   if (prev_calculated>rates_total || prev_calculated<= 0 ) // checking for the first start of the indicator calculation
     {
      limit= int (rates_total-min_rates_total- 1 ); // starting index for calculation of all bars
     }
   else limit=rates_total-prev_calculated; // starting index for calculation of new bars
   to_copy=limit+ 1 ;

//---- indexing elements in arrays as time series  
   ArraySetAsSeries (UpBB, true );
   ArraySetAsSeries (DnBB, true );

//---- copy newly appeared data into the arrays  
   if ( CopyBuffer (BB_Handle, UPPER_BAND , 0 ,to_copy,UpBB)<= 0 ) return (RESET);
   if ( CopyBuffer (BB_Handle, LOWER_BAND , 0 ,to_copy,DnBB)<= 0 ) return (RESET);

//---- Main cycle of calculation of the indicator
   for (bar=limit; bar>= 0 && ! IsStopped (); bar--) IndBuffer[bar]=(UpBB[bar]-DnBB[bar])/ _Point ;
//----     
   return (rates_total);
  }
//+------------------------------------------------------------------+
 
surubabs :

사용자 지정 표시기 를 추가하고 있습니다. 이 표시기의 올바른 호출 방법을 알려주세요.

당신의 도움을 주셔서 감사합니다.

내가 전에 말했듯이 당신은 명령에주의를 기울여야합니다. 따라서 입력 매개변수가 다음과 같은 경우:

 input uint bands_period= 20 ; //smoothing depth                    
input double deviation= 2.0 ; //deviation
input ENUM_APPLIED_PRICE   applied_price= PRICE_CLOSE ; //type of price or handle
input int Shift= 0 ; //horizontal shift of the indicator in bar

그런 다음 표시기를 호출하려면 동일한 주문을 작성해야 합니다.

BB_Handle= iCustom ( NULL , PERIOD_M1 , "i-BB-Width" ,bands_period,deviation,applied_price,Shift);
 
achidayat :

내가 전에 말했듯이 당신은 명령에주의를 기울여야합니다. 따라서 입력 매개변수가 다음과 같은 경우:

그런 다음 표시기를 호출하려면 동일한 주문을 작성해야 합니다.

나는 당신이 조언 한 것처럼 그것을했지만 여전히 직면하고있는 문제는 ontick()에 있습니다. 버퍼를 복사하면 너비 표시기가 한 줄만 있고 표시기 코드에서 IndiBuffer로 표시됩니다.

그런 다음 너비 표시기 코드와 같은 경우 너비 표시기에서 어떤 버퍼를 복사해야 하나요?

 //---- copy newly appeared data into the arrays  
   if ( CopyBuffer (BB_Handle, UPPER_BAND , 0 ,to_copy,UpBB)<= 0 ) return (RESET);
   if ( CopyBuffer (BB_Handle, LOWER_BAND , 0 ,to_copy,DnBB)<= 0 ) return (RESET);

나는 이것을 매수 매도 조건에서 사용할 수 없다.

올바른 방법으로 프로그래밍하도록 조언해 주세요. 나는 이것에 대해 이틀 이상 시도했습니다.

도와주세요 선생님

 

grazani가 당신에게 말한 것은 "i-BB_Width"의 사용이 불필요하다는 것입니다. 이 표시기는 상위 밴드와 하위 밴드 간의 차이만 계산합니다. 따라서 EA에서 이 표시기를 완전히 제거할 수 있습니다.

그런 다음 알고리즘의 논리를 확인 하는 것은 사용자의 몫입니다.

파일:
 
angevoyageur :

grazani가 당신에게 말한 것은 "i-BB_Width"의 사용이 불필요하다는 것입니다. 이 표시기는 상위 밴드와 하위 밴드 간의 차이만 계산합니다. 따라서 EA에서 이 표시기를 완전히 제거할 수 있습니다.

그런 다음 알고리즘의 논리를 확인하는 것은 사용자의 몫입니다.

하하 좋은 솔루션, 나는 그것을 좋아 :-)

선생님, 나에게 돈이 있습니다.

너비를 ea로 나눌 수 있습니까? 너비=업밴드-저대역/기준선,

가능합니까?

 
surubabs :

하하 좋은 솔루션, 나는 그것을 좋아 :-)

선생님, 나에게 돈이 있습니다.

너비를 ea로 나눌 수 있습니까? 너비=업밴드-저대역/기준선,

가능합니까?

죄송하지만 귀하의 질문을 이해하지 못합니다.
 
angevoyageur :
죄송하지만 귀하의 질문을 이해하지 못합니다.

맞춤법 오류가 있어 죄송합니다,

나는 이것을 위해 밴드의 너비를 원합니다. 다음과 같은 계산이 필요합니다.

폭=(상단대역-하대역)/기저대역

그래서 ea 내부에서 이 계산을 할 수 있습니까?

이것을 정의하는 방법? 내가 오류를 얻으려고했을 때,

너비[]=(상단대역[ ]-하대대역[ ])/기저대역[ ],

조언 부탁드립니다