Forex Factory
  • Login

  • Username: Password:
  • 11:46pm

  • Search
  • Home

  • Forums

  • Trades

  • Calendar

  • News

  • Market

  • Brokers

Options

Search
Search
Search

Subscribe to Thread

Bookmark Thread

First Page First Unread Last Page Last Post

Printable Version

Similar Threads

update MA indicator to use two colors for up and down 3 replies

Alternating Colors 5 replies

list of colors? 4 replies

  • Platform Tech
  • /
  • Reply to Thread
  • 61

Dynamic colors?

  • Last Post
  • First Unread
  •  
  • Page 1 23456 8
  •  
  • Post# 1
  • Quote
  • First Post: Jan 25, 2009 12:28am
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
I've been trying to develop some piece of code which allows me to change the color based on a specific value.

Inserted Code
      int RedValue = 255 * Ratio;
      int GreenValue = 255 * (1 - Ratio);

      color LineColor = C'RedValue,GreenValue,000';
There's something in the documentation referring to this:

Quote

// symbol constants C'128,128,128' // gray
So, how do I go about making the colors variable within an indicator/EA?
  • Post# 2
  • Quote
  • Jan 25, 2009 2:34am | Edited at 7:52am
  • lohikeitto
    Joined Nov 2008 | 40 Posts | Status: Member
Hi Ronald,

I just wrote a small script to test.

It seems that C'XXX,XXX,XXX' format works, but doesn't allow variables.
So I think you'd better calculate color value (e.g. 12345678) from each RGB values.

I tested several combinations and recorded the results in the code.
(Lines that is commented out)

It won't take so long for you to figure out the formula to calculate.


PHP Code:
//+------------------------------------------------------------------+
//| DynamicColor_Script
//+------------------------------------------------------------------+

int i;
int Dir;

//+------------------------------------------------------------------+
//| init
//+------------------------------------------------------------------+
int init()
{
   return(
0);
}
//+------------------------------------------------------------------+
//| deinit
//+------------------------------------------------------------------+
int deinit()
{
   
ObjectsDeleteAll();
   return(
0);
}

//+------------------------------------------------------------------+
//| start
//+------------------------------------------------------------------+
int start()
{
   
i=0;
   
Dir = 0;   
   while( !
IsStopped() )
   {
      
int RedValue = 255 - i;
      
int GreenValue = 255 - RedValue;

      
//color Color = C'RedValue,GreenValue,000'; // returned value is 0 (not working)
      //color Color = C'128,128,128'; // returned value is 8421504
      //color Color = Red;  // returned value is 255
      //color Color = C'116,213,082'; // returned value is 5428596 (random)
      //color Color = C'000,000,000'; // returned value is 0
      //color Color = C'255,255,255'; // returned value is 16777215 (=(256^3)-1)
      //color Color = C'255,255,000'; // returned value is 65535(=(256^2)-1)
      //color Color = C'255,254,000'; // returned value is 65279 (65535-256)
      //color Color = C'255,000,255'; // returned value is 16711935(=(256^3)-1 - 255*256)
      //color Color = C'255,000,254'; // returned value is 16646399 (16711935 - 65536(=256^2))
      //color Color = 12345678;
      //color Color = RedValue*GreenValue;

      //color Color = C'001,000,000'; // Color = 1;
      //color Color = C'002,000,000'; // Color = 2;
      //color Color = C'001,001,000'; // Color = 257;
      //color Color = C'001,002,000'; // Color = 513; =R(1) + G(2)*256 + B(0)*256*256
      //color Color = C'001,001,001'; // Color = 65793; =257 + B(1)*256^2

      
color Color = RGB(RedValue, GreenValue, 0);

      
int BarsInWindow = WindowBarsPerChart(); 

      
double PriceMax = WindowPriceMax();
      
double PriceMin = WindowPriceMin();

      
string ObjName = "ColorRect";
      if(
ObjectFind(ObjName) > -1) ObjectDelete(ObjName);
      
ObjectCreate(ObjName,OBJ_RECTANGLE,0,Time[ 0 ],PriceMax-((PriceMax-PriceMin)/2), Time[ BarsInWindow ],PriceMin); 
      
ObjectSet(ObjName,OBJPROP_COLOR,Color);

      
Sleep(10);

      if(
i==255) Dir = 1;
      if(
i==0) Dir = 0;

      if(
Dir == 0) i++;
      if(
Dir == 1) i--;
      
Comment("Curdir = "+Dir+" / i = "+i+" / Color = "+Color+" / RedValue"+RedValue+" / GreenValue"+GreenValue);
   } 
// while
   
   
return(0);
}

//+------------------------------------------------------------------+
//| RGB
//+------------------------------------------------------------------+
color RGB(int R, int G, int B)
{
   
int RGB = MathMin(255,MathAbs(R))+256*MathMin(255,MathAbs(G))+256*256*MathMin(255,MathAbs(B));

   return(
RGB);
} 
  • Post# 3
  • Quote
  • Jan 25, 2009 3:26am
  • mladen
    Joined Apr 2007 | 26 Posts | Status: ...
Something like this (the 256*256 left for clarity)
PHP Code:
color rgb(int red,int green,int blue)
{
   return(
red+256*green+256*256*blue);
} 
if red,green and blue are not checked for maximum values before the call to the function, then the function should be:
PHP Code:
color rgb(int red,int green,int blue)
{
 return(
MathMin(255,red)+256*MathMin(255,green)+256*256*MathMin(255,blue));
} 
  • Post# 4
  • Quote
  • Jan 25, 2009 7:58am
  • lohikeitto
    Joined Nov 2008 | 40 Posts | Status: Member
mladen's formula is perfect.
So I modded my code above.

MathAbs for minus value is added, but it will be unnecessary because we usually check the values before sending it to the function.
  • Post# 5
  • Quote
  • Jan 25, 2009 9:27am
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
Thanks for the help guys. The variable color part now works. Hopefully I can complete the rest of this indi.
  • Post# 6
  • Quote
  • Jan 25, 2009 9:47am
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
Ok, this is really frustrating me:

Why is Ratio always returning 0 at the bold line?


Inserted Code
//+------------------------------------------------------------------+
//|                              Support and Resistance Heat Map.mq4 |
//|                                  Copyright © 2009, Ronald Raygun |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Ronald Raygun"
#property link      ""

#property indicator_chart_window
//---- input parameters

extern double    Multiplier = 2;
extern double    MaxPriceUsed = 0;
extern double    MinPriceUsed = 0;
extern int       MaxBars = 0;

double Ratio = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for (int j = ObjectsTotal(); j >= 0; j--) {
   string OriginalName = ObjectName(j);  
   if(0 == StringFind(OriginalName, StringConcatenate("S/R EA: ", Symbol(), " ", Period()))) {
      ObjectDelete(ObjectName(j));
   }
   }  
   ObjectDelete("StartingBar");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----



double MaxPrice;
double MinPrice;
int BarsUsed;

if(MaxPriceUsed == 0) MaxPrice = WindowPriceMax();
else
MaxPrice = MaxPriceUsed;

if(MinPriceUsed == 0) MinPrice = WindowPriceMin();
else
MinPrice = MinPriceUsed;

if(MaxBars == 0) BarsUsed = WindowBarsPerChart();
else
BarsUsed = MaxBars;


ObjectDelete("StartingBar");
ObjectCreate("StartingBar", OBJ_VLINE, 0, Time[BarsUsed], 0);
ObjectSet("StartingBar", OBJPROP_COLOR, Aqua);
ObjectSet("StartingBar", OBJPROP_STYLE, STYLE_DASH);

int CrossCount = 0;
int CountsCrossed = 0;
Ratio = 0;
   
   for (int i = 0; i < ((MaxPrice - MinPrice) / Point); i ++) {
      ObjectCreate(StringConcatenate("S/R EA: ", Symbol(), " ", Period(), " ", MinPrice + (i * Point)), OBJ_HLINE, 0, 0, MinPrice + (i * Point));


         for (int k = 0; k < BarsUsed; k++) {
         if(High[k] >= (MinPrice + (i * Point)) && Low[k] <= (MinPrice + (i * Point)) ) CrossCount++;
         }
      CountsCrossed = CrossCount;

      
      Ratio = CountsCrossed / BarsUsed * Multiplier;
      Print("Ratio: ", Ratio);
      Print("CountsCrossed: ", CountsCrossed);
      Print("BarsUsed: ", BarsUsed);
      if(Ratio > 1) Ratio = 1;
      int RedValue = 255 * Ratio;
      int GreenValue = 255 - RedValue;

      color LineColor = (RedValue + GreenValue * 256);
      ObjectSet(StringConcatenate("S/R EA: ", Symbol(), " ", Period(), " ", MinPrice + (i * Point)), OBJPROP_COLOR, LineColor);
      ObjectSet(StringConcatenate("S/R EA: ", Symbol(), " ", Period(), " ", MinPrice + (i * Point)), OBJPROP_STYLE, STYLE_DOT);
      Ratio = 0;     
      CrossCount = 0;
      }
   
   

   
//----
   return(0);
  }
//+------------------------
  • Post# 7
  • Quote
  • Jan 25, 2009 12:57pm
  • lohikeitto
    Joined Nov 2008 | 40 Posts | Status: Member
Although I'm not sure what you really want to do,
isn't this nearly what you want ?

PHP Code:
//+------------------------------------------------------------------+
//|                              Support and Resistance Heat Map.mq4 |
//|                                  Copyright c 2009, Ronald Raygun |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright c 2009, Ronald Raygun"
#property link      ""

#property indicator_chart_window
//---- input parameters

extern double    Multiplier = 2.0;
extern double    MaxPriceUsed = 0.0;
extern double    MinPriceUsed = 0.0;
extern int       MaxBars = 0;
extern int       Step = 5; // value to control roughness (to reduce hline-step)

double Ratio = 0.0;

int DQ_ADJUST []  = { 0 , 0 , 1 , 10 , 1 , 10 , 100 };
int DQADJ;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   
DQADJ = DQ_ADJUST [ Digits ]; // DQADJ is adjustment for deci-quotes (3-5 digits) brokers

   
start();
   return(
0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
for (int j = ObjectsTotal(); j >= 0; j--){
   
string OriginalName = ObjectName(j);  
   if(
0 == StringFind(OriginalName, StringConcatenate("S/R EA: ", Symbol(), " ", Period()))) {
      
ObjectDelete(ObjectName(j));
   }
   }  
   
ObjectDelete("StartingBar");
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   
int counted_bars=IndicatorCounted();

   
double MaxPrice;
   
double MinPrice;
   
int BarsUsed;

   if(
MaxPriceUsed == 0) MaxPrice = WindowPriceMax();
   else 
MaxPrice = MaxPriceUsed;

   if(
MinPriceUsed == 0) MinPrice = WindowPriceMin();
   else 
MinPrice = MinPriceUsed;

   if(
MaxBars == 0) BarsUsed = WindowBarsPerChart();
   else 
BarsUsed = MaxBars;

   
ObjectDelete("StartingBar");
   
ObjectCreate("StartingBar", OBJ_VLINE, 0, Time[BarsUsed], 0);
   
ObjectSet("StartingBar", OBJPROP_COLOR, Aqua);
   
ObjectSet("StartingBar", OBJPROP_STYLE, STYLE_DASH);

   
int Roughness = DQADJ*Step;

   
double PriceStep = ( (MaxPrice - MinPrice) / Point )/Roughness;   

   for (
int k=0; k < BarsUsed; k++)
   {
      
int CrossCount = 0;
      
Ratio = 0.0;

      for (
int i=0; i<PriceStep; i++)
      {
         
double Price_i = MinPrice + (i *Roughness * Point);
         
string ObjName = StringConcatenate("S/R EA: ", Symbol(), " ", Period(), " ", D2STR(Price_i));
         
ObjectCreate(ObjName, OBJ_HLINE, 0, 0, Price_i);
         
         if(
High[k] >= Price_i && Low[k] <= Price_i ) CrossCount++;

         
double CC = CrossCount*Step;
         
double BU = BarsUsed;

         
Ratio = CC / BU * Multiplier;
         Print(
"Ratio: ", DoubleToStr(Ratio,2));
         Print(
"CrossCount: ", CrossCount);
         Print(
"BarsUsed: ", BarsUsed);

         
double d_RedValue = 255 * Ratio;
         
int RedValue = d_RedValue;
         if(
Ratio > 1) RedValue = 255;
      
         
int GreenValue = 255 - RedValue;

         
color LineColor = (RedValue + GreenValue * 256);
         
ObjectSet(ObjName, OBJPROP_COLOR, LineColor);
         
ObjectSet(ObjName, OBJPROP_STYLE, STYLE_DOT);
      }
   }
   
   return(
0);
}

//+------------------------------------------------------------------+
//| D2STR
//+------------------------------------------------------------------+
string D2STR(double Price)
{
   return( 
DoubleToStr(Price,Digits) );
} 
  • Post# 8
  • Quote
  • Jan 25, 2009 4:29pm
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
Thank you for your help lohikeitto.

What I'm trying to do is develop some sort of indicator which can help me automatically determine s/r. The way I'm doing this is by counting how many bars--wicks included--cross through a specific price. The more bars that cross through a specific price, the more red that particular price gets, the stronger the support/resistance.

Something similar to the chart below, but with more colors obviously.
Attached Image (click to enlarge)
Click to Enlarge

Name: sr heatmap.gif
Size: 30 KB
  • Post# 9
  • Quote
  • Jan 25, 2009 11:52pm | Edited Jan 26, 2009 12:06am
  • lohikeitto
    Joined Nov 2008 | 40 Posts | Status: Member
Ok, Here you go Ronald.

Basically, It's the same thing as your original code.
I just modded some processing of double value.

The problem of this indicator is .... you can't see the price on the right side of the chart
Attached Image (click to enlarge)
Click to Enlarge

Name: rr_heatmap.gif
Size: 25 KB
Attached File
File Type: mq4 RR_Support and Resistance Heat Map.mq4   4 KB | 322 downloads
  • Post# 10
  • Quote
  • Jan 26, 2009 8:10am
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
Thank you for your help lohikeitto.

Here's how I'm using this type of heatmap:

The idea is that red zones are ranging, and green zones are trending. Whenever the price is in a green zone, I know it's safe to trade. What I need to figure out is what multiplier value to use. Thanks to your help, I was able to capture that short trade 10 mins ago.
Attached Image (click to enlarge)
Click to Enlarge

Name: sr heatmap.gif
Size: 31 KB
  • Post# 11
  • Quote
  • Jan 26, 2009 8:11am
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
This is 3 mins after I got out of that trade.

I'm sure you understand the potential I see in this indicator concept.
Attached Image (click to enlarge)
Click to Enlarge

Name: sr heatmap2.gif
Size: 30 KB
  • Post# 12
  • Quote
  • Jan 26, 2009 9:11am
  • lohikeitto
    Joined Nov 2008 | 40 Posts | Status: Member
Yes, It will be useful, not only beautiful continuous tone.

Although I don't trade 1min chart and don't trade manually,
It will visually help to confirm breakout on longer timeframe also.

(I added step variable because price step become too many for longer timeframe or zoom-outed chart. It freezes my MT4.)

If you can find favorable multiplier value, I think it's possible to make it automated.
  • Post# 13
  • Quote
  • Jan 26, 2009 12:44pm
  • Willowgal
    Joined Sep 2008 | 506 Posts | Status: Member
Quoting Ronald Raygun
This is 3 mins after I got out of that trade.

I'm sure you understand the potential I see in this indicator concept.
That is cool ...and it looks useful as well !

I wish I could code
  • Post# 14
  • Quote
  • Jan 27, 2009 8:40am
  • CanuckCT
    Joined Oct 2007 | 1,049 Posts | Status: Bike now indoors for winter...grrr
So Ron....if I'm understanding this...and I have not seen it much live yet.....this is a dynamically changing breakout zone?
Cheers
CanuckCT
  • Post# 15
  • Quote
  • Jan 27, 2009 3:52pm
  • CanuckCT
    Joined Oct 2007 | 1,049 Posts | Status: Bike now indoors for winter...grrr
I'm interested in what is happening on M2...so I apply a multiplier of 2. Don't know if this is what you intended.

Here is my chart....could have bought the breakout at 117.30 and made 20+pips....and it's ugly right now re this ranging afternoon market. You've now have my attention re this...sorry I can't contribute anything to the programming.

I imagine you are likely working on an EA to monitor this. Interesting for sure.

Cheers
CanuckCT
Attached Image (click to enlarge)
Click to Enlarge

Name: ej.gif
Size: 44 KB
  • Post# 16
  • Quote
  • Jan 28, 2009 8:11pm
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
Quoting CanuckCT
So Ron....if I'm understanding this...and I have not seen it much live yet.....this is a dynamically changing breakout zone?
Cheers
CanuckCT
More or less.

As I see it:
  1. If price is in green: Trending
  2. If price is in red: Ranging.
EA is a long work in progress. If you increase the multiplier to ~10 or so, you'll see clearly defined zones.

The EA would not only see the above red zone, but the mini zones below that. I'm still working on some solid rules for this program/system. Maybe we can work on development jointly for this?

The thing about this indicator is that it uses the bars between the vertical aqua line and the present to calculate s/r. By default, the indicator will use all the bars and prices it sees on your screen for its calculations. So, one region could be red when you zoom in, but when you zoom out, it turns green. That's something which needs fixing.

The example below is a beautiful rendition of the concept.
Attached Image (click to enlarge)
Click to Enlarge

Name: sr heatmap2.gif
Size: 33 KB
  • Post# 17
  • Quote
  • Jan 29, 2009 7:13am
  • CanuckCT
    Joined Oct 2007 | 1,049 Posts | Status: Bike now indoors for winter...grrr
I've looked at the code...but I'm not much of a programmer...what does this look at to create the heatmap....

Do you see it creating historical levels of S & R based on data from a dynamically changing historical period...if that even makes sense.

Still trying the think conceptually about what you are trying to capture.

I'd like to help....days are busy for me....so PM me and we can arrange a time to chat.

Cheers
CanuckCT
Attached Image (click to enlarge)
Click to Enlarge

Name: eu-heatmap-wide.jpg
Size: 380 KB
  • Post# 18
  • Quote
  • Jan 29, 2009 9:09am
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
For the benefit of everyone else, here is how the indicator is supposed to work.


Figure out the range of bars, and the price range to be used. (Default:
  1. Bars = # bars in window
  2. Upper Price = Max Price in Window
  3. Lower Price = Min Price in Window)
Here's how the indi works
  1. For every price, count the number of bars which cross it.
  2. The number of bars crossed is then divided by the number of total bars. The multiplier increases the number of bars crossed, thus raising the ratio.
  3. The ratio is then multiplied against 255 (total amount of colors possible using the red)
  4. The green value is 255 - (the red value)
  5. The number remaining is then the value of the color used.
Example:
Price: 1.30000
Total bars: 500
Bars Crossed: 200
Multiplier: 1

For the current price being checked (1.30000), 200 of the 500 bars cross that particular price, for a ratio of 0.40. That ratio is then multiplied by 1, which equals 0.40, and then that is multiplied against 255 and rounded to the nearest integer. So red is 102, and green is (255 - 102) = 153.

The color value used is therefore: 39270, which is a light orange or thereabouts.


Any questions?

Now you should know how it works, and with that knowledge in mind, it's just a matter of optimizing it properly or refining it so it optimizes itself.


S/R is probably a bit of an extended truth, but as I see it, it shows me concentrations of ranging prices. The support resistance concept applies more to the present than the past. Yes, if the ratio for a specific price changes, then the color at that specific price will change. As for the dynamic s/r calculations, it's definitely showing me historical price ranges where there was trending, and where there was ranging. So, if the price is in a red zone, there was plenty of fighting amongst the bulls and the bears until the price breaks into a green zone. Then either the bulls or the bears are in control until the next red zone.

This looks to me a potential breakout style trading system. Early this morning (2am EST) I saw a solid red block on my chart with an almost instantaneous change to bright green below the price, and some orangish-red patterns above that solid red block. Guess where I thought the price was going to go? Short. And about 10 minutes later, after those solid red zones were created, the price broke out short just as I predicted.

The indi seems to be working just as I had designed it to work. The trading system which relies on this indicator is what needs refining.
  • Post# 19
  • Quote
  • Jan 29, 2009 5:52pm
  • eegle
    Joined Aug 2005 | 76 Posts | Status: eegle
Quoting Ronald Raygun
For the benefit of everyone else, here is how the indicator is supposed to work.


Figure out the range of bars, and the price range to be used. (Default:[list][*]Bars =...
Looks very interesting...any way we can help?

Eegle
  • Post# 20
  • Quote
  • Jan 29, 2009 7:15pm
  • Ronald Raygun
    Joined Jul 2007 | 4,248 Posts | Status: 22 y/o Investor/Trader/Programmer
See if you guys can come up with a mechanical way to trade using that indi. (If price crosses from red to lime, open trade) that sort of thing.
Thread Tools Search this Thread
Show Printable Version Show Printable Version
Email This Thread Email This Thread
Search this Thread:

Advanced Search

  • Platform Tech
  • /
  • Dynamic colors?
  • Reply to Thread
    • Page 1 23456 8
1 trader viewing now
  • More

©2013 Forex Factory, Inc. / Terms of Use / Privacy Policy

Forex Factory® is a registered trademark.

Connect

  • Facebook
  • Twitter
  • RSS

Company

  • About FF
  • FF Blog
  • Careers at FF
  • Advertising
  • Contact FF

Products

  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer

Website

  • Homepage
  • Search
  • User Guide
  • Member List
  • Online Now
  • Report a Bug