新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 117

 
Rustam Bikbulatov:
我是否要为它付钱?
好吧,如果有很多时间的人可以做到这一点,你可能会很幸运。但除此之外,是的,时间就是金钱,抱歉;)

或者尝试自己做,你会在这里得到帮助--帮助只针对那些自学的人,在某方面失败了。
 
Artyom Trishkin:
开始写作。有什么问题--问吧--我们会帮忙。

还是你想让我们为你做这件事?
我想连接这些指标,但有一个错误。 我已经挣扎了一整天了
附加的文件:
tyyu.mq4  5 kb
 
Rustam Bikbulatov:
我一直在尝试连接这些指标,但有一个错误。 我已经弄了一整天了。
给我看看你的代码,你在哪里试图连接它们,有什么问题?

请用SRC按钮粘贴代码,看看你想做什么,而不是把这些代码上传到你的系统,它们已经太多了。
 
Rustam Bikbulatov:
我试图连接这些指标,但有一个错误出来了。
'start' -函数 已经定义,并且有正文 sound Moving Averages.mq4 178 5

附加的文件:
 
Artyom Trishkin:
显示你的代码,你在哪里试图连接它们,你失败的原因是什么?

请使用SRC按钮查看你要做的事情,而不是将这些代码上传到你的系统中--已经有太多的代码了。
我希望我知道那个神奇的按钮是什么。
 
Rustam Bikbulatov:
如果我知道那个神奇的按钮是什么。

哦,好吧。

请阅读关于如何使用论坛的帮助。你想要一个链接,还是你能自己找到它?

 
//+------------------------------------------------------------------+
//|                                        Custom Moving Average.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- indicator parameters
extern int MA_Period=13;
extern int MA_Shift=0;
extern int MA_Method=0;
extern double Alert_Level = 0;
//---- indicator buffers
double ExtMapBuffer[];
double Buffer2[];
//----
int ExtCountedBars=0;
int br1=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexShift(0,MA_Shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   if(MA_Period<2) MA_Period=13;
   draw_begin=MA_Period-1;
//---- indicator short name
   switch(MA_Method)
     {
      case 1 : short_name="EMA(";  draw_begin=0; break;
      case 2 : short_name="SMMA("; break;
      case 3 : short_name="LWMA("; break;
      default :
         MA_Method=0;
         short_name="SMA(";
     }
   IndicatorShortName(short_name+MA_Period+")");
   SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars<=MA_Period) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
//----
   switch(MA_Method)
     {
      case 0 : sma();  break;
      case 1 : ema();  break;
      case 2 : smma(); break;
      case 3 : lwma();
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
void sma()
  {
   double sum=0;
   int    i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<MA_Period;i++,pos--)
      sum+=Close[pos];
//---- main calculation loop
   while(pos>=0)
     {
      sum+=Close[pos];
      ExtMapBuffer[pos]=sum/MA_Period;
           sum-=Close[pos+MA_Period-1];
           pos--;
     }
//---- zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<MA_Period;i++) ExtMapBuffer[Bars-i]=0;
  }
//+------------------------------------------------------------------+
//| Exponential Moving Average                                       |
//+------------------------------------------------------------------+
void ema()
  {
   double pr=2.0/(MA_Period+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer[pos+1]=Close[pos+1];
      ExtMapBuffer[pos]=Close[pos]*pr+ExtMapBuffer[pos+1]*(1-pr);
           pos--;
     }
  }
//+------------------------------------------------------------------+
//| Smoothed Moving Average                                          |
//+------------------------------------------------------------------+
void smma()
  {
   double sum=0;
   int    i,k,pos=Bars-ExtCountedBars+1;
//---- main calculation loop
   pos=Bars-MA_Period;
   if(pos>Bars-ExtCountedBars) pos=Bars-ExtCountedBars;
   while(pos>=0)
     {
      if(pos==Bars-MA_Period)
        {
         //---- initial accumulation
         for(i=0,k=pos;i<MA_Period;i++,k++)
           {
            sum+=Close[k];
            //---- zero initial bars
            ExtMapBuffer[k]=0;
           }
        }
      else sum=ExtMapBuffer[pos+1]*(MA_Period-1)+Close[pos];
      ExtMapBuffer[pos]=sum/MA_Period;
           pos--;
     }
  }
//+------------------------------------------------------------------+
//| Linear Weighted Moving Average                                   |
//+------------------------------------------------------------------+
void lwma()
  {
   double sum=0.0,lsum=0.0;
   double price;
   int    i,weight=0,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<=MA_Period;i++,pos--)
     {
      price=Close[pos];
      sum+=price*i;
      lsum+=price;
      weight+=i;
     }
//---- main calculation loop
   pos++;
   i=pos+MA_Period;
   while(pos>=0)
     {
      ExtMapBuffer[pos]=sum/weight;
      if(pos==0) break;
      pos--;
      i--;
      price=Close[pos];
      sum=sum-lsum+price*MA_Period;
      lsum-=Close[i];
      lsum+=price;
     }
//---- zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<MA_Period;i++) ExtMapBuffer[Bars-i]=0;
  }
//+------------------------------------------------------------------+

int start()
   {int limit;
    int counted_bars = IndicatorCounted();
//---- check for possible errors
    if(counted_bars < 0)
        return(-1);
//---- last counted bar will be recounted
    if(counted_bars > 0)
        counted_bars--;
    limit = Bars - counted_bars;
    if(counted_bars==0) limit--;
//----
    for(int i = limit; i >=0; i--)
    //for(int i = 1000; i >=0; i--)
       {
        Buffer2[i]=iMA(NULL,1,60,0,1,6,0);
       }
    if(((Buffer2[2]<0 && Buffer2[1]>Alert_Level) ||
        (Buffer2[2]>0 && Buffer2[1]<Alert_Level)) && br1<Bars  )
      {
       PlaySound("alert.wav"); Sleep(500);
       PlaySound("alert.wav"); Sleep(500);
       PlaySound("alert.wav"); br1=Bars;
       Alert("На ",Symbol()," \"", "\" пересечение с =0= ");
       Print("На ",Symbol()," \"", "\" пересечение с =0= ");
      }
  }
//+------------------------------------------------------------------+
 

另一件趣事

双重OP=5.00000

TP=(OP/100)。

Print("TP=",TP)。

2017.02.09 21:36:03.650 2015.01.05 04:00:00 martin H1-1 USDJPY,H1: TP= 0.5

我不明白,什么时候5除以100才是0.5?

我已经弄明白了--由于某种原因,终端不支持不同的颜色,它只是采用其他函数中已有的颜色。

 
trader781:
...

终端不支持不同的颜色,并采取了其他函数中已经存在的东西

在物体中?胡说八道。
 
Artyom Trishkin:
物品?胡说八道。
Artyom,我在上面抛出的代码
原因: