Some mql4 coding problems

 

Hi mql4 coders

 i m trying to build an indicator that that changes colors when certain conditions are met.Below are fragment of codes that i write to implement it .

 

 
if(CloseM)
  {       
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,Red);  
  }
else {
   if(CloseN)
          {
            SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,SkyBlue);
          }
   else
        {
          SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,White);  
        }
  
   }
  
   return(0);
  }
 }

I put this code in the 'start function block' and the results is that it shows changes in colors when the conditions changes however it shows only the latest color corresponding to the latest conditions ..but i want that the previous color changes be showed permanently while also showing the lates color.. this indicator is basically design to show up as a  line that changes colors as different condition are met.

can anyone throw light on the problem? 

 

SetIndexStyle

line index    SetIndexStyle( line index   ,                                   );

 One line in different colors 

 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. https://www.mql5.com/en/forum/143853
 

Hi guyz!

i still am not clear after going thru the links given above..

1.Can i used setindexdrawbegin to solve this problem? 

2.Should i allot three buffers to three indicator colors and activate only one buffer at a time when the particular 'color' condition is met?

...or are there more possibilities?

 

Plz clarify 

 
MirTD:


Plz clarify 

A line has a start point and an end point,  if yo want 3 colours you need 3 buffers . . . 

 

bar #  5    4    3     2    1    

 

--------

         ----------

                    ------------- 

So the red and blue lines have the same value for bar 5  and the red and green lines have the same value for bar 3,   otherwise you get gaps. 

 

Raptor,

so u mean at bar 5, when both lines have the same values i.e both 'red'  and 'blue' color conditions,then there ll b no gaps?.how can we have same conditions at the same point whereas different 'color' conditions are mutually exclusive?

 
MirTD:

Raptor,

so u mean at bar 5, when both lines have the same values i.e both 'red'  and 'blue' color conditions,then there ll b no gaps?.how can we have same conditions at the same point whereas different 'color' conditions are mutually exclusive?

If you want the lines to join then where one line ends and the other line starts they are joined so obviously have the same price value . . . if you don't like this then have gaps and be happy :-)
 

Raptor

 

do u hav any three color indicator code..a very simple one tht removes those gaps? ..i try to understand freely available codes but evryone seems coding in their own way!

i even find one program which shows three color(Google) but the color sequence remains constant always-blue-green-red and the color sequence as a whole advance when new bar

is formed!..useless threecolor indicator~ i reference the NK Library also but the indicator reference custom indicator which cannot b understood as of now..so wht should i do?

How simple to code threecolor indicator in Amibroker(if u want to see i can upload chart and code of AFL)? n impossible in MQL4! 

 
MirTD:

Raptor

 do u hav any three color indicator code..a very simple one tht removes those gaps? ..i try to understand freely available codes but evryone seems coding in their own way!

Sorry but no I don't.  That doesn't mean what it may sound like,  I am not refusing to share code,  let me explain.  

I don't use Technical Indicators . . .  I never have and maybe never will,  the only exposure and experience I have of them is from trying to help other people,  so I don't have any Technical indicators of my own,  so I don't have any code to share.  

I had intended to modify the code that another user had posted to demonstrate the approach I would have taken but I just didn't get round to doing this.  I have had my head in MQL5 trying to learn some bits in the last couple of weeks.

 

Here a very simple one ....

//+------------------------------------------------------------------+
//|                                                  three_color.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
 
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Blue
//---- buffers

extern int PeriodMA = 1;



double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i,j,shift;
   static int width=1;
//----
   for(i=0; i<Bars-21; i+=30)
     {
      for(j=0,shift=i; j<11; j++,shift++)
        {
         ExtMapBuffer1[shift]=iMA(NULL,0,PeriodMA,MODE_SMA,0,PRICE_OPEN,shift);
         if(j>0 && j<10)
           {
            ExtMapBuffer2[shift]=EMPTY_VALUE;
            ExtMapBuffer3[shift]=EMPTY_VALUE;
           }
        }
     }
//----
   for(i=10; i<Bars-11; i+=30)
     {
      for(j=0,shift=i; j<11; j++,shift++)
        {
         ExtMapBuffer2[shift]=iMA(NULL,0,PeriodMA,MODE_SMA,0,PRICE_OPEN,shift);
         if(j>0 && j<10)
           {
            ExtMapBuffer1[shift]=EMPTY_VALUE;
            ExtMapBuffer3[shift]=EMPTY_VALUE;
           }
        }
     }
//----
   for(i=20; i<Bars-1; i+=30)
     {
      for(j=0,shift=i; j<11; j++,shift++)
        {
         ExtMapBuffer3[shift]=iMA(NULL,0,PeriodMA,MODE_SMA,0,PRICE_OPEN,shift);
         if(j>0 && j<10)
           {
            ExtMapBuffer1[shift]=EMPTY_VALUE;
            ExtMapBuffer2[shift]=EMPTY_VALUE;
           }
        }
     }
//----
   if(width>5) width=1;
   else width++;
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,width);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,width);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,width);
//----
   return(0);
  }
//+------------------------------------------------------------------+

 Hope it helps

 

deVries

Tnx for ur time ..but 

wht shud i say?..do u code it or find it?..anyway it doesnt matter much..well i was refering to this code in my rlier post..i google it n found it and i found it funny~!..atfirst i though i hv found a simple code

How?..the single line indicator expand n contracts like a python after swallowing meaty meal !..n the threecolor moves s a whole ..not coded to change colors when certain conditions happen..rite?..well u may hv observe it alredy~..btw m just new to mql4 n to b honest except for this EA thing here i dont see any othr advantages over AFL.here u need to allocate buffers,set index,set index to style,define n declare type variables n so on whereas AFL automatically recognised the variable type used..no need to define type!(u can compare programs written in AFL n MQL4 n how much AFL is simpler n easier!)..n theres no line gap problems in AFL~!..if Raptor n U didnt reply tht rly~..i was scouring th web whethr AB has lately efficently integrate/provided AutomaticOrder sending functions with some 3rd party etc..really~i was even thinkin to take up MQL5..s i knw it is OOP n totally diffrent fr MQL4..m a newbie here in MQL4 n wht disadvantage i ll get by takin up MQL5 now at th beginnin stage.. ~i find very few MQL4 related threecolr coded indicator program when i ggogle it!..n not helpin much eithr by this forum~..alredy frustration sets in!..wel u may hv understood th logic of th code abv posted by u here but s i said this threecolor indicator is just aesthetic in nature..how to modify this so tht color can b change depending on conditions happening?

ur guidance ll b appreciated ~Tnx 

Reason: