Very simple EA: Draw a trend line — can't make it work - page 2

 

Dear TimNeuer

I have update previous code ; the update are changing draw  trendline instead rectangle . Please aware you need to copy and replace code below into your ea ( simply copy all and replace all )  . If the ea detect something else then ea wont work . 

#property strict

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {

   static int timeCurrent=0 ;
   if(DayOfWeek()==5)
      if(Hour()==23 && timeCurrent!=Hour())
        {
         //DRAW OBJ TREND AND OTHER PROPERTIES ...
         string TREND="TREND"+(string)ObjectsTotal();
         ObjectCreate(PERIOD_CURRENT,TREND,OBJ_TREND,0,TimeCurrent(),High[0],TimeCurrent()-82800,High[23]);
         ObjectSetInteger(PERIOD_CURRENT,TREND,OBJPROP_RAY,FALSE);
         ObjectSetInteger(PERIOD_CURRENT,TREND,OBJPROP_WIDTH,4);

         if(High[23]>High[0]) //PA BEARISH
           {
            ObjectSetInteger(PERIOD_CURRENT,TREND,OBJPROP_COLOR,clrRed);
           }
         else
            if(High[23]<High[0]) // PA BULLISH
              {
               ObjectSetInteger(PERIOD_CURRENT,TREND,OBJPROP_COLOR,clrBlue);
              }

        }
   timeCurrent=Hour();


  }//END ONTICK
//+------------------------------------------------------------------+

If you done correctly , the ea should work something like below ; 

preview

As shown gif file above , if open less then close  then the trendline color are Blue ( assume bullish ) meanwhile if open more then close then trendline color Red( assume bearish ) . 

By the way feel free to studies my code and be creative . 


p/s please note , iam using value high , for better reading and ploting trendline  i recommend to use priceMid=Low[]+((High[]-Low[0])/2) 

regard.

Cosmas

 
Cosmas Moses:

Dear TimNeuer

I have update previous code ; the update are changing draw  trendline instead rectangle . Please aware you need to copy and replace code below into your ea ( simply copy all and replace all )  . If the ea detect something else then ea wont work . 

If you done correctly , the ea should work something like below ; 

As shown gif file above , if open less then close  then the trendline color are Blue ( assume bullish ) meanwhile if open more then close then trendline color Red( assume bearish ) . 

By the way feel free to studies my code and be creative . 


p/s please note , iam using value high , for better reading and ploting trendline  i recommend to use priceMid=Low[]+((High[]-Low[0])/2) 

regard.

Cosmas

Hey Cosmas, thanks for the effort again. Unfortunately I am still unable to see any trend lines as in the gif you posted. Please take a look at the error messages I get: https://i.imgur.com/G8T3vyx.png
 
TimNeuer:
Hey Cosmas, thanks for the effort again. Unfortunately I am still unable to see any trend lines as in the gif you posted. Please take a look at the error messages I get: https://i.imgur.com/G8T3vyx.png

Iam test ea using Tick Data Suite hence i have no issues . I did some test whereby turning off Tick Data Suite option and run the EA and  i found out i have the same problem like yours. My conclusions  regarding issues Unmatched Data Error most likely related with your historical pair data .  To solve this problem you need to provide better historical data for the ea to work . 

regards

Cosmas

 

im a noob to trying to work out how to do the trend line when i mention using tend lines as part of a strategy on EA to close a trade im told i cant if possible i would like to simple have the EA to use the trend lines to close a trade and open the next the trade. 


If what you have done would me can you please show me the coding you have done and ill try and use that as my starting point i am looking at paying someone but i keep getting told im limited but when i look at the other EA's that have been made i see they already been made so not sure what to think any help would be greatly appreciate i also apologies if I doing the wrong thing by posting this here instead of making my own.

 

Here is a standard solution.

//+------------------------------------------------------------------+ 
//| Create a trend line by the given coordinates                     | 
//+------------------------------------------------------------------+ 
bool TrendCreate(const long            chart_ID=0,        // chart's ID 
                 const string          name="TrendLine",  // line name 
                 const int             sub_window=0,      // subwindow index 
                 datetime              time1=0,           // first point time 
                 double                price1=0,          // first point price 
                 datetime              time2=0,           // second point time 
                 double                price2=0,          // second point price 
                 const color           clr=clrRed,        // line color 
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style 
                 const int             width=1,           // line width 
                 const bool            back=false,        // in the background 
                 const bool            selection=true,    // highlight to move 
                 const bool            ray_left=false,    // line's continuation to the left 
                 const bool            ray_right=false,   // line's continuation to the right 
                 const bool            hidden=true,       // hidden in the object list 
                 const long            z_order=0)         // priority for mouse click 
  { 
//--- set anchor points' coordinates if they are not set 
   ChangeTrendEmptyPoints(time1,price1,time2,price2); 
//--- reset the error value 
   ResetLastError(); 
//--- create a trend line by the given coordinates 
   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create a trend line! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set line color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- set line display style 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
//--- set line width 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the line by mouse 
//--- when creating a graphical object using ObjectCreate function, the object cannot be 
//--- highlighted and moved by default. Inside this method, selection parameter 
//--- is true by default making it possible to highlight and move the object 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- enable (true) or disable (false) the mode of continuation of the line's display to the left 
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_LEFT,ray_left); 
//--- enable (true) or disable (false) the mode of continuation of the line's display to the right 
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 

You can move the trendline with 

ObjectMove();

Function by specifying the point that needs to be moved and it's new anchor point.

You can get the price value with

ObjectGetDouble();

Function so you can compare bid and ask against that price to see if it crossed over.

 
TimNeuer:

Well I would have if I were able to...

Played around a little bit more since posting it here earlier and was successful compiling it without any errors or warnings this time. Here you go: 

I get a couple of errors trying to compile this. I am using MetaTrader5 and DayOfWeek(), Open[], Time[], Close[] are unknown. What am I missing?

 
René Moll:

I get a couple of errors trying to compile this. I am using MetaTrader5 and DayOfWeek(), Open[], Time[], Close[] are unknown. What am I missing?

This topic is about MQL4 and is in the MQL4 section. These standard arrays do not exist in MQL5.

 
Does anyone knows how to code trandlines and channels? If you do please show me.
 
Hello guys. I need help to identify higher highs and higher lows or lower highs and lower lows. Eventually I would like to code a trendline or channel using these price peaks and troughs. Please see the Image of what I mean. I don't mind paying someone who knows how to do this properly and me being able to learn.
Files:
Reason: