Go Back   Traders Laboratory > Trading Resources > Trading Indicators > Coding Forum

Coding Forum Collaborate, receive help, or discuss coding related issues.

Reply
Bookmarks
del.icio.us StumbleUpon Google Digg Facebook Furl Reddit Netscape

 
LinkBack Thread Tools Display Modes Language
  #1 (permalink)  
Old 02-28-2008, 01:47 PM
turboscottomatic turboscottomatic is offline
Registered Trader

 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Help with Some Lin Reg Curve Color Coding - MQL4 to TS

Hi All,
I am hoping someone with some C or MQL4 coding savvy can help me. I have some color coding in an indicator written in MQL4 (which is supposed to be like C) that I am trying to apply to my TS indicator. I have some skill in TS indicator coding and can do that part, if someone can help me understand the MQL4 logic.

The indicator in MQL4 is 'Least Squares Moving Average' which is identical on a chart to TS 'Linear Regression Curve.' My TS version (MultiCharts, actually) is one color. The MQL4 version has a very nice 3 color appearance that I find very useful. However, I can't make heads or tails of the code. I would appreciate GREATLY if some real programmer out there can translate the color coding part of the following code into normal logic statements or pseudo-code for me. I can take it from there. I assume I"ll be able to apply it to the TS LRC indicator simply enough, if I can just understand the logic. I will be happy to share the indicator with the forum once it's done, if anyone is interested in it.

I've attached a picture of the indicator. You can see the 3 color logic I'm talking about.

Many Thanks for the help,
Scott

Here is the MQL4 code:



//+------------------------------------------------------------------+
//| |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, FX Sniper "
#property link "http://www.metaquotes.net/"

//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int width;

extern int Rperiod = 34;
extern int Draw4HowLongg = 1500;
int Draw4HowLong;
int shift;
int i;
int loopbegin;
double sum[];
int length;
double lengthvar;
double tmp ;
double wt[];
int c;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);

//---- drawing settings
SetIndexBuffer(2,ExtMapBu ffer1);
SetIndexBuffer(1,ExtMapBu ffer2);
SetIndexBuffer(0,ExtMapBu ffer3);
SetIndexBuffer(3,sum);
SetIndexBuffer(4,wt);

SetIndexStyle(2,DRAW_LINE ,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE ,STYLE_SOLID,2);
SetIndexStyle(0,DRAW_LINE ,STYLE_SOLID,2);

//---- initialization done
return(0);
}

int start()

{ Draw4HowLong = Bars-Rperiod - 5;
length = Rperiod;
loopbegin = Draw4HowLong - length - 1;

for(shift = loopbegin; shift >= 0; shift--)
{
sum[1] = 0;
for(i = length; i >= 1 ; i--)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
tmp = ( i - lengthvar)*Close[length-i+shift];
sum[1]+=tmp;
}
wt[shift] = sum[1]*6/(length*(length+1));

//========== COLOR CODING ========================= ==================

ExtMapBuffer3[shift] = wt[shift]; //red
ExtMapBuffer2[shift] = wt[shift]; //green
ExtMapBuffer1[shift] = wt[shift]; //yellow

// for(c=loopbegin;c==shift; c++)
// {
if (wt[shift+1] > wt[shift])
{
ExtMapBuffer2[shift+1] = EMPTY_VALUE;
// ObjectCreate("smiley_face ", OBJ_ARROW, 0, Time[shift], Low[shift]-Point*20);
// Print("time= ",Time[shift]);
// ObjectSet("smiley_face", OBJPROP_ARROWCODE, 242);
// ObjectSet("smiley_face", OBJPROP_COLOR , Red);
// ObjectSet("smiley_face", OBJPROP_WIDTH , 1);
// ObjectsRedraw();

//ExtMapBuffer3[shift+1] = EMPTY_VALUE;
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;

}
else if (wt[shift+1] < wt[shift])
{
ExtMapBuffer1[shift+1] = EMPTY_VALUE; //-1 red/greem tight
//ExtMapBuffer3[shift+1] = EMPTY_VALUE;

}
else
{

ExtMapBuffer1[shift+1]=CLR_NONE;//EMPTY_VALUE;
ExtMapBuffer2[shift+1]=CLR_NONE;//EMPTY_VALUE;
}

}

return(0);
}
//+------------------------------------------------------------------+
Attached Images
File Type: gif lsma pic.gif (19.1 KB, 27 views)

Reply With Quote
  #2 (permalink)  
Old 03-03-2008, 07:29 AM
turboscottomatic turboscottomatic is offline
Registered Trader

 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Re: Help with Some Lin Reg Curve Color Coding - MQL4 to TS

If anyone has been looking at this, thanks but don't bother. The color coding on this LinReg was so amazing I thought I found a grail. But when I put it on a 1 minute chart and watched it for a while, turns out it was repainting 2 bars back on reversals - thereby giving a fantasy early warning at every reversal.

Scott

Reply With Quote
The Following User Says Thank You to turboscottomatic For This Useful Post:
thrunner (03-03-2008)
  #3 (permalink)  
Old 03-03-2008, 01:34 PM
thrunner thrunner is offline
Registered Trader

 
Join Date: Feb 2007
Posts: 154
Thanks: 49
Thanked 34 Times in 17 Posts
Re: Help with Some Lin Reg Curve Color Coding - MQL4 to TS

Thanks. No price indicator can paint that reversal in real time. This is like a Zigzag or price action indicator, it won't know the price peak (HH) or trough (LL) until 2 or more bars later.
Attached Images
File Type: png Price action 2008-03-03_133150.png (12.4 KB, 18 views)

Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding for Sierra Charts mishnas Coding Forum 18 03-19-2008 03:19 PM
lomb periodogram indicator coding val2004 Coding Forum 0 09-13-2007 03:36 AM
Coding Help waveslider Coding Forum 1 08-03-2007 04:48 PM
TICK Coding Help Soultrader Coding Forum 16 05-15-2007 12:15 AM
[VSA] Coding TinGull Coding Forum 2 03-18-2007 01:05 PM


All times are GMT -4. The time now is 08:04 AM.

 


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58