Hi everyone,
Im new to mql4 & I got some problem working with object property.
Let's say I want to access to property "PRICE1" of Rectangles of all open charts if availalble.
My code looks fine :) & have no errors but there is something wrong & It doesnt work.
I think it may be these lines:
....
for (int j=ObjectsTotal(ID[i],0,-1)-1; j>=0; j--)
{
if(ObjectType(ObjectName(j)) == OBJ_RECTANGLE)
....
attached is my code.
Could anyone help me? please
Thanks in advanced! & have a good day
Regard,
Don't over-complicate your code by creating unnecessary collections to iterate over. You can iterate over the charts using a for loop. You should also specify the exact params in the Object functions. And finally, you can use a CArrayDouble collection to dynamically add your prices to.
Example:
#property strict #include <Arrays\ArrayDouble.mqh> //--- int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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[]) { //------ CArrayDouble prices; for(long id=ChartFirst(); id>=0; id=ChartNext(id)){ int total = ObjectsTotal(id, 0, OBJ_RECTANGLE); for(int j=0; j<total; j++){ string name = ObjectName(id, j, 0, OBJ_RECTANGLE); prices.Add(ObjectGetDouble(id, name, OBJPROP_PRICE1)); } } for(int i=prices.Total()-1; i>=0; i--) Print(DoubleToString(prices[i], _Digits)); return(rates_total); } //+------------------------------------------------------------------+
Don't over-complicate your code by creating unnecessary collections to iterate over. You can iterate over the charts using a for loop. You should also specify the exact params in the Object functions. And finally, you can use a CArrayDouble collection to dynamically add your prices to.
Example:
Great! Thank you very much! :), in fact, Ive just learnt coding mlq for nearly a month!
It is so advanced to me! never knew it fefore! & I didnt know how to use library functions as well.
It takes me all day to study standard library & understand your codes, now I can get it a bit :).
Simplicity is the ultimate sophistication! You are a pro coder & very kind as well!
Thanks again & Good night! Nicholi
me, 00:00 am GMT+7
- www.brainyquote.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 everyone,
Im new to mql4 & I got some problem working with object property.
Let's say I want to access to property "PRICE1" of Rectangles of all open charts if availalble.
My code looks fine :) & have no errors but there is something wrong & It doesnt work.
I think it may be these lines:
....
for (int j=ObjectsTotal(ID[i],0,-1)-1; j>=0; j--)
{
if(ObjectType(ObjectName(j)) == OBJ_RECTANGLE)
....
attached is my code.
Could anyone help me? please
Thanks in advanced! & have a good day
Regard,