want to draw a trendline

 

hi I want to draw a trendline from the corner of the candle. What is the code for this trendline?

thanks guys

Files:
Capture.PNG  6 kb
 

 ObjectCreate(0,objname,OBJ_TREND,0,Time[2],High[2],??????????,Open[1]);


?????   help me

 
web fx: hi I want to draw a trendline from the corner of the candle. What is the code for this trendline? thanks guys

There is no such thing as the "corner of the candle". Candles are just "visual artifacts" to represent the OHLC data and they have no set thickness. They can be "thick" or "thin" depending on the zoom level but have not set conditions for their precise display.

A start and end anchor points of trend-line graphical objects are based on price quotes and time, not on precise bitmap coordinates.

 

Endpoints of a trendline are on the candle center. The time of the candle.

You would have to compute the candle's width and distance between candles, in pixels. And then convert that to times for the endpoint(s).

Even when you get that right, the moment you change candle width, the line is wrong. Therefor you can't use it for trading. Why bother?

 
Fernando Carreiro #:

There is no such thing as the "corner of the candle". Candles are just "visual artifacts" to represent the OHLC data and they have no set thickness. They can be "thick" or "thin" depending on the zoom level but have not set conditions for their precise display.

A start and end anchor points of trend-line graphical objects are based on price quotes and time, not on precise bitmap coordinates.

thanks.

William Roeder #:

Endpoints of a trendline are on the candle center. The time of the candle.

You would have to compute the candle's width and distance between candles, in pixels. And then convert that to times for the endpoint(s).

Even when you get that right, the moment you change candle width, the line is wrong. Therefor you can't use it for trading. Why bother?


My trading time frame is one minute, and I want quick reaction in binary options.

How can I count pixels?

You can write the code and replace it.

Candlestick width is always the last zoom.

thanks

 
web fx #: My trading time frame is one minute, and I want quick reaction in binary options. How can I count pixels? You can write the code and replace it. Candlestick width is always the last zoom.

You seem to be ignoring our advice. As explained the candle thickness will vary with the zoom level irrespective of it being M1 or not. It will also change with Screen DPI.

You are analysing your situation incorrectly. Even if you did know the pixel count it would make no difference because the trend-line anchor points are not based on pixels, but instead on time and price.

Rethink your logic. It is flawed.

 
Fernando Carreiro #:

You seem to be ignoring our advice. As explained the candle thickness will vary with the zoom level irrespective of it being M1 or not. It will also change with Screen DPI.

You are analysing your situation incorrectly. Even if you did know the pixel count it would make no difference because the trend-line anchor points are not based on pixels, but instead on time and price.

Rethink your logic. It is flawed.

Thanks you very much sir
 

hello Mr Carreiro 

This indicator is not drawn for the new candle. I must change the time frame for it to change. What should I add?

string objname1="LINEee"
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- Output in Char

//----
   return(0);
  }

int deinit() 
  {
   ObjectDelete(0, objname1);

   return(0);
  } 
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
/////////////////////M1
 double  high1= iHigh(Symbol(),0,2); 
 double  close1= iClose(Symbol(),0,1); 

 datetime   time2= iTime(Symbol(),0,2); 
 datetime    time1= iTime(Symbol(),0,1); 

ObjectCreate(0,objname1,OBJ_TREND,0,time2,high1,time1 ,close1);
            ObjectSetInteger(0,objname1,OBJPROP_COLOR,clrAqua);
            ObjectSetInteger(0,objname1,OBJPROP_STYLE,STYLE_DOT);
            ObjectSetInteger(0,objname1,OBJPROP_WIDTH,1);
            ObjectSetInteger(0,objname1,OBJPROP_BACK,false);
            ObjectSetInteger(0,objname1,OBJPROP_SELECTABLE,false);
            ObjectSetInteger(0,objname1,OBJPROP_SELECTED,false);
            ObjectSetInteger(0,objname1,OBJPROP_HIDDEN,false); 
   return(0);
  }
//
 
web fx #: This indicator is not drawn for the new candle. I must change the time frame for it to change. What should I add?
  1. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  2. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  3. You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

  4. You created the object on one tick. You can never create it again; including a new candle.

    Either delete and re-create it, or move it if it already exists.

 
William Roeder #:
  1. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  2. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  3. You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

  4. You created the object on one tick. You can never create it again; including a new candle.

    Either delete and re-create it, or move it if it already exists.

@William Roeder, he did not hijack the thread. It is his own thread. He is the OP of this thread.

Reason: