MA start - влияет на период самой быстрой средней
MA degree - влияет на шаг между средними
Исходный код:
Код: Выделить всё
#include <windows.h>
#include "IndicatorInterfaceUnit.h"
#include "TechnicalFunctions.h"
// External variables
#define _buzzcnt 25
int MAstart;
double MAdegree;
///////////////////////////////////////
int calcMAper( int j){
int per= (int) pow(j+MAstart, MAdegree);
return per;
}
///////////////////////////////////////
#define __pi 3.1415926535897932384626433832795
int cvetradugi(int i, int iz){
double q=(__pi*2)/((double)iz)*i;
return
RGB( 127*(cos(q)+1) ,
127*(cos(q+4*__pi/3.)+1) ,
127*(cos(q+2*__pi/3.)+1) );
}
// Buffers
TIndexBuffer BigMA;
TIndexBuffer buzz[_buzzcnt];
//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
EXPORT void __stdcall Init()
{
char ss[100]={0};
strcat_s(ss, 100, "Mnogo MA: ");
strcat_s(ss, 100, __DATE__);
strcat_s(ss, 100, ", ");
strcat_s(ss, 100, __TIME__);
// define properties
IndicatorShortName(ss);
SetOutputWindow(ow_ChartWindow);
// register options
AddSeparator("MA");
RegOption("MA start (wierd)", ot_Integer, &MAstart);
SetOptionRange("MA start (wierd)", 1, 50);
MAstart = 4;
RegOption("MA degree", ot_Double, &MAdegree);
SetOptionRange("MA degree", 1, 3);
MAdegree = 2.1;
// create buffers
BigMA = CreateIndexBuffer();
IndicatorBuffers(_buzzcnt+1);
SetIndexBuffer(0, BigMA);
int a=1;
for(int i=0; i<_buzzcnt; i++){
buzz[i]=CreateIndexBuffer();
SetIndexBuffer(i+a, buzz[i]);
sprintf_s(ss,100,"Buzz %2d %4d", i, calcMAper(i) );
SetIndexLabel(i+a, ss);
SetIndexStyle(i+a, ds_Line, psSolid, 1, cvetradugi(i, _buzzcnt) );
}
SetIndexStyle(0, ds_Line, psSolid, 1, clRed);
SetIndexLabel(0, "----");
}
EXPORT void __stdcall OnParamsChange(){
char ss[100]={0};
int a=1;
for(int i=0; i<_buzzcnt; i++){
sprintf_s(ss,100,"Buzz %2d %4d", i, calcMAper(i) );
SetIndexLabel(i+a, ss);
}
// SetBufferShift(4, KijunSenPeriod);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool newb() {static TDateTime knw; if (Time(0)==knw) return(false); knw=Time(0); return(true); }
//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
EXPORT void __stdcall Calculate(int index){
double ph=-1,pl=99999999999999999;
int bh=0,bl=0,Barz=Bars();
if(index==0) if (!newb()) return;
if(index<Barz-5) BigMA[index]=BigMA[index+1]+Close(index);
if(index<Barz-200){
for (int j=0; j<_buzzcnt; j++){
int per=calcMAper(j);
(buzz[j])[index]= (BigMA[index]-BigMA[index+per])/per;
}
}
}