//+------------------------------------------------------------------+ //| PriceTargetStub.mq4 | //| Copyright © 2011, Robert Hill | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Robert Hill" #property indicator_chart_window //---- input parameters extern int PriceTarget = 300; extern color PriceColor = Yellow; extern color PriceFontColor = White; extern int PriceFontSize = 8; extern int PriceWidth = 1; extern int LabelShift = 20; extern int LineShift = 40; datetime LabelShiftTime, LineShiftTime; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: add your code here ObjectDelete("Price Label"); ObjectDelete("Price Line"); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { static bool displayed = false; int counted_bars=IndicatorCounted(); //---- TODO: add your code here LabelShiftTime = Time[LabelShift]; LineShiftTime = Time[LineShift]; //---- Set line labels on chart window if (!displayed) { double P = Bid + PriceTarget * Point; DisplayLabel("Price Label", "Target : " + DoubleToStr(P, Digits), P, PriceFontSize, PriceFontColor); DisplayLine("Price Line", P, 0, STYLE_DASH, PriceColor); displayed = true; } //---- done //---- return(0); } //---- Set line labels on chart window void DisplayLabel(string LabelName, string LabelText, double LabelPos, int LabelFontSize, color LabelColor) { if(ObjectFind(LabelName) != 0) { ObjectCreate(LabelName, OBJ_TEXT, 0, LabelShiftTime, LabelPos); ObjectSetText(LabelName, LabelText, LabelFontSize, "Arial", LabelColor); } else { ObjectMove(LabelName, 0, LabelShiftTime, LabelPos); } } //--- Draw lines on chart void DisplayLine(string LineName, double LinePos, int LineWidth, int LineStyle, color LineColor) { if(ObjectFind(LineName) != 0) { ObjectCreate(LineName, OBJ_HLINE, 0, LineShiftTime, LinePos); ObjectSet(LineName, OBJPROP_STYLE, LineStyle); ObjectSet(LineName, OBJPROP_COLOR, LineColor); if (LineWidth > 0) ObjectSet(LineName, OBJPROP_WIDTH, LineWidth); } else { ObjectMove(LineName, 0, LineShiftTime, LinePos); } } //+------------------------------------------------------------------+