Highest bar and Lowest Bar Close

KelvinHand

Well-Known Member
#11
Here is the MT4 code.
It is not generating any signal.
The logic is simple to mark the highest close of M15,M30,H1,H4,D1 looking back x periods.The default is 14 periods.
Similarly for lowest close of M15,M30,H1,H4,D1.

Code:
//+------------------------------------------------------------------+
//|                                                       KLines.mq4 |
//|                                                          Kalenzo |
//|                                      [email protected] |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "[email protected]"
//----
extern int KLPeriod=14;
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   drawLabel();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll() ;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   double hhmd =iClose(NULL,PERIOD_D1, Highest (NULL,PERIOD_D1, MODE_CLOSE, KLPeriod,1));
   double hhmh4=iClose(NULL,PERIOD_H4, Highest (NULL,PERIOD_H4, MODE_CLOSE, KLPeriod,1));
   double hhmh1=iClose(NULL,PERIOD_H1, Highest (NULL,PERIOD_H1, MODE_CLOSE, KLPeriod,1));
   double hhm30=iClose(NULL,PERIOD_M30, Highest (NULL,PERIOD_M30, MODE_CLOSE, KLPeriod,1));
   double hhm15=iClose(NULL,PERIOD_M15, Highest (NULL,PERIOD_M15, MODE_CLOSE, KLPeriod,1));
   //
   drawLine("HH_D1",Time[50],Time[40],hhmd,hhmd,3,0,Green,1);
   drawLine("HH_H4",Time[40],Time[30],hhmh4,hhmh4,3,0,Green,1);
   drawLine("HH_H1",Time[30],Time[20],hhmh1,hhmh1,3,0,Green,2);
   drawLine("HH_M30",Time[20],Time[10],hhm30,hhm30,3,0,LimeGreen,2);
   drawLine("HH_M15",Time[10],Time[0],hhm15,hhm15,3,0,Lime,1);
   drawLine("HH_D1r",Time[50],Time[40],hhmd,hhmd,1,1,Green,0);
   drawLine("HH_H4r",Time[40],Time[30],hhmh4,hhmh4,1,1,Green,0);
   drawLine("HH_H1r",Time[30],Time[20],hhmh1,hhmh1,1,1,LimeGreen,0);
   drawLine("HH_M30r",Time[20],Time[10],hhm30,hhm30,1,1,Lime,0);
   //
   drawTXTLabel("D1 Bar Highest Close",hhmd,Time[45],Green);
   drawTXTLabel("H4 Bar Highest Close",hhmh4,Time[35],Green);
   drawTXTLabel("H1 Bar Highest Close",hhmh1,Time[25],Green);
   drawTXTLabel("M30 Bar Highest Close",hhm30,Time[15],Green);
   drawTXTLabel("M15 Bar Highest Close",hhm15,Time[5],Green);
   //
   double llmd =iClose(NULL,PERIOD_D1, Lowest (NULL,PERIOD_D1, MODE_CLOSE, KLPeriod,1));
   double llmh4=iClose(NULL,PERIOD_H4, Lowest (NULL,PERIOD_H4, MODE_CLOSE, KLPeriod,1));
   double llmh1=iClose(NULL,PERIOD_H1, Lowest (NULL,PERIOD_H1, MODE_CLOSE, KLPeriod,1));
   double llm30=iClose(NULL,PERIOD_M30, Lowest (NULL,PERIOD_M30, MODE_CLOSE, KLPeriod,1));
   double llm15=iClose(NULL,PERIOD_M15, Lowest (NULL,PERIOD_M15, MODE_CLOSE, KLPeriod,1));
   //
   drawLine("LL_D1",Time[50],Time[40],llmd,llmd,3,0,Red,1);
   drawLine("LL_H4",Time[40],Time[30],llmh4,llmh4,3,0,Red,1);
   drawLine("LL_H1",Time[30],Time[20],llmh1,llmh1,3,0,Red,2);
   drawLine("LL_M30",Time[20],Time[10],llm30,llm30,3,0,Magenta,2);
   drawLine("LL_M15",Time[10],Time[0],llm15,llm15,3,0,Violet,1);
   drawLine("LL_D1r",Time[50],Time[40],llmd,llmd,1,1,Red,0);
   drawLine("LL_H4r",Time[40],Time[30],llmh4,llmh4,1,1,Red,0);
   drawLine("LL_H1r",Time[30],Time[20],llmh1,llmh1,1,1,Magenta,0);
   drawLine("LL_M30r",Time[20],Time[10],llm30,llm30,1,1,Violet,0);
   //
   drawTXTLabel("D1 Bar Lowest Close",llmd,Time[45],Red);
   drawTXTLabel("H4 Bar Lowest Close",llmh4,Time[35],Red);
   drawTXTLabel("H1 Bar Lowest Close",llmh1,Time[25],Red);
   drawTXTLabel("M30 Bar Lowest Close",llm30,Time[15],Red);
   drawTXTLabel("M15 Bar Lowest Close",llm15,Time[5],Red);
//----
   return(0);
  }
//+------------------------------------------------------------------+
void drawTXTLabel(string name,double lvl,datetime time, color Color)
  {
   if(ObjectFind(name)!=0)
     {
      ObjectCreate(name, OBJ_TEXT, 0, time, lvl);
      ObjectSetText(name, name, 8, "Arial", EMPTY);
      ObjectSet(name, OBJPROP_COLOR, Color);
     }
   else
     {
      ObjectMove(name, 0, time, lvl);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void drawLine(string name,datetime tfrom, datetime tto, double pfrom, double pto, int width, int ray, color Col,int type)
  {
   if(ObjectFind(name)!=0)
     {
      ObjectCreate(name, OBJ_TREND, 0, tfrom, pfrom,tto,pto);
//----
      if(type==1)
         ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
      else if(type==2)
            ObjectSet(name, OBJPROP_STYLE, STYLE_DASHDOT);
         else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
//----
      ObjectSet(name, OBJPROP_COLOR, Col);
      ObjectSet(name,OBJPROP_WIDTH,width);
      ObjectSet(name,OBJPROP_RAY,ray);
     }
   else
     {
      ObjectDelete(name);
      ObjectCreate(name, OBJ_TREND, 0, tfrom, pfrom,tto,pto);

      if(type==1)
         ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
      else if(type==2)
            ObjectSet(name, OBJPROP_STYLE, STYLE_DASHDOT);
         else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
//----
      ObjectSet(name, OBJPROP_COLOR, Col);
      ObjectSet(name,OBJPROP_WIDTH,width);
      ObjectSet(name,OBJPROP_RAY,ray);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void drawLabel()
  {
   ObjectCreate("KLabelKLines", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("KLabelKLines","Kale Workshop", 15, "Arial", EMPTY);
   ObjectSet("KLabelKLines", OBJPROP_COLOR, DodgerBlue);
   ObjectSet("KLabelKLines", OBJPROP_CORNER, 0);
   ObjectSet("KLabelKLines", OBJPROP_XDISTANCE, 20);
   ObjectSet("KLabelKLines", OBJPROP_YDISTANCE, 20);
   ObjectCreate("InameKLines", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("InameKLines","KLines", 10, "Arial", EMPTY);
   ObjectSet("InameKLines", OBJPROP_COLOR, DodgerBlue);
   ObjectSet("InameKLines", OBJPROP_CORNER, 0);
   ObjectSet("InameKLines", OBJPROP_XDISTANCE, 21);
   ObjectSet("InameKLines", OBJPROP_YDISTANCE, 50);
//----
   string desc="Indicator peroid: "+KLPeriod+" Bars";
   ObjectCreate("DescKLines", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("DescKLines",desc, 8, "Arial", EMPTY);
   ObjectSet("DescKLines", OBJPROP_COLOR, DodgerBlue);
   ObjectSet("DescKLines", OBJPROP_CORNER, 0);
   ObjectSet("DescKLines", OBJPROP_XDISTANCE, 21);
   ObjectSet("DescKLines", OBJPROP_YDISTANCE, 70);
  }
//+------------------------------------------------------------------+
Hi Mr shruti.trader,

See :thumb:


Next Carry out Research on Amibroker Help Guide and Sample from WiseStock.

For Example:

double hhmd =iClose(NULL,PERIOD_D1, Highest (NULL,PERIOD_D1, MODE_CLOSE, KLPeriod,1));
==>
TimeFrameSet( inDaily);
idx = HHVBars( Ref(Close, -1), KLPeriod ) ;
hhmd = Ref(Close, -idx);
TimeFrameRestore();
 
Last edited:

KelvinHand

Well-Known Member
#13
hello Kelvinhand,

Give me some more hints..not able to understand.
Based on MT4 statement:
PHP:
double hhmd =iClose(NULL,PERIOD_D1, Highest (NULL,PERIOD_D1, MODE_CLOSE, KLPeriod,1));
There are 2 commands to consider:

iClose()
PHP:
double iClose( string symbol, int timeframe, int shift) ;
which is equivalent in Amibroker
PHP:
//-- Exclude this Foreign( symbol, "C" );   
TimeFrameSet( timeframe);
 iClose = Ref(Close, Shift);
TimeFrameRestore();
iHighest()
PHP:
int iHighest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)

which is equivalent in Amibroker
PHP:
//-- Exclude this Foreign( symbol, "C" );   
TimeFrameSet( timeframe);
 iHighest = HHVBars( ref(type, start) , count ) ; 
TimeFrameRestore();

Based on above, we need find out the iClose( .... shift) first. This "Shift" means the Nth Bar, and this Nth Bar is the iHighest();
So we need to process the iHighest() 1st then iClose() Price will be found
Because both commands using Daily Period, so using

PHP:
TimeFrameSet( timeframe);
...
TimeFrameRestore();
then process iHighest(), because start from 1 to refer previous bar, will need to be -1 in AMI in Ref(), count=KLPeriod

TimeFrameSet( timeframe);
PHP:
idx = HHVBars( Ref(Close, -1), KLPeriod ) ;
TimeFrameRestore();


Once the iHighest bar found, then process iClose()
TimeFrameSet( timeframe);
idx = HHVBars(ref(Close, -1), KLPeriod ) ;
PHP:
hhmd = ref(Close -idx);
TimeFrameRestore();


I give a roughly idea not checking myself, Your need to test out yourself.


To confirm you are doing the right thing.
You need to export the MT4 say Tata_Power H1 in your post #1 into .csv file and import into Ami
When your code is doing right, both charts should tally.


The difficulty part is draw lines and labels at the precise position as in MT4.
You need to use the LineArray(), PlotOHLC() or GFX functions to do it.
You can reference to Trash's Code on the Supply n Demand thread.

That why
88 views but no one to answer !
.
It seen simple to you, but not easy to do for us.
 
Last edited:
#16
It is not that difficult.

Have made two custom higher TF functions for LLV and HHV and a custom line procedure.


So play around with timeframecompress, timeframeexpand and linearray.
Good!

I have send a PM to you containing a request to buy your AFL (I know how to code it). It's just meant to say thanks for your work and inputs here and there. There are definitely too many takers but not many givers here on this board. Just send me the details and what you wanna charge for it.
 
#17
Based on MT4 statement:
PHP:
double hhmd =iClose(NULL,PERIOD_D1, Highest (NULL,PERIOD_D1, MODE_CLOSE, KLPeriod,1));
There are 2 commands to consider:

iClose()
PHP:
double iClose( string symbol, int timeframe, int shift) ;
which is equivalent in Amibroker
PHP:
//-- Exclude this Foreign( symbol, "C" );   
TimeFrameSet( timeframe);
 iClose = Ref(Close, Shift);
TimeFrameRestore();
iHighest()
PHP:
int iHighest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)

which is equivalent in Amibroker
PHP:
//-- Exclude this Foreign( symbol, "C" );   
TimeFrameSet( timeframe);
 iHighest = HHVBars( ref(type, start) , count ) ; 
TimeFrameRestore();

Based on above, we need find out the iClose( .... shift) first. This "Shift" means the Nth Bar, and this Nth Bar is the iHighest();
So we need to process the iHighest() 1st then iClose() Price will be found
Because both commands using Daily Period, so using

PHP:
TimeFrameSet( timeframe);
...
TimeFrameRestore();
then process iHighest(), because start from 1 to refer previous bar, will need to be -1 in AMI in Ref(), count=KLPeriod

TimeFrameSet( timeframe);
PHP:
idx = HHVBars( Ref(Close, -1), KLPeriod ) ;
TimeFrameRestore();


Once the iHighest bar found, then process iClose()
TimeFrameSet( timeframe);
idx = HHVBars(ref(Close, -1), KLPeriod ) ;
PHP:
hhmd = ref(Close -idx);
TimeFrameRestore();


I give a roughly idea not checking myself, Your need to test out yourself.


To confirm you are doing the right thing.
You need to export the MT4 say Tata_Power H1 in your post #1 into .csv file and import into Ami
When your code is doing right, both charts should tally.


The difficulty part is draw lines and labels at the precise position as in MT4.
You need to use the LineArray(), PlotOHLC() or GFX functions to do it.
You can reference to Trash's Code on the Supply n Demand thread.

That why
.
It seen simple to you, but not easy to do for us.


I tried to make out all combinations but giving error.i feel its not my cup of tea.


Iclose or Ihighest close code given above is totally amibroker code when i pasted them giving errors.
 

KelvinHand

Well-Known Member
#18
I tried to make out all combinations but giving error.i feel its not my cup of tea.


Iclose or Ihighest close code given above is totally amibroker code when i pasted them giving errors.
I only give you the concept n idea.

You need to work with the help guides and search the examples.

If you put in your efford and still faced the errors, then publish your homework.

Correction will be given.
 

Similar threads