Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course > Questions






Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-04-2005, 01:18 PM
forexts's Avatar
Administrator
 
Join Date: Sep 2005
Posts: 299
forexts has disabled reputation
GC Oscillator

http://www.forex-tsd.com/showpost.ph...0&postcount=23

I think this oscillator (documented in Ehlers section), is a very good exercise for this section.

In fact I think we could develop as much indicators from Ehlers as possible.

Figure 1. Easy Language Code to Compute the CG Oscillator

Inputs: Price((H+L)/2),

Length(10);



Vars: count(0),

Num(0),

Denom(0),

CG(0);



Num = 0;

Denom = 0;

For count = 0 to Length - 1 begin

Num = Num + (1 + count)*(Price[count]);

Denom = Denom + (Price[count]);

End;

If Denom <> 0 then CG = -Num/Denom;



Plot1(CG, "CG");

Plot2(CG[1], "CG1");
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 11-04-2005, 06:13 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 994
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Thumbs up It's a great example!

Quote:
Originally Posted by forexts
http://www.forex-tsd.com/showpost.ph...0&postcount=23

I think this oscillator (documented in Ehlers section), is a very good exercise for this section.

In fact I think we could develop as much indicators from Ehlers as possible.

Figure 1. Easy Language Code to Compute the CG Oscillator

Inputs: Price((H+L)/2),

Length(10);



Vars: count(0),

Num(0),

Denom(0),

CG(0);



Num = 0;

Denom = 0;

For count = 0 to Length - 1 begin

Num = Num + (1 + count)*(Price[count]);

Denom = Denom + (Price[count]);

End;

If Denom <> 0 then CG = -Num/Denom;



Plot1(CG, "CG");

Plot2(CG[1], "CG1");
Forexts,

Thank you very much for your suggestion; it's really a very good exercise.
It will be our next lesson.

At the same time the Oscillator's name starts with my name's first letters CG (Center of Gravity) (Coders' Guru)
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 07-21-2006, 03:17 AM
emjay's Avatar
Junior Member
 
Join Date: Jul 2006
Posts: 8
emjay is on a distinguished road
Cog

I do not yet have access to the Elite section, anyone care to critique my COG indicator for MQL4?

Code:
//+------------------------------------------------------------------+
//|                                                   Ehlers COG.mq4 |
//+------------------------------------------------------------------+ 
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  Red
#property indicator_color2  Blue

extern int COGPeriod = 10;

double COG[], COG1[], wrkArray[];
//+------------------------------------------------------------------+
int init()
{
   IndicatorBuffers(2);
   IndicatorDigits( MarketInfo( Symbol(), MODE_DIGITS ));
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE); 

   if( !SetIndexBuffer( 0, COG ) &&
       !SetIndexBuffer( 1, COG1 ))
      Print( "cannot set indicator buffers!" );

   SetIndexDrawBegin( 0, COGPeriod );
   SetIndexDrawBegin( 1, COGPeriod ); 

   IndicatorShortName( "Ehlers COG" );

   return(0);
}
//+------------------------------------------------------------------+
// Calculating Ehlers Center of Gravity
//+------------------------------------------------------------------+ 
// COG = -1 * (NUM / DENOM)
// NUM = the sum of [PRICE[i] * (i + 1)] from 0 to N
// DENOM = the sum of PRICE[i] from 0 to N
//   where N equals the number of periods (COGPeriod)
//         PRICE[0] equals the current bar 
//         PRICE[1] equals the previous bar
//         PRICE[n] equals the price from n bars previous
//+------------------------------------------------------------------+
int start()
{
   int i, j, limit, iWrk00; 
   int countedBars = IndicatorCounted();
   double dWrk00, num, denom;

   limit = Bars - countedBars;
   for( i = 0; i < limit; i++ )
   {
      if((i >= COGPeriod) || (limit < 10))
      { 
         num = 0;
         denom = 0;
         for( j = 0; j < COGPeriod; j++)
         {
            if(limit < 10)
               iWrk00 = i + j;
            else
               iWrk00 = i - COGPeriod + j; 
            dWrk00 = (High[iWrk00] + Low[iWrk00]) / 2;
            num = num + (1 + j) * dWrk00;
            denom = denom + dWrk00;
         }
         if(limit < 10)
            iWrk00 = i;
         else 
            iWrk00 = i - COGPeriod;
         COG[iWrk00] = -num / denom;
         if(iWrk00 > 0)
            COG1[iWrk00 - 1] = COG[iWrk00];
      }
   }

   return(0);
}
//+------------------------------------------------------------------+
It doesn't seem to be charting out for me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 07-21-2006, 10:02 AM
Administrator
 
Join Date: Sep 2005
Posts: 20,016
Blog Entries: 235
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
First COG I found inside my computer. The second indicator on the image is yours.
Attached Images
File Type: gif cog.gif (19.7 KB, 503 views)
Attached Files
File Type: mq4 Center of Gravity.mq4 (2.2 KB, 112 views)
File Type: mq4 Ehlers COG.mq4 (2.4 KB, 112 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 07-21-2006, 02:03 PM
emjay's Avatar
Junior Member
 
Join Date: Jul 2006
Posts: 8
emjay is on a distinguished road
Yes, they do look nearly identical.

And I am able to get the display now. I must have placed an invalid character somewhere while viewing in the editor.

Thanks NewDigital!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
center of gravity, cog.mq4, cg oscillator

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stochastic Oscillator newdigital Setup Questions 318 10-30-2009 05:36 PM
WESS-Oscillator McDuck Suggestions for Trading Systems 12 04-02-2007 03:43 AM
Awesome oscillator trevman Metatrader 4 0 12-15-2006 04:32 PM
Oscillator Indicator babarmughal Indicators - Metatrader 4 5 05-07-2006 09:38 AM
Oscillator 006 Expert Advisors - Metatrader 4 2 01-28-2006 05:49 PM


All times are GMT. The time now is 09:02 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.