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);
}