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