Drawing short trendline (no ray) at 4 levels

 

I would like to draw 4 short trendlines of about 4 candles width backwards from the current candle at 4 levels. Any ideas?

I also want it to leave other lines on the chart untouched.

Can I do this with a script because I only want it to draw the lines once depending on what I enter for the inputevel...not every tick.

The I would run the script again maybe every 2 days or so.


   double inputlevel=1.3870;
double level1=inputlevel+(20*Point*10); //+20pips
double level2=inputlevel+(30*Point*10); //+30pips
double level3=inputlevel+(40*Point*10); //+40pips
double level4=inputlevel+(80*Point*10); //+80pips

    ObjectCreate("HorizontalLine1",OBJ_TREND,0,0,level1);
    ObjectSet("HorizontalLine1",OBJPROP_COLOR,Red);
    ObjectSet("HorizontalLine1",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSet("HorizontalLine1",OBJPROP_WIDTH,1);
 
    ObjectCreate("HorizontalLine2",OBJ_TREND,0,0,level2);
    ObjectSet("HorizontalLine2",OBJPROP_COLOR,Red);
    ObjectSet("HorizontalLine2",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSet("HorizontalLine2",OBJPROP_WIDTH,1);

    ObjectCreate("HorizontalLine3",OBJ_TREND,0,0,level3);
    ObjectSet("HorizontalLine3",OBJPROP_COLOR,Red);
    ObjectSet("HorizontalLine3",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSet("HorizontalLine3",OBJPROP_WIDTH,1);

    ObjectCreate("HorizontalLine4",OBJ_TREND,0,0,level4);
    ObjectSet("HorizontalLine4",OBJPROP_COLOR,Red);
    ObjectSet("HorizontalLine4",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSet("HorizontalLine4",OBJPROP_WIDTH,1);
 

I guess OBJ_TREND has more then one coordinate

https://docs.mql4.com/constants/objects

or you have to use horisontal line.

 
Roger:

I guess OBJ_TREND has more then one coordinate

https://docs.mql4.com/constants/objects

or you have to use horisontal line.

What about the length though?

Can I use a script to draw these lines or does it have to be an inidicator?

If an indicator, can I use the script to start the indicator?

int start()
  {
   int    counted_bars=IndicatorCounted();
//----

//testing variable
inputlevel = 1.5898;

int i;
double level1=inputlevel+(20*Point*10); //+20pips
double level2=inputlevel+(30*Point*10); //+30pips
double level3=inputlevel+(40*Point*10); //+40pips
double level4=inputlevel+(80*Point*10); //+80pips

for(i=0;i<Bars;i++)
{
   datetime dtStart = iTime(NULL,PERIOD_M15,i-4);
   datetime dtEnd = iTime(NULL,PERIOD_M15,i);
}

    ObjectCreate("Line1",OBJ_TREND,0,dtStart,level1, dtEnd, level1); 
    ObjectSet("Line1",OBJPROP_COLOR,Red);
    ObjectSet("Line1",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSet("Line1", OBJPROP_RAY, false);
    ObjectSet("Line1",OBJPROP_WIDTH,1);
 
    ObjectCreate("Line2",OBJ_TREND,0,dtStart,level2, dtEnd, level2);
    ObjectSet("Line2",OBJPROP_COLOR,Red);
    ObjectSet("Line2",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSet("Line2", OBJPROP_RAY, false);
    ObjectSet("Line2",OBJPROP_WIDTH,1);

    ObjectCreate("Line3",OBJ_TREND,0,dtStart,level3, dtEnd, level3);
    ObjectSet("Line3",OBJPROP_COLOR,Red);
    ObjectSet("Line3",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSet("Line3", OBJPROP_RAY, false);
    ObjectSet("Line3",OBJPROP_WIDTH,1);

    ObjectCreate("Line4",OBJ_TREND,0,dtStart,level4, dtEnd, level4);
    ObjectSet("Line4",OBJPROP_COLOR,Red);
    ObjectSet("Line4",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSet("Line4", OBJPROP_RAY, false);
    ObjectSet("Line4",OBJPROP_WIDTH,1);
   
//----
   return(0);
  }
 

Can I use a script to draw these lines or does it have to be an inidicator? -- either one

If an indicator, can I use the script to start the indicator? -- no

 
SanMiguel:

The code above doesn't draw anything. Any ideas what's wrong?

? :)

 
SanMiguel:

? :)

Any ideas why it doesn't draw anything?

No errors either...

 
SanMiguel:

Any ideas why it doesn't draw anything?

It does draw the lines somewhere in the Universe. :) You just can't see them.

Find the objects in the object list and check their coordinates.


No errors either...

Unlikely. Iterative call to ObjectCreate() with the same object name does return an error.


I'm curious what's the purpose of the 'for' loop? A time delay in the indicator?

Reason: