Different coloured lines

 

Hey, I'm trying to plot a custom ADX line that plots a different coloured ADX line based on DI+ > DI- or vice versa. For some reason it wont change the colour when plotting on chart, could someone give me an example on how to do that? thank you for your time.

//+------------------------------------------------------------------+
//|                                                  ImprovedADX.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   1
//--- plot ADX
#property indicator_label1  "ADX"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen, clrRed, clrGray
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- input parameters
input int      InpADXperiod=14;
//--- indicator buffers
double         ADXBuffer[],
               ADXcolor[],
               DIminBuffer[],
               DIplusBuffer[];
int            ADXhandle;               

int OnInit(){
   SetIndexBuffer(0,ADXBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ADXcolor,INDICATOR_COLOR_INDEX);
   
   if((ADXhandle=iADX(_Symbol,PERIOD_CURRENT,InpADXperiod))==INVALID_HANDLE)
      return(INIT_FAILED);
   
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]){
   if((CopyBuffer(ADXhandle,0,0,rates_total,ADXBuffer))==-1 ||
      (CopyBuffer(ADXhandle,1,0,rates_total,DIplusBuffer))==-1 ||
      (CopyBuffer(ADXhandle,2,0,rates_total,DIminBuffer))==-1) Print("Failed to copy ADX buffer: ", GetLastError());       
               
   int start = prev_calculated;
   if(prev_calculated < InpADXperiod) start = InpADXperiod;
   if(start >= rates_total) start = rates_total-1;

   for(int i=start; i<rates_total; i++){
      bool uptrend = DIplusBuffer[i]>DIminBuffer[i]; 
      bool downtrend = DIplusBuffer[i]<DIminBuffer[i];
      bool flat = DIplusBuffer[i]=DIminBuffer[i];
      
      //why does the line color not change on the chart?
      if(uptrend) ADXcolor[i] = 1;
      if(downtrend) ADXcolor[i] = 2;
      if(flat) ADXcolor[i] = 3;
      
      Print(downtrend," ", i, " ", ADXcolor[i]);
      }
  
   return(rates_total);
  }
//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.04.03
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Elmer:

Hey, I'm trying to plot a custom ADX line that plots a different coloured ADX line based on DI+ > DI- or vice versa. For some reason it wont change the colour when plotting on chart, could someone give me an example on how to do that? thank you for your time.


Different colored lines can have various meanings depending on the context in which they are used. Here are some possible examples:

  1. In charts and graphs, different colored lines or bars may represent different data sets or categories. For example, in a line graph showing the sales performance of several products over time, each product could be represented by a different colored line.

  2. In road maps and transportation systems, different colored lines may indicate different routes or modes of transportation. For example, a subway map may use different colored lines to represent different subway lines.

 
gpaspot13 #:

Don't use ChatGPT. If you don't know the answer to OP's coding problem, don't post your nonsense non-coding answer.