Hi guys, may I ask after ea find Lowerlow, how to write to store the price?
Because it will always produce new ticks, which is also means that it will always form new Lowerlow,
What I want to do is store the price when it forms the first Lowerlow, But I've been thinking about it for a long time and can't figure out how to write it, I need some help.
Not sure if I understand fully, but I think you want the value of LowerLow to persist across ticks.
The way you have defined it, the scope is limited within the if and else/if sections. The simplest change you could make is to make it global, assuming that is what you want
MqlTick Ticks[]; double Lowerlow = 0; //make global void OnTick() { double Open1 = iOpen(Symbol(),PERIOD_CURRENT,1); double Close1 = iClose(Symbol(),PERIOD_CURRENT,1); double Open2 = iOpen(Symbol(),PERIOD_CURRENT,2); double Close2 = iClose(Symbol(),PERIOD_CURRENT,2); if(Open2 > Close2 && Close1 > Open1) { if(Close2 > Open1) { Lowerlow = Close2; //use global } else if(Open1 > Close2) { Lowerlow = Close2; //use global } } }
Not sure if I understand fully, but I think you want the value of LowerLow to persist across ticks.
The way you have defined it, the scope is limited within the if and else/if sections. The simplest change you could make is to make it global, assuming that is what you want
hi R4tna, so first thing I wanna say sorry to my bad english,
I'm not a native speaker, I think u misunderstand what I mean,
what I want is I want to store the first Lowerlow price, then stop storing it,
because if I let ea keep running, then the price and ticks will goes different,
so it might have a new Lowerlow, and the price will change to the newest Lowerlow price.
I've already try my best to explain, but not sure u understand or not.
hi R4tna, so first thing I wanna say sorry to my bad english,
I'm not a native speaker, I think u misunderstand what I mean,
what I want is I want to store the first Lowerlow price, then stop storing it,
because if I let ea keep running, then the price and ticks will goes different,
so it might have a new Lowerlow, and the price will change to the newest Lowerlow price.
I've already try my best to explain, but not sure u understand or not.
Ok you could try something like this - initialize with a negative value, and stop changing it once it is positive (assigned)
Just an example - adjust as needed
//+------------------------------------------------------------------+ //| 431185-StorePrice.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" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ MqlTick Ticks[]; double Lowerlow = -1; //make global //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { double Open1 = iOpen(Symbol(),PERIOD_CURRENT,1); double Close1 = iClose(Symbol(),PERIOD_CURRENT,1); double Open2 = iOpen(Symbol(),PERIOD_CURRENT,2); double Close2 = iClose(Symbol(),PERIOD_CURRENT,2); if((Open2 > Close2 && Close1 > Open1) && (Lowerlow < 0)) { if(Close2 > Open1) { Lowerlow = Close2; //use global } else if(Open1 > Close2) { Lowerlow = Close2; //use global } } } //+------------------------------------------------------------------+
You are running that code on every tick — why? The prices quotes for previous bars will not change until the current bar is closed and a new on is formed. Checking them on every tick is redundant.
So, detect when a new bar is formed and update and check your values only then, and if needed, then store those values, either in globally scoped variables or in static variables.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys, may I ask after ea find Lowerlow, how to write to store the price?
Because it will always produce new ticks, which is also means that it will always form new Lowerlow,
What I want to do is store the price when it forms the first Lowerlow, But I've been thinking about it for a long time and can't figure out how to write it, I need some help.