how can i do this? - page 2

 
meysam rahpeyma:

hi again.
i learned about my request.
i want to check last low and high of two closed currency pair (for example: 'USDCHF' and 'USDJPY').
if low and high in first currency pair less than second currency pair then draw a red bar else if low and high in first currency pair greater than second currency pair then draw a green bar.

i want to repeat it in every 1 minute.

how to do this?

USDJPY is always going to be "greater" than USDCHF

 
Mladen Rakic:

USDJPY is always going to be "greater" than USDCHF

i said for example.

 
meysam rahpeyma:

i said for example.

You are trying to compare apples with pairs (also an example)

 
Mladen Rakic:

USDJPY is always going to be "greater" than USDCHF

meysam rahpeyma:

i said for example.

As Mladen has hinted at with your 2 examples (or any 2 currency pairs), there is absolutely no point in comparing the highs and lows of different currency pairs.

 
Keith Watford:

As Mladen has hinted at with your 2 examples (or any 2 currency pairs), there is absolutely no point in comparing the highs and lows of different currency pairs.

can you write this code or not? compare for example USDCHF and USDJPY together and draw that chart.

 
i write this.
Please help me.
        
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrRed
#property indicator_color2 clrSilver


double line1[],line2[];


int OnInit()
  {
   SetIndexBuffer(0,line1);
   SetIndexBuffer(1,line2);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
   int Counted_bars=prev_calculated;
   
   for(int i = 1;i <= rates_total;i++)
     {
      double low1=iLow("USDJPY",PERIOD_M1,1)-iLow("USDCHF",PERIOD_M1,1);
      double high1=iHigh("USDJPY",PERIOD_M1,1)-iHigh("USDCHF",PERIOD_M1,1);
      if(low1<0 && high1<0){
         line1[i-1]=low1*2;
         line1[i]=high1*2;
      }else if(low1>0 && high1>0){
         line2[i-1]=low1*2;
         line2[i]=high1*2;
      }
      
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
meysam rahpeyma:
i write this.
Please help me.
        

Your code seems ok, go on.

 
meysam rahpeyma:
i write this.
Please help me.
        

What is this for?

int Counted_bars=prev_calculated;


You are counting all bars every tick

for(int i = 1;i <= rates_total;i++)

Very inefficient and you will get an array out of range - should be

for(int i = 1;i <rates_total;i++)

also rates_total may well not apply to the pair that is not the chart pair.


I don't know what the reasoning is behind your calculations but the indicator may be better placed in a separate window, otherwise the lines may be off the chart.

Also you are assigning values to only 1 buffer depending on the outcome of your calculations. A line buffer needs consecutive values in order to be drawn, so you may get blank periods if the results are oscillating around zero.

 
double low1=iLow("USDJPY",PERIOD_M1,1)-iLow("USDCHF",PERIOD_M1,1);
      double high1=iHigh("USDJPY",PERIOD_M1,1)-iHigh("USDCHF",PERIOD_M1,1);
You are checking index 1, not the relevant index.
 

how to draw my bars in chart?

and how do it in separate chart?

need to have any array?

if i need array then how to add new number to new cell of array?
Reason: