Lower Time Frame Looking Back To Higher Time Frames

neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

Hello, very green coding newbie here,

I have created my first indicator - it magically draws two lines. :yahoo:
It looks back to the previous candle and at the high and low of that previous candle draws a horizontal line.

I created the code, through watching videos, etc on youtube but from some investigation, a lot of the older videos are using a different rule for the syntax (i think that is what I mean to say).

I also try and look through the mql4 docs from Empty4 but currently, they seem to have a lot of info within that I still can't pick out the nuggets that I need.

I'll keep plugging away in my investigation but on the off chance someone can explain the process for what is basically finding PERIOD_D1 High, from within a lower time frame that would be a great nudge. I'll then go back through my installed indicators and see if I can spot how they did it.

My ultimate idea is to find that price, then use it as a basis to add things, like lines that are 20 pips above yesterdays high but the starting point is definitely not coming easily to me :arrrg:

Anyway, I am nev and I am new to here and coding but not to trading so maybe i'll also be able to add some value back one day.

bye for now.
neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

I created my first indicator
It's called Lines 4 as I hope one day to have 4 lines on my charts :D

Code: Select all

//+------------------------------------------------------------------+
//|                                                       Lines4.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+


//| Property                      
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DarkRed
#property indicator_color2 DarkGreen 



//|Buffers                    
//+------------------------------------------------------------------+


double tops[];
double bots[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,tops);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,bots);
   SetIndexStyle(1,DRAW_LINE);
  
//---
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+  

int deinit()
{

return(0);
}

  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

  int start()
  {
  int limit;
  int counted_bars=IndicatorCounted();
  double HighPrice = High[1];
  double LowPrice = Low[1];
  
  
  // check for possible errors
  if(counted_bars<0) return(-1);
  // last counted bars will be checked
  if(counted_bars>0) counted_bars--;
  limit=Bars-counted_bars;
  
                
 
//--- Main Loop
   for(int i=0; i<limit; i++)
   {
 
 
//--- First Check To See if it already exists
ObjectDelete("HighLine");
ObjectDelete("LowLine");

 
//--- Draws Horizontal Lines   


   tops[i]=HighPrice;
   ObjectCreate("HighLine",OBJ_HLINE,0,Time[0],tops[0]);
   ObjectSet("HighLine",OBJPROP_COLOR,DarkRed);
   ObjectSet("HighLine",OBJPROP_WIDTH,3);

   bots[i]=LowPrice;
   ObjectCreate("LowLine",OBJ_HLINE,0,Time[0],bots[0]);
   ObjectSet("LowLine",OBJPROP_COLOR,DarkGreen);
   ObjectSet("LowLine",OBJPROP_WIDTH,3);
  
   
  }
   return(0);
   
   }
  


//+------------------------------------------------------------------+
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Lower Time Frame Looking Back To Higher Time Frames

Post by SteveHopwood »

This returns the highest on the Daily, of the previous 24 bars, starting at the close of the previous bar.

double high = iHigh( Symbol(), PERIOD_D1, iHighest( Symbol(), PERIOD_D1, MODE_HIGH, 24, 1 ) );

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

SteveHopwood » Mon Jul 08, 2019 6:27 pm wrote:This returns the highest on the Daily, of the previous 24 bars, starting at the close of the previous bar.

double high = iHigh( Symbol(), PERIOD_D1, iHighest( Symbol(), PERIOD_D1, MODE_HIGH, 24, 1 ) );

:xm: :rocket:

Thank you,
I'll have a go at seeing if I have learned anything by trying your code in place.

Also gives me something to search for within the installed indi's.
so thanks again.
User avatar
tomele
Administrator
Posts: 1208
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

Lower Time Frame Looking Back To Higher Time Frames

Post by tomele »

As Steve pointed out, the functions you should look up in the manual are

iHigh
iLow
IHighest
iLowest

As soon as you understand those, you might want to re-organize your code.

Indicators must not only do what you want, they also must be efficient and not eat up resources by brainlessly iterating things. That is the real challenge in coding indicators.

Just a hint. Find things out for yourself. You are on a good path.

Thomas
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

Thank you Thomas
tomele » Mon Jul 08, 2019 9:30 pm wrote:
As soon as you understand those, you might want to re-organize your code.

Indicators must not only do what you want, they also must be efficient and not eat up resources by brainlessly iterating things. That is the real challenge in coding indicators.
That is something I would like to learn more about.
In your opinion is it possible to learn those efficiencies via youtube? or is there an online course you would recommend?
User avatar
tomele
Administrator
Posts: 1208
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

Lower Time Frame Looking Back To Higher Time Frames

Post by tomele »

Effective coding of indicators is an art you will only learn by investing lots of time in struggling with MQL. No one can spoonfeed you the knowledge that is needed for it.

I don't know of any YT videos or online courses that would be very helpful. In fact, most of them are outdated. As an example, they teach you to use the old "special functions" init(), deinit() and start(). Meanwhile, we are using the more sophisticated event handlers OnInit(), OnDeinit(), OnTick(), OnCalculate(), OnTimer() and so on. Read about them in the MQL documentation.

My first steps with MQL were analyzing existing indicators, looking up everything in the MQL documentation that I didn' completely understand and then trying to modify parts of the code and watch the results.

Although I had a background as a coder in other languages, it took me quite a while to understand the basic concepts. Even today, the MQL documentation is my indispensable resource when coding. The basic syntax is easy, but there are just too many specific nuts and bolts. Nobody can remember them all. At least I can't.

You might consider going the same route. If you get totally stuck, post intelligent questions and you will eventually see that you are member of a community very willing to help people sticking their nose "under the hood".

Hope that gives you an idea.

Thomas
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

tomele » Tue Jul 09, 2019 8:55 pm wrote:
My first steps with MQL were analyzing existing indicators, looking up everything in the MQL documentation that I didn' completely understand and then trying to modify parts of the code and watch the results.
I am at that part where I fiddle with indicators etc.
Trying to learn the reasons behind how some indicators work etc. is the tricky bit. I'll keep plugging away.

Thank you for your kind words.
neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

Hello,
I have new question:

Having worked on defining a level, I now need to workout how to define Time on the charts, so as to be able to plot an OBJ_TREND

Code: Select all

ObjectCreate(
   

   string        "Pivot",       // object name 
   ENUM_OBJECT   OBJ_TREND,     // object type 
   int           0,             // window index 
   datetime      time1,         // time of the first anchor point 
   double        cpPrice,        // price of the first anchor point 
   datetime      time2=0,       // time of the second anchor point 
   double        cpPrice,      // price of the second anchor point 
   datetime      time3=0,       // time of the third anchor point 
   double        cpPrice       // price of the third anchor point 
   
   );
what I would like to do is define a new day, plot time 1 @ the start of a new day, Plot time 3 @ the end of the day, I am guessing you leave time 2 as Null and it works it self out?

Do I start with a new daily candle Open? Do I have to break it all down in 1440 minutes? or is there a way of say StartTime= EndTime =?


Thanks for the help so far, I have a wonderful Horizontal Line at the High and Low of the previous day, attached is the code so far.

Code: Select all

//+------------------------------------------------------------------+
//|                                                       Lines4.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+


//| Property                      
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 DarkRed
#property indicator_color2 DarkGreen 



//|Buffers                    
//+------------------------------------------------------------------+
int    dig;
double pnt, stl; 
static datetime DayTime;


double tops[];
double bots[];
double cp[];
double r1[];
double r2[];
double s1[];
double s2[];




//|Variables                    
//+------------------------------------------------------------------+




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,tops);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,bots);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,cp);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(3,r1);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(4,r2);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(5,s1);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(6,s2);
   SetIndexStyle(6,DRAW_LINE);
   
   
   
   //---- initialize variables
   dig=SymbolInfoInteger(Symbol(),SYMBOL_DIGITS);
   pnt=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
   if (dig==3 || dig==5) pnt*=10; 
  
//----   
   
//---
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+  

int deinit()
{

return(0);
}

  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

  int start()
  {
  int limit;
  int counted_bars=IndicatorCounted();
  double HighPrice = iHigh(Symbol(),PERIOD_D1,iHighest(Symbol(),PERIOD_D1,MODE_HIGH,1,1));
  double LowPrice = iLow(Symbol(),PERIOD_D1,iLowest(Symbol(),PERIOD_D1,MODE_LOW,1,1));
  double cpPrice = NormalizeDouble((iHigh(Symbol(),PERIOD_D1,1)+iLow(Symbol(),PERIOD_D1,1)+iClose(Symbol(),PERIOD_D1,1))/3,dig);
  
  
   //----
  double r1Price =NormalizeDouble(2*cpPrice-iLow(Symbol(),PERIOD_D1,1),dig); 
  double r2Price =NormalizeDouble(cpPrice+(iHigh(Symbol(),PERIOD_D1,1)-iLow(Symbol(),PERIOD_D1,1)),dig);  
  
   //----   
  double s1Price =NormalizeDouble(2*cpPrice-iHigh(Symbol(),PERIOD_D1,1),dig); 
  double s2Price =NormalizeDouble(cpPrice-(iHigh(Symbol(),PERIOD_D1,1)-iLow(Symbol(),PERIOD_D1,1)),dig);  
  
  
    // check for possible errors
  if(counted_bars<0) return(-1);
  // last counted bars will be checked
  if(counted_bars>0) counted_bars--;
  limit=Bars-counted_bars;
  
                
 
//--- Main Loop
   for(int i=0; i<limit; i++)
   {
 
 
//--- First Check To See if it already exists
ObjectDelete("HighLine");
ObjectDelete("LowLine");
//--- Draws Horizontal Lines   


   tops[i]=HighPrice;
   ObjectCreate("HighLine",OBJ_HLINE,0,Time[0],tops[0]);
   ObjectSet("HighLine",OBJPROP_COLOR,DarkRed);
   ObjectSet("HighLine",OBJPROP_WIDTH,3);

   bots[i]=LowPrice;
   ObjectCreate("LowLine",OBJ_HLINE,0,Time[0],bots[0]);
   ObjectSet("LowLine",OBJPROP_COLOR,DarkGreen);
   ObjectSet("LowLine",OBJPROP_WIDTH,3);
   
   
   
   ObjectCreate(
   

   string        "Pivot",       // object name 
   ENUM_OBJECT   OBJ_TREND,     // object type 
   int           0,             // window index 
   datetime      time1,         // time of the first anchor point 
   double        cpPrice,        // price of the first anchor point 
   datetime      time2=0,       // time of the second anchor point 
   double        cpPrice,      // price of the second anchor point 
   datetime      time3=0,       // time of the third anchor point 
   double        cpPrice       // price of the third anchor point 
   
   );
   
   
   
   
  
   
  }
   return(0);
   
   }
  
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Lower Time Frame Looking Back To Higher Time Frames

Post by SteveHopwood »

neville, you have some thinking to do.

I have not a clue what you are asking in your last post. More expert coders may have but have lost patience with you. Either way, you need to shut up and do some thinking for yourself.

My EA code is littered with stuff provided by coders far better than me but here is why they were prepared to provide such code: I spent years and years and years battering away at this stuff until I worked out the solutions to the problems I was having. We are talking over a decade here.

Then I started to attract the attention of the more professional coders here. The more I worked out for myself, the more they felt able to help me out.

So stop asking, "Erm, what do I do next?" and start proving that you are worthy of help from people who would otherwise charge hundreds of dollars an hour for their service. Do that and they might be prepared to step in and help; they did for me.

:xm: :rocket:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Post Reply

Return to “Coders Hangout”