| / | Forum |
|
devilian1899
2007.08.10 09:35
Hello, I need some advice, I want to make an EA using this center of gravity indicator.
I want to use it as a function so I could call it anywhere in my EA. I'm a newbie in programmer's world, and I find some difficulties in it. Please someone help me, thank you. //+------------------------------------------------------------------+ //| Center of Gravity.mq4 | //+------------------------------------------------------------------+ #property copyright "Copyright 2002, Finware.ru Ltd." #property link "http://www.finware.ru/" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red extern int Per=10; extern int CountBars=300; //---- buffers double val1[]; double val2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- indicator line IndicatorBuffers(2); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,val1); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,val2); //---- return(0); } //+------------------------------------------------------------------+ //| Center of Gravity | //+------------------------------------------------------------------+ int start() { if (CountBars>=Bars) CountBars=Bars; SetIndexDrawBegin(0,Bars-CountBars+Per+1); SetIndexDrawBegin(1,Bars-CountBars+Per+1); int i,cnt,counted_bars=IndicatorCounted(); double value1,sum,sum1; //---- if(Bars<=38) return(0); //---- initial zero if(counted_bars<Per) { for(i=1;i<=0;i++) val1[CountBars-i]=0.0; for(i=1;i<=0;i++) val2[CountBars-i]=0.0; } //---- i=CountBars-Per-1; while(i>=0) { sum = 0.0; for (cnt=0; cnt<=Per-1; cnt++) { sum = sum + (High[i+cnt]+Low[i+cnt])/2; } sum1=0.0; for (cnt=0; cnt<=Per-1; cnt++) { sum1=sum1+((High[i+cnt]+Low[i+cnt])*(cnt+1)/2); } value1=sum/sum1; val1[i]=value1; if (i>0) val2[i-1]=value1; i--; } return(0); } //+------------------------------------------------------------------+ |
|
Interview with Tai Elliott (MiltonWaddams) At present, I'm interested more in something which has proven results over a long period without any intervention, rather than an EA which requires frequent optimization. |
|
hansjlachmann
2009.10.07 00:50
Hi, i have implemented the Center of Gravity indicator into a function that can be used in a EA or Script. Please see attached file for example.... kind regards Hans |
|
TuTBaluT
2009.10.07 11:35
If you have it as an indicator, you could use the "iCustom" function to retrieve data from your indicator. |
|
hansjlachmann
2009.11.27 15:53
|