Download MetaTrader 5

Always search Two Bars in Five Bars _ and print this...

To add comments, please log in or register
microhyd
28
microhyd  

Hello all! :)

I need loop for this, it is strong to me...

I want to find the range for the last two bars and search for 5 bars

And get the result in print, please check picture for understanding.

better to explain I do not know, so I believe it will be understandable from picture.


I need this results in print, this is solution for me.


Start loop:

Bar[0] + Bar[1]    ; Print range

Bar[1] + Bar[2]    ; Print range

Bar[2] + Bar[3]    ; Print range

Bar[3] + Bar[4]    ; Print range   

Bar[4] + Bar[5]    ; Print range   


End loop, 5 bars are scanned ! 

123


Thank you very much for replies! :)


micro

whroeder1
17125
whroeder1  
If you know how to get the high/low of each bar, you know how to get the range of each bar and thus the sum of each pair. Do it.

You haven't stated a problem. Show us your attempt (using CODE button) and state the nature of your problem.
          No free help
          urgent help.

microhyd
28
microhyd  
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
double diff = 0;
  for ( int i = 0 ; i <= 5 ; i++ )
   {
   // This code return range for every bar, per last 5 bars
   diff = NormalizeDouble( (High[i] - Low[i]) * 10000 , 1);
   

   
   // But I need sumary (bar[0]+bar[1] and print) && (bar[1]+bar[2] and print) && (bar[2]+bar[3] and print) && (bar[3]+bar[4] and print) && (bar[4]+bar[5] and print)
   // I do not know how to do it
   // So, sumary all 2 bars in 5 bars and loop for this.
   // otherwise I can not explain it
   //screen top describes the question
   Print(diff);
   }
   
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {


         
         
   return(0);
  }
//+------------------------------------------------------------------+
SanjayBalraj
48
SanjayBalraj  
microhyd:

Per Mr whroeder, don't ever perform trading logic within the OnInit function

SanjayBalraj
48
SanjayBalraj  
microhyd:

Hello all! :)

I need loop for this, it is strong to me...

I want to find the range for the last two bars and search for 5 bars

And get the result in print, please check picture for understanding.

better to explain I do not know, so I believe it will be understandable from picture.


I need this results in print, this is solution for me.


Start loop:

Bar[0] + Bar[1]    ; Print range

Bar[1] + Bar[2]    ; Print range

Bar[2] + Bar[3]    ; Print range

Bar[3] + Bar[4]    ; Print range   

Bar[4] + Bar[5]    ; Print range   


End loop, 5 bars are scanned ! 



Thank you very much for replies! :)


micro

void PrintBars(int num_bars)
  {
   for(int i=0;i<num_bars-1;i++)
     {
      int r1 = (int)round((High[i]-Low[i])/_Point);
      int r2 = (int)round((High[i+1]-Low[i+1])/_Point);
      printf("range[%d] = %d, range[%d] = %d, sum = %d",i,r1,i+1,r2,r1+r2);
     }
  }
whroeder1
17125
whroeder1  
SanjayBalraj: Per Mr whroeder, don't ever perform trading logic within the OnInit function

Yep

Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent and prices are valid.
microhyd
28
microhyd  

Great thanks to all, I already have it! :)
Special thanks for Petr Nosek for making a script for me!

microhyd
28
microhyd  
SanjayBalraj: Per Mr whroeder, don't ever perform trading logic within the OnInit function

whroeder1
:

Yep

Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:

  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValueTimeCurrent and prices are valid.

Yes and I know how to use features :)

At the init, I write the code just so that it can be loaded once only after the compilation.

Then I check Print ("...");

When the code is working, it goes to start ()


But thank you for the alert :)

To add comments, please log in or register