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

 

Hello there, 

absolute coding noob here — this is my first try at an EA.

The code should create a trend line with one anchor point at the open of Friday and second anchor point at the close of the same day. 

Time frame is 1h bars. The idea is to look at the 1h chart and be easily able to see the PA on Fridays for the whole 1h data history, or on as many Fridays as possible. 


p.s. A rectangle can do the trick as well, don't have to be a trend line.


Here's how far I've come:

void OnTick() 
  { 
      int weekday;
      weekday=TimeDayOfWeek
  
      if (weekday==5)
         ObjectCreate(0,0,OBJ_TREND,0,Time[24],Open[24],Time[0],Close[0]);  
  }

Would appreciate any hints, thanks in advance.

 
  1. Don't post code that won't even compile.
  2. Give your object a name.
 
William Roeder:
  1. Don't post code that won't even compile.
  2. Give your object a name.

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: 

void OnTick() 
  { 
     DayOfWeek();
  
     if(DayOfWeek()==5)
     {
     ObjectCreate("TrendLine",OBJ_TREND,0,Time[24],Open[24],Time[0],Close[0]);
     }  
  }
 

You can do a trendline,   But you habe to make sure, that you will do it at the richt time in your code.

so, your code only works on sunday opening, bcs you get a fix way back

to fix this problem, you schould check the actual time and count from this time

 
amando: He ask for help, not sensless comments

I gave him help. You gave him nonsense. The code has nothing to so with Sunday.

 
William Roeder:

I gave him help. You gave him nonsense. The code has nothing to so with Sunday.

I was able to get the code to compile without errors but it still doesn't do what I want it to. Any other ideas?
 
TimNeuer:
I was able to get the code to compile without errors but it still doesn't do what I want it to. Any other ideas?

Show the code

 
Keith Watford:

Show the code

It's in my comment #2 
 
TimNeuer: I was able to get the code to compile without errors but it still doesn't do what I want it to. Any other ideas?
  1. We have no idea what you want or what your code is doing. "Doesn't work" is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.

  2. Open Object list (Charts (Alt+C) → ObjectsObjects List (Control+B)) and verify your object has been created.

  3. Add a Print statement so you know you have called your create code.
 
TimNeuer:

Hello there, 

absolute coding noob here — this is my first try at an EA.

The code should create a trend line with one anchor point at the open of Friday and second anchor point at the close of the same day. 

Time frame is 1h bars. The idea is to look at the 1h chart and be easily able to see the PA on Fridays for the whole 1h data history, or on as many Fridays as possible. 


p.s. A rectangle can do the trick as well, don't have to be a trend line.


Here's how far I've come:

Would appreciate any hints, thanks in advance.

since i quite free at this moment , iam willing to share my approach regarding this issues and here my code

#property strict

void OnTick()
  {

   static int timeCurrent=0 ;
   if(DayOfWeek()==5) 
      if(Hour()==23 && timeCurrent!=Hour())
        { 
         //CHECK FOR THE HIGHEST BAR
         int barHigh = iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,23,0);
         //CONVERT THE HIGEST BAR TO PRICE
         double priceHigh = iHigh(Symbol(),PERIOD_CURRENT,barHigh);

         //CHECK FOR THE LOWEST BAR
         int barLow = iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,23,0);
         //CONVERT THE LOWEST BAR TO PRICE
         double priceLow = iLow(Symbol(),PERIOD_CURRENT,barLow);

         //DRAW OBJ RECTANGLE AND OTHER PROPERTIES ...
         string RECTANGLE="RECTANGLE"+(string)ObjectsTotal();
         ObjectCreate(PERIOD_CURRENT,RECTANGLE,OBJ_RECTANGLE,0,TimeCurrent(),priceHigh,TimeCurrent()-82800,priceLow);
         ObjectSetInteger(PERIOD_CURRENT,RECTANGLE,OBJPROP_BACK,True);

        }
   timeCurrent=Hour();

  }//END ONTICK

As shown above my approach might differ from other . How iam doing it is quite simple , first filter day and time . Once filtering is done , then check for the lowest and highest values after that  draw obj_rectangle using the lowest and highest values . 

You can review this code for studies purpose 

Hope get your message correctly 

regard 

Cosmas

 
Cosmas Moses:

since i quite free at this moment , iam willing to share my approach regarding this issues and here my code

As shown above my approach might differ from other . How iam doing it is quite simple , first filter day and time . Once filtering is done , then check for the lowest and highest values after that  draw obj_rectangle using the lowest and highest values . 

You can review this code for studies purpose 

Hope get your message correctly 

regard 

Cosmas

Hey Cosmas, thanks for your time and effort. I applied your EA to the chart but unfortunately no objects were created anywhere. Also, if I understand your code correctly, you're looking for the highest and lowest bar of the day, and I need the trendline/rectangle anchored between the open and the close. 
Reason: