Download MetaTrader 5
To add comments, please log in or register
Publish your programs in the Market. Make money with your knowledge!
mci
11
mci 2014.02.19 20:08 

Hi,

I want to create a HLine with the close price of the current pair. After that I want to change the value of the Horizontal Line by moving it up or down. And it should stay there no mater if I change the time frame or the pair.

My problem is, that if I change the pair, the Horizontal Line does not reset to the current price, but it keeps the price from the pair before. Additionally I don't deinit() the Object, because it would always reset to the current Close. As I mentioned before... I want to keep the changed value, no matter what time frame I am and no matter if I change to another currency pair.

What am I doing wrong?

int init(){
   ObjectCreate("myHLineStop", OBJ_HLINE , 0, Time[0], Close[0]);
   ObjectSet("myHLineStop", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("myHLineStop", OBJPROP_COLOR, Red);
   ObjectSet("myHLineStop", OBJPROP_WIDTH, 0);
   
   return(0);
}

}

I check the current value of my HLine by using ObjectGet in the start() function.

ObjectGet("myHLineStop", OBJPROP_PRICE1);


Thank you in advance.

whroeder1
13644
whroeder1 2014.02.19 20:23  

mci: I want to create a HLine with the close price of the current pair.

And it should stay there no mater if I change the time frame or the pair.

My problem is, that if I change the pair, the Horizontal Line does not reset to the current price,

  1. Make up your mind "stay there on change of time frame or the pair" vs "does not reset to the current price,"
  2. You can only create an object once, that is why it doesn't move. You would know that had you bothered to check your return codes: What are Function return values ? How do I use them ? - MQL4 forum
  3. Either delete it and recreate it, or move it, or change the price. See my HLine/Tline code
Keith Watford
Moderator
7990
Keith Watford 2014.02.19 21:11  
mci:

Hi,

I want to create a HLine with the close price of the current pair. After that I want to change the value of the Horizontal Line by moving it up or down. And it should stay there no mater if I change the time frame or the pair.

My problem is, that if I change the pair, the Horizontal Line does not reset to the current price, but it keeps the price from the pair before. Additionally I don't deinit() the Object, because it would always reset to the current Close. As I mentioned before... I want to keep the changed value, no matter what time frame I am and no matter if I change to another currency pair.

What am I doing wrong?


}

I check the current value of my HLine by using ObjectGet in the start() function.


Thank you in advance.


As you contradict yourself, it is impossible to know exactly what you are asking.

However, I suspect that you DO want the line to change when changing the chart symbol

Not tested

string CurrentSymbol; //Variable declared on Global Scope

int init(){
   CurrentSymbol =Symbol();
   ObjectCreate("myHLineStop", OBJ_HLINE , 0, Time[0], Close[0]);
   ObjectSet("myHLineStop", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("myHLineStop", OBJPROP_COLOR, Red);
   ObjectSet("myHLineStop", OBJPROP_WIDTH, 0);
   
   return(0);
}

int start()
   {
   if(CurrentSymbol!=Symbol())
      {
      CurrentSymbol=Symbol();
      ObjectMove("myHLineStop",0,Time[0],Close[0]);
      }
   
   ObjectGet("myHLineStop", OBJPROP_PRICE1);
   
   }
mci
11
mci 2014.02.19 22:05  

Thank you for the fast response.

Yes, you are right. Just to clear it up. I meant, that I want the HLine to stay where I have moved it, no matter what timeframe I switch. It shouldn't matter if I switch between 15M or 1H on the EURUSD Chart. The HLine should be at the position, where I have moved it f.e: 1,54000

The other thing is. If I change the currency pair to f.e. to GBPUSD then I would like to have a new HLine that I can move around and put it f.e. at 1,6678. When switching back to EURUSD I would like to find my HLine at 1,5400 no matter what time frame. When switching back to GBPUSD the HLine should be at 1,6678 no matter what time frame.

Thank you for the links. I will dive into them.

Tjipke de Vries
6282
Tjipke de Vries 2014.02.19 22:18  
mci:

Thank you for the fast response.

Yes, you are right. Just to clear it up. I meant, that I want the HLine to stay where I have moved it, no matter what timeframe I switch. It shouldn't matter if I switch between 15M or 1H on the EURUSD Chart. The HLine should be at the position, where I have moved it f.e: 1,54000

The other thing is. If I change the currency pair to f.e. to GBPUSD then I would like to have a new HLine that I can move around and put it f.e. at 1,6678. When switching back to EURUSD I would like to find my HLine at 1,5400 no matter what time frame. When switching back to GBPUSD the HLine should be at 1,6678 no matter what time frame.

Thank you for the links. I will dive into them.


in that case you can't use Time[0] Close[0]

use iTime(Symbol(),PERIOD_..,0) iClose(..... )

mci
11
mci 2014.02.20 21:51  

Hi,

thank you very much for your support! I solved it with your help by using iTime and iClose and by creating objects for every single currency pair.


string sCurrentHLineName = "myHLineStop" + Symbol();

int init(){
  ObjectCreate(sCurrentHLineName, OBJ_HLINE , 0, iTime(Symbol(),0,0), iClose(Symbol(),0,0));
  ObjectSet(sCurrentHLineName, OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet(sCurrentHLineName, OBJPROP_COLOR, Pink);
  ObjectSet(sCurrentHLineName, OBJPROP_WIDTH, 0);

  return(0);
}
/
To add comments, please log in or register