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 »

The Code so far is pasted below
In its function it does everything I need it to do.
next step is to make it look a bit more how I manually draw the lines

Code: Select all

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

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_plots   7

//--- plot High
#property indicator_label1  "High"        //Yesterdays High
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Low
#property indicator_label2  "Low"         //Yesterdays Low
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Pivot
#property indicator_label3  "Pivot"       //Todays Pivot
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrDodgerBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot Resistance
#property indicator_label4  "Resistance"  //Todays resistance 20pips above High
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrLightPink
#property indicator_style4  STYLE_SOLID
#property indicator_width4  2
//--- plot Support
#property indicator_label5  "Support"     //Todays support 20 pips below Low
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrPaleGreen
#property indicator_style5  STYLE_SOLID
#property indicator_width5  2
//--- plot HighTarget
#property indicator_label6  "HighTarget"  //Todays target 50 pips above Resistance
#property indicator_type6   DRAW_LINE
#property indicator_color6  clrBlack
#property indicator_style6  STYLE_DASH
#property indicator_width6  1
//--- plot LowTarget
#property indicator_label7  "LowTarget"   //Todays target 50 pips below Support
#property indicator_type7   DRAW_LINE
#property indicator_color7  clrBlack
#property indicator_style7  STYLE_DASH
#property indicator_width7  1


//--- indicator buffers


double   HighBuffer[],
         LowBuffer[],
         PivotBuffer[],
         ResistanceBuffer[],
         SupportBuffer[],
         HighTargetBuffer[],
         LowTargetBuffer[];


//--- these will be the inputs for choosing where to plot the Sup/Res and their targets
input         int   Res = 20;
input         int   Sup = 20;
input         int   ResTarget = 50;    
input         int   SupTarget = 50;

//--- 
int      dig;
double   pnts;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,HighBuffer);
   SetIndexBuffer(1,LowBuffer);
   SetIndexBuffer(2,PivotBuffer);
   SetIndexBuffer(3,ResistanceBuffer);
   SetIndexBuffer(4,SupportBuffer);
   SetIndexBuffer(5,HighTargetBuffer);
   SetIndexBuffer(6,LowTargetBuffer);

   
//---- initialize variables
   dig=SymbolInfoInteger(Symbol(),SYMBOL_DIGITS);
   pnts=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
   if (dig==3 || dig==5) pnts*=10; 
   
  int limit,
      counted_bars=IndicatorCounted();
    
  double HighPrice,
         LowPrice,
         ClosePrice,
         PivotPrice,
         ResistancePrice,
         SupportPrice,
         HTPrice,
         LTPrice;
   
   
       // 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++)  
                               // counting from current bar to the previous bar
                               // i=0 is the current bar, bar 1 = previous bar
                               // so current bar < all the bars available - all of the counted bars
                               // i++ includes the next available bar
                               // alternative method would be to start at bar 1 and look right to the current bar
                               // i=limit-1; i>0; i--;
   {
   
   
   
   
   HighPrice  = iHigh(Symbol(),PERIOD_D1,iHighest(Symbol(),PERIOD_D1,MODE_HIGH,1,1));
   LowPrice   = iLow(Symbol(),PERIOD_D1,iLowest(Symbol(),PERIOD_D1,MODE_LOW,1,1));
   ClosePrice = iClose(Symbol(),PERIOD_D1,1); 
   
   PivotPrice = (HighPrice+LowPrice+ClosePrice)/3;
   
   ResistancePrice = HighPrice+(Res*pnts);
   SupportPrice    = LowPrice-(Sup*pnts);
   
   HTPrice = ResistancePrice+(ResTarget*pnts);
   LTPrice = SupportPrice-(SupTarget*pnts);
   
   }
   
//--- Check, deleting the lines before creating new ones
ObjectDelete("High");
ObjectDelete("Low");
ObjectDelete("Pivot");
ObjectDelete("Resistance");
ObjectDelete("Support");
ObjectDelete("HighTarget");
ObjectDelete("LowTarget");

//--- Create new lines

ObjectCreate("High",OBJ_HLINE,0,Time[0],HighPrice);
ObjectSet("High",OBJPROP_COLOR,indicator_color1);
ObjectSet("High",OBJPROP_STYLE,indicator_style1);
ObjectSet("High",OBJPROP_WIDTH,indicator_width1);

ObjectCreate("Low",OBJ_HLINE,0,Time[0],LowPrice);
ObjectSet("Low",OBJPROP_COLOR,indicator_color2);
ObjectSet("Low",OBJPROP_STYLE,indicator_style2);
ObjectSet("Low",OBJPROP_WIDTH,indicator_width2);

ObjectCreate("Pivot",OBJ_HLINE,0,Time[0],PivotPrice);
ObjectSet("Pivot",OBJPROP_COLOR,indicator_color3);
ObjectSet("Pivot",OBJPROP_STYLE,indicator_style3);
ObjectSet("Pivot",OBJPROP_WIDTH,indicator_width3);

ObjectCreate("Resistance",OBJ_HLINE,0,Time[0],ResistancePrice);
ObjectSet("Resistance",OBJPROP_COLOR,indicator_color4);
ObjectSet("Resistance",OBJPROP_STYLE,indicator_style4);
ObjectSet("Resistance",OBJPROP_WIDTH,indicator_width4);

ObjectCreate("Support",OBJ_HLINE,0,Time[0],SupportPrice);
ObjectSet("Support",OBJPROP_COLOR,indicator_color5);
ObjectSet("Support",OBJPROP_STYLE,indicator_style5);
ObjectSet("Support",OBJPROP_WIDTH,indicator_width5);

ObjectCreate("HighTarget",OBJ_HLINE,0,Time[0],HTPrice);
ObjectSet("HighTarget",OBJPROP_COLOR,indicator_color6);
ObjectSet("HighTarget",OBJPROP_STYLE,indicator_style6);
ObjectSet("HighTarget",OBJPROP_WIDTH,indicator_width6);

ObjectCreate("LowTarget",OBJ_HLINE,0,Time[0],LTPrice);
ObjectSet("LowTarget",OBJPROP_COLOR,indicator_color7);
ObjectSet("LowTarget",OBJPROP_STYLE,indicator_style7);
ObjectSet("LowTarget",OBJPROP_WIDTH,indicator_width7);


//---
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+  

int deinit()
{

ObjectsDeleteAll( 
   0,   // window index 
   OBJ_HLINE   // object type 
   );

return(0);
}

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

int start()
{

   
    
//----
   return(0);
  }
 
User avatar
SteveHopwood
Owner
Posts: 9754
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 »

I will help you out with this one.

Pop the attached shell into your editor and navigate to the trendline drawing function:
void DrawTrendLine(string name,datetime time1,double val1,datetime time2,double val2,color col,int width,int style,bool ray)

I wrote the function a long, long time ago so I would not have to endlessly rewrite it. You can see how I use the passed parameters to draw the line.

Navigate to: void DrawSessionStartLines()

This is the function that draws a start of trading session line if the user has elected to do so. Scroll down to: if (DrawSessionOpenPriceLine). You can see how I set up the parameters to pass to the line drawing function.

Do a search for:
extern string sess1="================================================================";
Here you can see how I offer the user some control over which lines to draw and colours to use. You can add more inputs to allow control of line style and width.

Related functions are:
void DrawHorizontalLine(string name,double price,color col,int style,int width) - not called in this shell.
void DrawVerticalLine(string name, int tf, int shift,color col,int style,int width) - is called in this shell.

The more you can create reusable functions by passing parameters to them, the better. You are also less likely to have LUC calling around for anything from a light morning coffee to the bender of the decade with all his mates.

:xm: :rocket:
You do not have the required permissions to view the files attached to this post.
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. [email protected] 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 »

Thank you Mr. Hopwood,
I downloaded the shell and I have found the areas within it that you highlighted.
I'll go through each line and see if I can commit it to the grey matter and make good use of it.
:good:
neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

So after some handy pointers I re wrote the indi.

Code: Select all

//+------------------------------------------------------------------+
//|                                                 TradingLines.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright     "Copyright 2019, MetaQuotes Software Corp."
#property link          "https://www.mql5.com"
#property description   " "
#property description   "Copyright "
#property description   "Version 1.00"
#property description   "Updated on 20/07/2019"
#property version       "1.00"

#property indicator_chart_window

// name of the indicator
input string   ID       = "HCPLines";      //High+Close+Pivot Lines

//--- these will be the inputs for choosing where to plot the Sup/Res and their targets if broken
input         int       Res = 20;          //Price Tends To Reverse @ 20pips Above High
input         int       Sup = 20;          //Price Tends To Reverse @ 20pips Below Low
input         int       ResTarget = 50;    //Best To Aim For >2:1 Risk:Rewards
input         int       SupTarget = 50;    //Best To Aim For >2:1 Risk:Rewards

//--- 
int      dig, tf;
double   pnts;
static datetime DayTime;

double   HP,            //Yesterdays High Price
         LP,            //Yesterdays Low Price
         CP,            //Yesterdays Close Price
         PP,            //Todays Pivot Price
         RP,            //Todays Possible Resistance Level
         SP,            //Todays Possible Support Level
         HTP,           //If Res Level is Broken This Is A Possible Target
         LTP;           //If Sup Level is Broken This Is A Possible Target

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {

   
//---- initialize variables
   dig=SymbolInfoInteger(Symbol(),SYMBOL_DIGITS);
   pnts=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
   if (dig==3 || dig==5) pnts*=10; 
   
//----   
   tf=1440;
   DayTime=TimeCurrent();
   
//----   
//+------------------------------------------------------------------+
//| Count How Many Bars Are Available On The Chart                   |
//+------------------------------------------------------------------+   
  int limit,
      counted_bars=IndicatorCounted();
       
  // 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++)  
                               // counting from current bar to the previous bar
                               // i=0 is the current bar, bar 1 = previous bar
                               // so current bar < all the bars available - all of the counted bars
                               // i++ includes the next available bar
                               // alternative method would be to start at bar 1 and look right to the current bar
                               // i=limit-1; i>0; i--;
   {
   
//+------------------------------------------------------------------+
//| How To Calculate The Variables                                   |
//+------------------------------------------------------------------+     
   
   HP =  iHigh(Symbol(),PERIOD_D1,iHighest(Symbol(),PERIOD_D1,MODE_HIGH,1,1)); 
   LP =  iLow(Symbol(),PERIOD_D1,iLowest(Symbol(),PERIOD_D1,MODE_LOW,1,1));
   CP =  iClose(Symbol(),PERIOD_D1,1); 
   PP =  (HP+LP+CP)/3;
   RP =  HP+(Res*pnts); 
   SP =  LP-(Sup*pnts); 
   //----   
   HTP   =  RP+(ResTarget*pnts);
   LTP   =  SP-(SupTarget*pnts); 

//+------------------------------------------------------------------+
//| How To Draw The Objects                                          |
//+------------------------------------------------------------------+     

//---- sequence from top to bottom: YHighPrice,YLowPrice,Pivot,PossibleResistance,PossibleSupport,DailyHighTarget,DailyLowTarget,StartOfDay    
   Del_obj(ID);
   HLineCreate(0,ID+"HP",0,HP,clrDarkRed,STYLE_SOLID,4);
   HLineCreate(0,ID+"LP",0,LP,clrDarkGreen,STYLE_SOLID,4); 
   TrendCreate(0,ID+"PP",0,PP,clrBlue,STYLE_SOLID);
   TrendCreate(0,ID+"RP",0,RP,clrLightPink,STYLE_DASH);
   TrendCreate(0,ID+"SP",0,SP,clrLimeGreen,STYLE_DASH);   
   TrendCreate(0,ID+"HTP",0,HTP,clrBlack,STYLE_DASH);
   TrendCreate(0,ID+"LTP",0,LTP,clrBlack,STYLE_DASH);
   VLineCreate(0,ID+"",0,0,clrDarkGray,STYLE_DOT); 
   
   }
//---
   return(INIT_SUCCEEDED);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+  

void OnDeinit(const int reason)
  {
//----
   Del_obj(ID);
//----
  }  

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

int start()
{
//----

//----
   return(0);
}

   
//+------------------------------------------------------------------+
//| FUNCTION: Create a trend line by the given coordinates           |
//+------------------------------------------------------------------+
//TrendCreate(0,ID+"ChartTrend",0,Time[3],lo,Time[1],lo,clrRed,STYLE_SOLID,3)
bool TrendCreate(const long            chart_ID=0,        // chart's ID
                 const string          name="TrendLine",  // line name
                 const int             sub_window=0,      // subwindow index
                 double                price1=0,          // first 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=true,        // in the background
                 const bool            selection=false,   // highlight to move
                 const bool            ray_right=true,   // line's continuation to the right
                 const bool            hidden=true,       // hidden in the object list
                 const long            z_order=0)         // priority for mouse click
  {
//--- create a trend line by the given coordinates
   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,iTime(Symbol(),tf,0),price1,Time[0]+Period()*60,price1))
     {
      Print(__FUNCTION__,
            ": failed to create a trend line! Error code = ",GetLastError());
      return(false);
     }
//--- 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }

//+------------------------------------------------------------------+ 
//| Create the horizontal line                                       | 
//+------------------------------------------------------------------+ 
bool HLineCreate(const long            chart_ID=0,          // chart's ID 
                 const string          name="HLine",        // line name 
                 const int             sub_window=0,        // subwindow index 
                 double                price=0,              // line 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=true,           // in the background 
                 const bool            selection=false,     // highlight to move 
                 const bool            hidden=true,         // hidden in the object list 
                 const long            z_order=0)           // priority for mouse click 
  { 

//--- reset the error value 
   ResetLastError(); 
//--- create a horizontal line 
   if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create a horizontal line! Error code = ",GetLastError()); 
      return(false); 
     } 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);  
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);  
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 

//+------------------------------------------------------------------+ 
//| Create the vertical line                                         | 
//+------------------------------------------------------------------+ 
bool VLineCreate(const long            chart_ID=0,        // chart's ID 
                 const string          name="VLine",      // line name 
                 const int             sub_window=0,      // subwindow index 
                 datetime              time=0,            // line time 
                 const color           clr=clrRed,        // line color 
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style 
                 const int             width=1,           // line width 
                 const bool            back=true,        // in the background 
                 const bool            selection=false,    // highlight to move 
                 const bool            hidden=true,       // hidden in the object list 
                 const long            z_order=0)         // priority for mouse click 
  { 
//--- if the line time is not set, draw it via the last bar 
   if(!time) 
      time=TimeCurrent(); 
//--- reset the error value 
   ResetLastError(); 
//--- create a vertical line 
   if(!ObjectCreate(chart_ID,name,OBJ_VLINE,sub_window,iTime(Symbol(),tf,0),0)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create a vertical line! Error code = ",GetLastError()); 
      return(false); 
     } 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

   return(true); 
  } 
  
//+------------------------------------------------------------------+
//| FUNCTION: Delete objects                                         |
//+------------------------------------------------------------------+
void Del_obj(string str) 
  {
//----
   int k=0;
   while (k<ObjectsTotal()) 
     {
      string objname=ObjectName(k);
      if (StringSubstr(objname,0,StringLen(str))==str) ObjectDelete(objname);  
      else k++;
     }    
  }
Now this is exactly as I want it in looks, and will save me enough time so as I don't have to draw the lines each day. Though, it will be interesting to see how it behaves when the markets are open and a new day comes along.
As I am tinkering under the hood, my next goal is to make the indicator load quicker on the chart.
I'll start at the current loop

Code: Select all

for(int i=0; i<limit; i++)
and see if I can work out
into TimeAsSeries
If it is the objects themselves, I can live with it but if the code could be tightened up I'll keep going
neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

Ok, so now the markets are open.
My code didn't update exactly how I imagined - proving that I need to move most of the code out of the init and into somewhere else, I am looking into on calculate or on tick etc.
The proof is in the pudding as they say and I now understand more about what the init really means at least. A simple click of a time frame and everything drew perfectly.
I'm investigating whether I can force the indicator to be only available in the Visualization on the H1 and below time frames automatically and therefor being ignored by H4 and above.
I have a new layout design where I drop the horizontal and just use trend lines, so the next update will be a little closer to the inidcator i have been imagining.
neville
Trader
Posts: 11
Joined: Sun Jul 07, 2019 8:52 pm

Lower Time Frame Looking Back To Higher Time Frames

Post by neville »

Got the indicator doing what I need it to do.
Having the lines pre drawn makes life a lot easier and not having all the other crud from other peoples indicators is nicer to my eye.
I'll continue to make improvements to the functionality. There are a few bits of code that I feel like I could make more elegant and I'll keep working on those.

Code: Select all

//+------------------------------------------------------------------+
//|                                                   HCPLINES_3.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright     "Copyright 2019, MetaQuotes Software Corp."
#property link          "https://www.mql5.com"
#property description   " "
#property description   "Copyright "
#property description   "Version 1.03"
#property description   "Updated on 20/07/2019"
#property version       "1.00"

#property indicator_chart_window

// name of the indicator
input string   ID       = "HCPLines";      //High+Close+Pivot Lines

//--- these will be the inputs for choosing where to plot the Sup/Res and their targets if broken
input         int       Res = 20;          //Price Tends To Reverse @ 20pips Above High
input         int       Sup = 20;          //Price Tends To Reverse @ 20pips Below Low
input         int       ResTarget = 50;    //Best To Aim For >2:1 Risk:Rewards
input         int       SupTarget = 50;    //Best To Aim For >2:1 Risk:Rewards

//--- 
int      dig, tf;
double   pnts;
static datetime DayTime;

double   HP,            //Yesterdays High Price
         LP,            //Yesterdays Low Price
         CP,            //Yesterdays Close Price
         PP,            //Todays Pivot Price
         RP,            //Todays Possible Resistance Level
         SP,            //Todays Possible Support Level
         HTP,           //If Res Level is Broken This Is A Possible Target
         LTP,           //If Sup Level is Broken This Is A Possible Target
         TSS,           //Yesterday Session Start Time
         YSS1,
         YSS;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+  

void OnDeinit(const int reason)
  {
//----
   Del_obj(ID);
//----
  }  

  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
 //---- initialize variables
   dig=SymbolInfoInteger(Symbol(),SYMBOL_DIGITS);
   pnts=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
   if (dig==3 || dig==5) pnts*=10; 
   
//----   
   tf=1440;
   //DayTime=TimeCurrent();
   
   
//----   
//+------------------------------------------------------------------+
//| Count How Many Bars Are Available On The Chart                   |
//+------------------------------------------------------------------+   
  int limit,
      counted_bars=IndicatorCounted();
       
  // 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++)  
                               // counting from current bar to the previous bar
                               // i=0 is the current bar, bar 1 = previous bar
                               // so current bar < all the bars available - all of the counted bars
                               // i++ includes the next available bar
                               // alternative method would be to start at bar 1 and look right to the current bar
                               // i=limit-1; i>0; i--;
   {
   
//+------------------------------------------------------------------+
//| How To Calculate The Variables                                   |
//+------------------------------------------------------------------+     
   
   HP =  iHigh(Symbol(),PERIOD_D1,iHighest(Symbol(),PERIOD_D1,MODE_HIGH,1,1)); 
   LP =  iLow(Symbol(),PERIOD_D1,iLowest(Symbol(),PERIOD_D1,MODE_LOW,1,1));
   CP =  iClose(Symbol(),PERIOD_D1,1); 
   PP =  (HP+LP+CP)/3;
   RP =  HP+(Res*pnts); 
   SP =  LP-(Sup*pnts); 
   //----   
   HTP   =  RP+(ResTarget*pnts);
   LTP   =  SP-(SupTarget*pnts);
   
//---- working with the time1,time2 variables   
   YSS   =  iTime(Symbol(),tf,0); //time1[0] trendline starts here
   YSS1  =  iTime(Symbol(),tf,1); //time1[1]
   TSS   =  Time[0];              //time2[0] Time[0]+Period()*60
  
//+------------------------------------------------------------------+
//| How To Draw The Objects                                          |
//+------------------------------------------------------------------+     

//---- sequence from top to bottom: YHighPrice,YLowPrice,Pivot,PossibleResistance,PossibleSupport,DailyHighTarget,DailyLowTarget,StartOfDay    
   Del_obj(ID);
  
   TrendCreate(0,ID+"HP",0,YSS1,TSS,HP,clrDarkRed,STYLE_DOT);
   TrendCreate(0,ID+"LP",0,YSS1,TSS,LP,clrDarkGreen,STYLE_DOT);
   TrendCreate(0,ID+"PP",0,YSS,TSS,PP,clrBlue,STYLE_SOLID);
   //TrendCreate(0,ID+"PP",0,PP,clrBlue,STYLE_SOLID);
   TrendCreate(0,ID+"RP",0,YSS,TSS,RP,clrLightPink,STYLE_DASH);
   TrendCreate(0,ID+"SP",0,YSS,TSS,SP,clrLimeGreen,STYLE_DASH);   
   TrendCreate(0,ID+"HTP",0,YSS,TSS,HTP,clrBlack,STYLE_DASH);
   TrendCreate(0,ID+"LTP",0,YSS,TSS,LTP,clrBlack,STYLE_DASH);
//----   
   
   VLineCreate(0,ID+"YVL",0,YSS,clrDarkGray,STYLE_DOT);
   VLineCreate(0,ID+"TVL",0,YSS1,clrDarkGray,STYLE_DOT);
  
   
   }  
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| FUNCTION: Create a trend line by the given coordinates           |
//+------------------------------------------------------------------+
//TrendCreate(0,ID+"ChartTrend",0,Time[3],lo,Time[1],lo,clrRed,STYLE_SOLID,3)
bool TrendCreate(const long            chart_ID=0,          // chart's ID
                 const string          name="TrendLine",    // line name
                 const int             sub_window=0,        // subwindow index
                 //datetime            time=0,              //  time 
                 double                time1=0,
                 double                time2=0,        
                 double                price1=0,
                           
                 const color           clr=clrRed,          // line color
                 const ENUM_LINE_STYLE style=STYLE_SOLID,   // line style
                 const int             width=1,             // line width
                 const bool            back=true,           // in the background
                 const bool            selection=false,     // highlight to move
                 const bool            ray_right=true,      // line's continuation to the right
                 const bool            hidden=true,         // hidden in the object list
                 const long            z_order=0)           // priority for mouse click
  {
//--- create a trend line by the given coordinates
   //if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,iTime(Symbol(),tf,0),price1,Time[0]+Period()*60,price1))
   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price1))
     {
      Print(__FUNCTION__,
            ": failed to create a trend line! Error code = ",GetLastError());
      return(false);
     }
//--- 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }


//+------------------------------------------------------------------+ 
//| Create the vertical line                                         | 
//+------------------------------------------------------------------+ 
bool VLineCreate(const long            chart_ID=0,          // chart's ID 
                 const string          name="VLine",        // line name 
                 const int             sub_window=0,        // subwindow index 
                 double                time1=0,             // line time 
                 const color           clr=clrRed,          // line color 
                 const ENUM_LINE_STYLE style=STYLE_SOLID,   // line style 
                 const int             width=1,             // line width 
                 const bool            back=true,           // in the background 
                 const bool            selection=false,     // highlight to move 
                 const bool            hidden=true,         // hidden in the object list 
                 const long            z_order=0)           // priority for mouse click 
  { 

//--- reset the error value 
   ResetLastError(); 
//--- create a vertical line 
   if(!ObjectCreate(chart_ID,name,OBJ_VLINE,sub_window,time1,0)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create a vertical line! Error code = ",GetLastError()); 
      return(false); 
     } 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

   return(true); 
  } 

//+------------------------------------------------------------------+
//| FUNCTION: Delete objects                                         |
//+------------------------------------------------------------------+
void Del_obj(string str) 
  {
//----
   int k=0;
   while (k<ObjectsTotal()) 
     {
      string objname=ObjectName(k);
      if (StringSubstr(objname,0,StringLen(str))==str) ObjectDelete(objname);  
      else k++;
     }    
}

//+------------------------------------------------------------------+ 
//| Create the horizontal line                                       | 
//+------------------------------------------------------------------+ 
/*bool HLineCreate(const long            chart_ID=0,          // chart's ID 
                 const string          name="HLine",        // line name 
                 const int             sub_window=0,        // subwindow index 
                 double                price=0,              // line 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=true,           // in the background 
                 const bool            selection=false,     // highlight to move 
                 const bool            hidden=true,         // hidden in the object list 
                 const long            z_order=0)           // priority for mouse click 
  { 

//--- reset the error value 
   ResetLastError(); 
//--- create a horizontal line 
   if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create a horizontal line! Error code = ",GetLastError()); 
      return(false); 
     } 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);  
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);  
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 
*/
You do not have the required permissions to view the files attached to this post.
User avatar
SteveHopwood
Owner
Posts: 9754
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 »

:clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap:
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. [email protected] 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”