编码帮助 - 页 678

 
mladen:

西蒙

这些条件应该更加精确。例如:当两个指标都发出相同的信号时是非常频繁的。那么,他们到底应该在什么时候做。在第一次发生的时候?还是在每次发生时?另外,如果你在这两个信号中的一个发生变化时退出,那么退出将非常频繁。

谢谢你的答复!是的,这可能不是一个好的策略。只是,如果我得到这个模板,我可能以后可以自己做一些修改。我想要的是结合两个指标的可能性(以及使用它们的缓冲区)。

比方说,这个策略应该是:当两个指标都显示时买入。当两个指标都显示时卖出。它应该发生在指标变化和闭合条形图之后。它应该在每次出现时发生。

所有这些都是最好的!

 

亲爱的mladen。


我对附件中的指标有一个问题。

当在EA执行过程中应用indi(MT4中的标准移动平均线)时,其数值与EA执行结束时应用同一指标显示的数值非常不同。

能否请您解释一下原因,如果可行,请纠正指标?


附加的文件:
 

Mr mladen ,

我正在做一些改变,将ma ribbon填充到ma channel中,但我对缓冲区有意见。

有什么办法可以把通道隐藏在直方图后面,或者在通道之间做一个空白?

我试着让它空白,但只能在一边做,是否需要增加一个缓冲区?

还有一个问题是在第44行,我不能扩展或删除它。

它总是有错误出现。

请给我一些建议,谢谢。

史蒂芬.


附加的文件:
 
stevenpun:

Mr mladen ,

我正在做一些改变,将ma ribbon填充到ma channel中,但我对缓冲区有意见。

有什么办法可以把通道隐藏在直方图后面,或者在通道之间做一个空白?

我试着让它空白,但只能在一边做,是否需要增加一个缓冲区?

还有一个问题是在第44行,我不能扩展或删除它。

它总是有错误出现。

请给我一些建议,谢谢。

史蒂芬 .


我不确定这是否是你想做的,但可以试试。


附加的文件:
 
mladen:

我不确定这是否是你想要做的,但可以试试。


是的,正是我想要的:D

但你能帮我检查一下 第44行'AlertOnClosedCandle'的代码,为什么它不能删除或extern bool?

这是我第一次遇到这种类型的问题。

无论如何,我已经学到了一些关于缓冲区的东西。

谢谢你。

 

Mladen刚刚完成了我在你之前修改的指标中的定制。这段代码有什么问题?它没有显示任何东西......编译时没有错误。

#property version   "1.00"
#property strict


#property indicator_chart_window
#property indicator_buffers    4
#property  indicator_color1     Gold
#property  indicator_color2     DodgerBlue
#property  indicator_color3     LimeGreen
#property  indicator_color4     Crimson

#property  indicator_width1     2
#property  indicator_width2     2
#property  indicator_width3     2
#property  indicator_width4     2

extern string                NOTE1           = "SELECT PARAMETERS OF THE INDICATOR"; //SPAN MA CROSS PARAMS
extern int                   SpanPeriod      = 1;            // Period of Span
extern int                   SpanShift       = -26;          // Shift of Span
extern ENUM_MA_METHOD        SpanMode        = 1;            // Mode of Span
extern ENUM_APPLIED_PRICE    SpanPrice       = 0;            // Applied price of Span
extern int                   MaPeriod        = 55;           // Period of Moving average
extern int                   MaShift         = 0;            // Shift of Moving average
extern ENUM_MA_METHOD        MaMode          = 1;            // Mode of Moving average
extern ENUM_APPLIED_PRICE    MaPrice         = 0;            // Applied price of Moving average

extern string                NOTE2           = "SELECT COLORS/STYLES OF THE INDICATOR"; //SPAN MA CROSS COLORS/STYLES
extern color                 SpanClr         = Gold;         // Span color
extern int                   SpanWdt         = 2;            // Span width
extern ENUM_LINE_STYLE       SpanStl         = 0;            // Span line style
extern color                 MaClr           = DodgerBlue;   // Moving average color
extern int                   MaWdt           = 2;            // Moving average width
extern ENUM_LINE_STYLE       MaStl           = 0;            // Moving average line style

extern string                NOTE3           = "SELECT PARAMETERS OF THE SIGNAL ARROWS"; //SPAN MA CROSS PARAMETERS OF THE SIGNAL ARROWS
extern bool                  DrawArrows      = true;         // Draw signal arrows?
extern bool                  DrawMaLines     = true;         // Draw lines?
extern color                 UpArrowClr      = LimeGreen;    // Up arrow color
extern int                   UpArrowWdt      = 2;            // Up arrow width
extern color                 DnArrowClr      = Crimson;      // Down arrow color
extern int                   DnArrowWdt      = 2;            // Down arrow width
extern int                   ArrowsDistance  = 10;           // Arrows distance from candle

extern string                NOTE4           = "SELECT PARAMETERS OF THE ALERT"; //SPAN MA CROSS PARAMETERS OF THE ALERT
extern bool                  AlertsOn        = true;         // Active alert?
extern bool                  AlertsOnCurrent = true;         // Alert on current unclosed bar
extern bool                  AlertsMessage   = true;         // Alert message
extern bool                  AlertsSound     = true;         // Alert sound
extern bool                  AlertsEmail     = false;        // Alert e-mail
extern string                SoundFile       = "alert2.wav"; // Filename of sound alert

string                       IndicatorFileName;
int                          WhichBar;
double                       Gap;


double   SpanBuffer[];     // Buffer of the Span
double   MaBuffer[];       // Buffer of the Moving average
double   CrossUpBuffer[];  // Up arrow buffer
double   CrossDnBuffer[];  // Down arrow buffer
double   TrendBuffer[];    // Span/Ma cross buffer


int init()
  {
   IndicatorFileName = WindowExpertName();
   IndicatorBuffers(5);
   
   
   SetIndexBuffer(0, SpanBuffer);
   SetIndexBuffer(1, MaBuffer);
   SetIndexBuffer(2, CrossUpBuffer);
   SetIndexBuffer(3, CrossDnBuffer);
   SetIndexBuffer(4, TrendBuffer);
   
   if (DrawMaLines) {   
   SetIndexStyle (0, DRAW_LINE, SpanStl, SpanWdt, SpanClr);  
   SetIndexStyle (1, DRAW_LINE, MaStl, MaWdt, MaClr);}
        
   else { 
   SetIndexStyle(0, DRAW_NONE); 
   SetIndexStyle(1, DRAW_NONE);} 
     
   if (DrawArrows) {
   SetIndexStyle (2, DRAW_ARROW, 0, UpArrowWdt, UpArrowClr); SetIndexArrow(0, 233);
   SetIndexStyle (3, DRAW_ARROW, 0, DnArrowWdt, DnArrowClr); SetIndexArrow(0, 234);}
   
   else { 
   SetIndexStyle(2, DRAW_NONE); 
   SetIndexStyle(3, DRAW_NONE);} 
   
   
   
return(0);}
  
int deinit() {  return(0); }

int start() {
   int counted_bars = IndicatorCounted();
   int i, limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = MathMin(Bars-counted_bars, Bars-1);
         
         
  for(i=limit; i>=0; i--){   
      SpanBuffer[i]  = iMA(NULL, 0, SpanPeriod, SpanShift, SpanMode, SpanPrice, i);
      MaBuffer[i]    = iMA(NULL, 0, MaPeriod, MaShift, MaMode, MaPrice, i);
      Gap = iATR(NULL,0,20,i);
      
      TrendBuffer[i] = TrendBuffer[i+1];
         if (SpanBuffer[i] > MaBuffer[i]) TrendBuffer[i] = 1;
         if (SpanBuffer[i] < MaBuffer[i]) TrendBuffer[i] =-1;
         
      
         CrossUpBuffer[i] = EMPTY_VALUE;
         CrossDnBuffer[i] = EMPTY_VALUE;
         if (TrendBuffer[i]!= TrendBuffer[i+1])
         if (TrendBuffer[i] == 1)
               CrossUpBuffer[i] = Low[i]  - ArrowsDistance * Gap;
         else  CrossDnBuffer[i] = High[i] + ArrowsDistance * Gap; 
         }
         
         if (AlertsOn)
         {
         if (AlertsOnCurrent)
                  WhichBar = 0;
         else     WhichBar = 1;      
      
         if (TrendBuffer[WhichBar] != TrendBuffer[WhichBar+1])
         if (TrendBuffer[WhichBar] == 1)
               doAlert("uptrend");
         else  doAlert("downtrend");       
   }
   
   return(0);
}


// CUSTOM FUNCTIONS -------------------------

 void doAlert(string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
      if (previousAlert != doWhat || previousTime != Time[0]) {
          previousAlert  = doWhat;
          previousTime   = Time[0];

          message =  StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Span ma cross ", doWhat);
             if (AlertsMessage) Alert(message);
             if (AlertsEmail)   SendMail(StringConcatenate(Symbol()," Span ma cross "), message);
             if (AlertsSound)   PlaySound(SoundFile);
      }
}
 
