trying to draw horizontal line for opening price of range

 

hey there,

i am trying to work out how to draw a line on the opening price of a range i have defined in my EA.

I am able to draw the high of the range in green, the low of the range in red... but i cant figure out how to draw the actual opening price

so i understand the concept

if the lastTick.time is bigger or equal to the start of the range and if the lastTick.time is smaller than the end of the range we are inside the range
Then store the high of the range in range.high using the last ask price that is the highest
Then store the low of the range in range.low using the last bid price that is the lowest

but how do u store only the first opening price of the range without that price move every time there is a new tick?


 //range calculation 
   if(lastTick.time >= range.start_time && lastTick.time <  range.end_time){ //inside range

      //new high
      if(lastTick.ask > range.high){     //if the last price is high that the range high
         range.high = lastTick.ask;      // store the highest price in range.high
         DrawObjects();                  // draw the high
      }
      //new low
      if(lastTick.bid < range.low){      //if the last price is lower that the range low
         range.low = lastTick.bid;       // store the lowest price in range.low
         DrawObjects();                  // draw the low
      }

I tried


      //range open
      range.range_open = lastTick.ask; 
         DrawObjects();

but with this my open line moves everytime theres a new tick... which also makes sense cause lastTick is the most recent tick and price is always moving using that

Can you give me some advice?

Kind regards

 
pebs85:

hey there,

i am trying to work out how to draw a line on the opening price of a range i have defined in my EA.

I am able to draw the high of the range in green, the low of the range in red... but i cant figure out how to draw the actual opening price

so i understand the concept

if the lastTick.time is bigger or equal to the start of the range and if the lastTick.time is smaller than the end of the range we are inside the range
Then store the high of the range in range.high using the last ask price that is the highest
Then store the low of the range in range.low using the last bid price that is the lowest

but how do u store only the first opening price of the range without that price move every time there is a new tick?


I tried


but with this my open line moves everytime theres a new tick... which also makes sense cause lastTick is the most recent tick and price is always moving using that

Can you give me some advice?

Kind regards

if you want to store opening price use this 

//declare global variable 

double openprice ;

void OnInit()
{openprice = 
lastTick.Bid ;}

void OnTick()
{
 //Your code logic here.


}
 
Chioma Obunadike #: if you want to store opening price use this 
Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), 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. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.