[英]mql4 separate window indicator using sin wave function
Below is the original code that creates a sin wave in a separate window for MetaTrader 4. My question is how to code it for a 2nd, or 3rd sin wave.下面是在 MetaTrader 4 的单独窗口中创建正弦波的原始代码。我的问题是如何为第二或第三正弦波编写代码。 The original code is compiled and is functional.
原始代码已编译并且可以正常工作。 I will also attach the code I added to the original, it still creates the 1st sin wave but not the second wave.
我还将附上我添加到原始代码中的代码,它仍然会创建第一个正弦波,但不会创建第二个波。 I need help coding the 2nd and 3rd waves.
我需要帮助编码第二波和第三波。 Thanks.
谢谢。
This is the original working code:这是原始工作代码:
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2 // org 1
#property indicator_color1 Red //
//---- indicator buffers
double ExtBuffer1[];
double Dgr[];
extern datetime StartTime=D'1999.11.10 00:00';
//+---------------------------------------------------------------+
//| Custom indicator initialization function |
//+---------------------------------------------------------------+
int init()
{
IndicatorBuffers(1);
SetIndexStyle(0,DRAW_LINE); // 0
SetLevelValue(0,0); //
//----indicator buffers mapping //
SetIndexBuffer(0,ExtBuffer1);
SetIndexShift(0,25); // B. added
//---- initialization done
return(0);
}
//+---------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+---------------------------------------------------------------+
int start()
{
int Shift;
int i;
Shift=iBarShift(Symbol(),PERIOD_D1,StartTime); // Only run on PERIOD_D1
ArrayResize(Dgr,Shift+1); // ArrayResize(Dgr,Shift+1); ?????????????????
MyCalc(Shift,1); // ??? 1
for(i=Shift; i>=0; i--)
ExtBuffer1[i]=Dgr[i];
return(0);
}
//+---------------------------------------------------------------+
void MyCalc(int Shift,int i Yhigh)
{
int i;
for(i=Shift;i>=0;i--) // should be >
{
Dgr[i]=i*2.5;
// ..... B. added code below
double val=i*2.5; // 2.5
Dgr[i]=MathSin(3.14159*val/149)+Yhigh; // 149 ,,, Origina code ...
Dgr[i]=MathSin(3.14159*val/180)+Yhigh; changing the /180 to lower degree changes the
frequency
// ..... B. added above code
//Dgr[i]=MathSin(3.14159*Dgr[i]/180)+Yhigh; // Original Dgr[i]=MathSin(3.14159*-
Dgr[i]/180)+Yhigh;
}
}
This code below is the same code, but with my attempt at creating the 2nd sin wave code added to the original code.下面的代码是相同的代码,但我尝试创建添加到原始代码的第二个正弦波代码。
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2 // org 1
#property indicator_color1 Red //
#property indicator_color2 Orange //
//---- indicator buffers
double ExtBuffer1[];
double ExtBuffer2[];
double Dgr[];
double Dgr2[];
extern datetime StartTime=D'1999.11.10 00:00';
//+---------------------------------------------------------------+
//| Custom indicator initialization function |
//+---------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE); // 0
SetIndexStyle(1,DRAW_LINE); // 0
SetLevelValue(0,0); //
//----indicator buffers mapping //
SetIndexBuffer(0,ExtBuffer1);
SetIndexBuffer(1,ExtBuffer2);
SetIndexShift(0,25); // B. added
SetIndexShift(1,25); // B. added
//---- initialization done
return(0);
}
//+---------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+---------------------------------------------------------------+
int start()
{
int Shift;
int i;
Shift=iBarShift(Symbol(),PERIOD_D1,StartTime); // Only run on PERIOD_D1
ArrayResize(Dgr,Shift+1); // ArrayResize(Dgr,Shift+1); ?????????????????
ArrayResize(Dgr2,Shift+1);
MyCalc(Shift,1); // ??? 1
for(i=Shift; i>=0; i--)
ExtBuffer1[i]=Dgr[i];
ExtBuffer2[i]=Dgr2[i];
return(0);
}
//+---------------------------------------------------------------+
void MyCalc(int Shift, int Yhigh)
{
int i;
for(i=Shift;i>=0;i--) // should be >
{
Dgr[i]=i*2.5;
Dgr2[i]=i*2.5;
double val=i*2.5; // 2.5
double val2=i*2.5; // 2.5
Dgr[i]=MathSin(3.14159*val/149)+Yhigh; // 149
Dgr2[i]=MathSin(3.14159*val2/49)+Yhigh; // 49
}
}
You've just mixed up some lines of your code.您刚刚混淆了一些代码行。 Try the following.
试试下面的。
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Orange
//---- indicator buffers
double ExtBuffer1[], ExtBuffer2[];
double Dgr1[], Dgr2[];
extern datetime StartTime=D'1999.11.10 00:00';
//+---------------------------------------------------------------+
//| Custom indicator initialization function |
//+---------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtBuffer1); SetIndexShift(0,25);
SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,ExtBuffer2); SetIndexShift(1,25);
SetLevelValue(0,0);
return(0);
}
//+---------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+---------------------------------------------------------------+
int start()
{
int Shift;
int i;
Shift=iBarShift(Symbol(),PERIOD_D1,StartTime);
ArrayResize(Dgr1,Shift+1); ArrayResize(Dgr2,Shift+1);
MyCalc(Shift,1);
for(i=Shift; i>=0; i--)
{
ExtBuffer1[i]=Dgr1[i];
ExtBuffer2[i]=Dgr2[i];
}
return(0);
}
//+---------------------------------------------------------------+
void MyCalc(int Shift,int Yhigh)
{
int i;
for(i=Shift;i>=0;i--)
{
Dgr1[i]=i*2.5; Dgr2[i]=i*2.5;
double val1=i*2.5;
double val2=i*2.5;
Dgr1[i]=MathSin(3.14159*val1/149)+Yhigh;
Dgr2[i]=MathSin(3.14159*val2/49)+Yhigh;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.