thefxpros:

Mladen刚刚完成了我在你之前修改的指标中的定制。这段代码有什么问题?它没有显示任何东西......编译时没有错误。

thefxpros

像这样试试吧

#property version   "1.00"
#property strict


#property indicator_chart_window
#property indicator_buffers    4
#property  indicator_color1     Gold
#property  indicator_color2     DodgerBlue
#property  indicator_color3     LimeGreen
#property  indicator_color4     Crimson

#property  indicator_width1     2
#property  indicator_width2     2
#property  indicator_width3     2
#property  indicator_width4     2

extern string                NOTE1           = "SELECT PARAMETERS OF THE INDICATOR"; //SPAN MA CROSS PARAMS
extern int                   SpanPeriod      = 1;            // Period of Span
extern int                   SpanShift       = -26;          // Shift of Span
extern ENUM_MA_METHOD        SpanMode        = 1;            // Mode of Span
extern ENUM_APPLIED_PRICE    SpanPrice       = 0;            // Applied price of Span
extern int                   MaPeriod        = 55;           // Period of Moving average
extern int                   MaShift         = 0;            // Shift of Moving average
extern ENUM_MA_METHOD        MaMode          = 1;            // Mode of Moving average
extern ENUM_APPLIED_PRICE    MaPrice         = 0;            // Applied price of Moving average

extern string                NOTE2           = "SELECT COLORS/STYLES OF THE INDICATOR"; //SPAN MA CROSS COLORS/STYLES
extern color                 SpanClr         = Gold;         // Span color
extern int                   SpanWdt         = 2;            // Span width
extern ENUM_LINE_STYLE       SpanStl         = 0;            // Span line style
extern color                 MaClr           = DodgerBlue;   // Moving average color
extern int                   MaWdt           = 2;            // Moving average width
extern ENUM_LINE_STYLE       MaStl           = 0;            // Moving average line style

extern string                NOTE3           = "SELECT PARAMETERS OF THE SIGNAL ARROWS"; //SPAN MA CROSS PARAMETERS OF THE SIGNAL ARROWS
extern bool                  DrawArrows      = true;         // Draw signal arrows?
extern bool                  DrawMaLines     = true;         // Draw lines?
extern color                 UpArrowClr      = LimeGreen;    // Up arrow color
extern int                   UpArrowWdt      = 2;            // Up arrow width
extern color                 DnArrowClr      = Crimson;      // Down arrow color
extern int                   DnArrowWdt      = 2;            // Down arrow width
extern int                   ArrowsDistance  = 10;           // Arrows distance from candle

extern string                NOTE4           = "SELECT PARAMETERS OF THE ALERT"; //SPAN MA CROSS PARAMETERS OF THE ALERT
extern bool                  AlertsOn        = true;         // Active alert?
extern bool                  AlertsOnCurrent = true;         // Alert on current unclosed bar
extern bool                  AlertsMessage   = true;         // Alert message
extern bool                  AlertsSound     = true;         // Alert sound
extern bool                  AlertsEmail     = false;        // Alert e-mail
extern string                SoundFile       = "alert2.wav"; // Filename of sound alert

string                       IndicatorFileName;
int                          WhichBar;
double                       Gap;


double   SpanBuffer[];     // Buffer of the Span
double   MaBuffer[];       // Buffer of the Moving average
double   CrossUpBuffer[];  // Up arrow buffer
double   CrossDnBuffer[];  // Down arrow buffer
double   TrendBuffer[];    // Span/Ma cross buffer


int init()
  {
   IndicatorFileName = WindowExpertName();
   IndicatorBuffers(5);
   
   
   SetIndexBuffer(0, SpanBuffer);
   SetIndexBuffer(1, MaBuffer);
   SetIndexBuffer(2, CrossUpBuffer);
   SetIndexBuffer(3, CrossDnBuffer);
   SetIndexBuffer(4, TrendBuffer);
   
   if (DrawMaLines) {   
   SetIndexStyle (0, DRAW_LINE, SpanStl, SpanWdt, SpanClr);  
   SetIndexStyle (1, DRAW_LINE, MaStl, MaWdt, MaClr);}
        
   else { 
   SetIndexStyle(0, DRAW_NONE); 
   SetIndexStyle(1, DRAW_NONE);} 
     
   if (DrawArrows) {
   SetIndexStyle (2, DRAW_ARROW, 0, UpArrowWdt, UpArrowClr); SetIndexArrow(0, 233);
   SetIndexStyle (3, DRAW_ARROW, 0, DnArrowWdt, DnArrowClr); SetIndexArrow(0, 234);}
   
   else { 
   SetIndexStyle(2, DRAW_NONE); 
   SetIndexStyle(3, DRAW_NONE);} 
   
   
   
return(0);}
  
int deinit() {  return(0); }

int start() {
   int counted_bars = IndicatorCounted();
   int i, limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = MathMin(Bars-counted_bars, Bars-1);
         
         
  for(i=limit; i>=0; i--){   
      SpanBuffer[i]  = iMA(NULL, 0, SpanPeriod, SpanShift, SpanMode, SpanPrice, i);
      MaBuffer[i]    = iMA(NULL, 0, MaPeriod, MaShift, MaMode, MaPrice, i);
      Gap = iATR(NULL,0,20,i);
      
      if (i<Bars-1) TrendBuffer[i] = TrendBuffer[i+1];
         if (SpanBuffer[i] > MaBuffer[i]) TrendBuffer[i] = 1;
         if (SpanBuffer[i] < MaBuffer[i]) TrendBuffer[i] =-1;
         
      
         CrossUpBuffer[i] = EMPTY_VALUE;
         CrossDnBuffer[i] = EMPTY_VALUE;
         if (i<Bars-1 && TrendBuffer[i]!= TrendBuffer[i+1])
         if (TrendBuffer[i] == 1)
               CrossUpBuffer[i] = Low[i]  - ArrowsDistance * Gap;
         else  CrossDnBuffer[i] = High[i] + ArrowsDistance * Gap; 
         }
         
         if (AlertsOn)
         {
         if (AlertsOnCurrent)
                  WhichBar = 0;
         else     WhichBar = 1;      
      
         if (TrendBuffer[WhichBar] != TrendBuffer[WhichBar+1])
         if (TrendBuffer[WhichBar] == 1)
               doAlert("uptrend");
         else  doAlert("downtrend");       
   }
   
   return(0);
}


// CUSTOM FUNCTIONS -------------------------

 void doAlert(string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
      if (previousAlert != doWhat || previousTime != Time[0]) {
          previousAlert  = doWhat;
          previousTime   = Time[0];

          message =  StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Span ma cross ", doWhat);
             if (AlertsMessage) Alert(message);
             if (AlertsEmail)   SendMail(StringConcatenate(Symbol()," Span ma cross "), message);
             if (AlertsSound)   PlaySound(SoundFile);
      }
}
 
mladen:

纠正:

把sigma的第74行和第75行改成这样。

对这个:

它应该可以工作

或者完全删除strict语句(因为如果要使用 "strict",该指标需要完全重写)。

亲爱的mladen。

我已经尝试了这两个建议,但没有成功,但我发现在EA中运行时,indi没有更新,如下图所示。

应该可以解决这个问题?:

附加的文件:
Sigma.mq4  5 kb
 
mladen:

Thefxpros

像这样尝试一下

我试过Mladen,它似乎在工作,但在策略测试器中,它没有自我刷新,也没有弹出警报,当市场开放时,我将在真实市场中尝试。
 

你好,Mladen先生。

我在想,当价格从趋势中反转时,添加一个评论,并有 "等待购买 "和 "等待出售"。

在买入时添加新线是没有问题的,但在卖出时添加新线却无法使其发挥作用。

我应该怎么改呢?

   string OPstr;
   color OPclr;
   if (buffer1[i+SignalCandle]>buffer5[i+SignalCandle]) {
      OPstr = "BUY";
      OPclr = Green;
      }
   if (buffer1[i+SignalCandle]>buffer5[i+SignalCandle] && Bid < buffer1[i+SignalCandle] ) {
      OPstr = "WAIT FOR BUY";
      OPclr = LimeGreen;
      }       
   else
   
   if (buffer1[i+SignalCandle]<buffer6[i+SignalCandle] ) {
      OPstr = "SELL";
      OPclr = Red;
      }
   if (buffer1[i+SignalCandle]<buffer6[i+SignalCandle] && Bid > buffer1[i+SignalCandle] ) {
      OPstr = "WAIT FOR SELL";
      OPclr = OrangeRed;
      }        
   else 
      {
      OPstr = "NO TRADE";
      OPclr = Yellow;
      }
原因: