[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 197

 

Explain. I don't understand. Why the condition

int Takeprofit = 62;

pp = MarketInfo(OrderSymbol(), MODE_POINT);

if(OrderTakeProfit() - OrderOpenPrice() < Takeprofit*pp )

it works as true? Although both parts are equal!!! As you can see below.

2009.08.22 18:50:31 1999.10.11 23:43 Delta EURUSD,M1: OrderTakeProfit() - OrderOpenPrice() = 0.0062 Takeprofit*pp = 0.0062

Thank you!

 

Since you work with real numbers, you should know that 0.0062 can actually be 0.0061999 or 0.0062001.

Use normalisation.

 
OneDepo писал(а) >>

Since you work with real numbers, you should know that 0.0062 can actually be 0.0061999 or 0.0062001.

Use normalisation.

I tried normalizing Takeprofit*pp - nothing worked. Maybe both sides of the equation should be normalized?

 
001 >> :

I tried normalising Takeprofit*pp - nothing worked. Maybe both sides of the equation ( the inequality) need to be normalised?

Yes.

The second option is to work with int type, for example:

int temp = 0.5 + (OrderTakeProfit() - OrderOpenPrice())/ pp;
if ( temp < Takeprofit)
 
OneDepo писал(а) >>

Yes.

The second option is to work with int type, for example:

>> Thank you!

 

Hello!

How do I change the colour of the indicator line depending on the condition - for example, so that different ranges of bars have different colours?

The SetIndexStyle function, which is supposed to do this, does not work by setting the colour or line thickness - see figure

See example code below.

Each bar should be a different colour and thickness, but they are all just red and 2 thick.

//+------------------------------------------------------------------+
//|                                                       MinMax.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Gray

//---- buffers
double ExtMapBuffer1[];
double Val;
int ExtCountedBars=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Brown);
   SetIndexBuffer(0, ExtMapBuffer1);
   Val=Close[Bars-1];
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   

   if(Bars<=100) return(0);
   ExtCountedBars=IndicatorCounted();

   //---- check for possible errors
   if ( ExtCountedBars<0) return(-1);
   if ( ExtCountedBars>0) ExtCountedBars--;
   int    i, pos=Bars- ExtCountedBars-1; 
   Comment(Bars," ", ExtCountedBars, " ", pos); 
//---- last counted bar will be recounted
   
//----

   while( pos>=0) {
        
         if ( pos<100 && pos>0)   { SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Red); Val=1.45; }
         if ( pos<200 && pos>100) { SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,Blue); Val=1.44; }
         if ( pos<300 && pos>200) { SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,4,Yellow); Val=1.43; }
         if ( pos<400 && pos>300) { SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,5,Magenta); Val=1.42; }
             
      ExtMapBuffer1[ pos]= Val;
    
    pos--;
     }
  return(0);
  }
//+------------------------------------------------------------------+
 
stera писал(а) >>

Hello!

How do I change the colour of the indicator line depending on the condition - for example, so that different ranges of bars have different colours?

The SetIndexStyle function, which is supposed to do this, does not work by setting the colour or line thickness - see figure

See example code below.

Each step should be a different colour and thickness, but they are all just red and thickness 2.

Use additional buffers, each with their own style and colour

 
Vinin >> :

Use additional buffers, each with their own style and colour

Once initiated a similar question, and together we worked out what should have been clear :)))

SetIndexStyle when used at start honestly changes colour, but the whole buffer at once. That is, in the current chart, the buffer (line) will have the colour corresponding to the last triggered SetIndexStyle application.

 
stera писал(а) >>

Hello!

How to change the colour of the indicator line...

Look here .

 
granit77 писал(а) >>

Once initiated a similar question, and together we worked out what should have been clear :))

SetIndexStyle when used at start honestly changes colour, but the whole buffer at once. That is, in the current chart, the buffer (line) will have the colour corresponding to the colour of the last triggered SetIndexStyle application .

Thank you very much, granit77.

That's a comprehensive answer.
I suspected as much, but I couldn't believe that such a strange idea was embedded in this function.

It may be necessary to change the colour of the whole buffer for some purposes, but more practical is

But the mechanism of coloring (and changing other attributes) of some parts of the indicator.

EasyLang, for example, has it.

I will write to the developers.

Is there a more detailed description of MQL functions somewhere?

With the examples of some or other parameters?

All the parameters have to be either tested by myself or taken from third-party examples.

Reason: