Download MetaTrader 5

check the highest and lowest price live - page 2

To add comments, please log in or register
m_shafiei2006
147
m_shafiei2006  

I dont understand these parts;

   double &dblHighPriceVar, double &dblLowPriceVar

   dblHighPriceVar = EMPTY;
   dblLowPriceVar  = EMPTY;


OK, it was my code before I asked:

#property strict
#include <stdlib.mqh>
#import


extern            ENUM_TIMEFRAMES TimeFrame = PERIOD_M1;
extern datetime   inTime = D'29.04.2016 12:30:00',
                  outTime = D'29.04.2016 12:50:00';

int     inBar  = iBarShift(NULL,TimeFrame,inTime),
        outBar = iBarShift(NULL,TimeFrame,outTime-1),
        BarRange  = inBar - outBar + 1,
        MaxShift = iHighest(NULL,TimeFrame,MODE_HIGH,BarRange,outBar),
        MinShift = iLowest(NULL,TimeFrame, MODE_LOW,BarRange,outBar);

double  
         MaxPrice = iHigh(NULL,TimeFrame,MaxShift),
         MinPrice = iLow(NULL,TimeFrame,MinShift); 
         
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

if (TimeCurrent() < outTime)
{
   if (OrdersTotal() > 0)
   Comment ("YOU ALREADY HAVE POSITIONS!");
   else
   if (OrdersTotal() == 0)
   {
      if (TimeCurrent() < inTime)   
      {
         Comment (Symbol()," CHART SCAN WILL BE STARTING AT ",inTime,   
         "\n",TimeToStr((inTime-TimeCurrent()),TIME_SECONDS)," REMAINING TO SCAN ..."); 
         if (TimeCurrent() >= inTime)
         return;
      }  
   
      if (TimeCurrent() >= inTime && TimeCurrent() < outTime)
      {
         Comment (Symbol()," CHART IS SCANNING BETWEEN ",TimeToStr(inTime,TIME_DATE|TIME_SECONDS)," AND ",TimeToStr(outTime,TIME_DATE|TIME_SECONDS),
         "\n",TimeToStr((outTime-TimeCurrent()),TIME_SECONDS)," REMAING TO START ...",
         "\n","MAX PRICE : ",DoubleToStr(MaxPrice,Digits),
         "\n","MIN PRICE : ",DoubleToStr(MinPrice,Digits));
         return;
      }
   }
}


  }
//+------------------------------------------------------------------+

I need to get the minimum and maximum price on every tick and comment it on chart dynamically.

How do I change it ?

Keith Watford
Moderator
10544
Keith Watford  
m_shafiei2006:

I dont understand these parts;


OK, it was my code before I asked:

I need to get the minimum and maximum price on every tick and comment it on chart dynamically.

How do I change it ?

You were given the answer in the very first reply to your OP.

Why have you ignored it?

m_shafiei2006
147
m_shafiei2006  
GumRai:

You were given the answer in the very first reply to your OP.

Why have you ignored it?

the problem is that I have many functions that uses these variable and when I put these variable in ontick() part, it gives me error and needs these variable.

have got a solution ?

Fernando Carreiro
3579
Fernando Carreiro  
m_shafiei2006:

the problem is that I have many functions that uses these variable and when I put these variable in ontick() part, it gives me error and needs these variable.

have got a solution ?

Both GumRai and myself have given you several solutions for different variations that you have described, but you seem to be ignoring them.

First of all, you should invest some time learning about the basics of programming, before you tackle an EA or even an Indicator in MQL.

It is difficult to try explain things to you, when you still don't understand the basics  such as local and global variables, data-types, functions and parameters, passing by value or passing by reference, etc.

I suggest that you first learn the basics by learning for example some coding in "C" (because MQL is very similar). There are many free online resources (such sample code, tutorials and even videos) to learn "C".

Then once you understand those basics then you can tackle MQL again and coding for an Indicator or an EA.

Keith Watford
Moderator
10544
Keith Watford  
m_shafiei2006:

the problem is that I have many functions that uses these variable and when I put these variable in ontick() part, it gives me error and needs these variable.

have got a solution ?

Declare the variables globalscope and assign vales in OnTick()
m_shafiei2006
147
m_shafiei2006  
GumRai:
Declare the variables globalscope and assign vales in OnTick()

OK.

I thought I am allowed to assign values where I declare !

I fixed it and works now.

thanks all.

whroeder1
16529
whroeder1  
m_shafiei2006: I thought I am allowed to assign values where I declare !
Yes you are correct and you did. You can only declare once, thus assigned a value once. Therefor they never changed.
12
To add comments, please log in or register