void TLine( string name, datetime T0, double P0, datetime T1, double P1 , color clr, bool ray=false ){ #define WINDOW_MAIN 0 if (!Show.Objects) return; /**/ if(ObjectMove( name, 0, T0, P0 )) ObjectMove(name, 1, T1, P1); else if(!ObjectCreate( name, OBJ_TREND, WINDOW_MAIN, T0, P0, T1, P1 )) Alert("ObjectCreate(",name,",TREND) failed: ", GetLastError() ); else if (!ObjectSet( name, OBJPROP_RAY, ray )) Alert("ObjectSet(", name, ",Ray) failed: ", GetLastError()); if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change Alert("ObjectSet(", name, ",Color) [2] failed: ", GetLastError()); string P0t = PriceToStr(P0); if (MathAbs(P0 - P1) >= Point) P0t = StringConcatenate(P0t, " to ", PriceToStr(P1)); if (!ObjectSetText(name, P0t, 10)) Alert("ObjectSetText(",name,") [2] failed: ", GetLastError()); } void HLine(string name, double P0, color clr){ // #define WINDOW_MAIN 0 if (!Show.Objects) return; /**/ if (ObjectMove( name, 0, Time[0], P0 )){} else if(!ObjectCreate( name, OBJ_HLINE, WINDOW_MAIN, Time[0], P0 )) Alert("ObjectCreate(",name,",HLINE) failed: ", GetLastError() ); if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change Alert("ObjectSet(", name, ",Color) [1] failed: ", GetLastError() ); if (!ObjectSetText(name, PriceToStr(P0), 10)) Alert("ObjectSetText(",name,") [1] failed: ", GetLastError()); } string PriceToStr(double p){ string pFrc = DoubleToStr(p, Digits); if(Digits.pips==0) return(pFrc); string pPip = DoubleToStr(p, Digits-1); if (pPip+"0" == pFrc) return(pPip); return(pFrc); }
Thanks WHRoeder, will try..
Hi WHRoeder, I still can't manage to get it proper. I'm sorry, I'm quite new in mql language. Please help me. This is my edited code.
I think there is something wrong in coordinate section. Anyone, please help.
#property indicator_chart_window color Trendline_Colour = DeepPink; extern string StartTime = "12:37"; extern string EndTime = "15:48"; datetime TimeStart, TimeEnd; int ShiftStart, ShiftEnd; double PriceStart, PriceEnd; int init() { return(0); } int deinit() { ObjectDelete("Trendline"); return(0); } int start() { //+------------------------------------------------------------------+ //| COORDINATE | //+------------------------------------------------------------------+ TimeStart = StrToTime(StartTime); TimeEnd = StrToTime(EndTime); ShiftStart = iBarShift(Symbol(),PERIOD_M1,TimeStart); ShiftEnd = iBarShift(Symbol(),PERIOD_M1,TimeEnd); PriceStart = iClose(Symbol(), PERIOD_M1, ShiftStart); PriceEnd = iClose(Symbol(), PERIOD_M1, ShiftEnd); //+------------------------------------------------------------------+ //| TRENDLINE | //+------------------------------------------------------------------+ TrendLine("Trendline",TimeStart,PriceStart,TimeEnd,PriceEnd,Trendline_Colour,false); return(0); } //+-------------------------------------------------------------------------------------------------------------------------------------+ ////////////////////////////////////////////////////// END OF MAIN PROGRAM ////////////////////////////////////////////////////////////+ //+-------------------------------------------------------------------------------------------------------------------------------------+ void TrendLine( string name, datetime T0, double P0, datetime T1, double P1, color clr, bool ray=false ) { if(ObjectFind(name) != 0) { if(!ObjectCreate( name, OBJ_TREND, 0, T0, P0, T1, P1 )) Alert("ObjectCreate(",name,",TREND) failed: ", GetLastError() ); else if (!ObjectSet( name, OBJPROP_RAY, ray )) Alert("ObjectSet(", name, ",Ray) failed: ", GetLastError()); if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change Alert("ObjectSet(", name, ",Color) [2] failed: ", GetLastError()); } else { ObjectDelete(name); if(!ObjectCreate( name, OBJ_TREND, 0, T0, P0, T1, P1 )) Alert("ObjectCreate(",name,",TREND) failed: ", GetLastError() ); else if (!ObjectSet( name, OBJPROP_RAY, ray )) Alert("ObjectSet(", name, ",Ray) failed: ", GetLastError()); if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change Alert("ObjectSet(", name, ",Color) [2] failed: ", GetLastError()); } }
Hairi:
I think there is something wrong in coordinate section. Anyone, please help.
I think there is something wrong in coordinate section. Anyone, please help.
if(ObjectFind(name) != 0)if the name doesn't exit ObjectFind returns -1
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Dear Friends,
Need some help on coding this simple indicator to draw a line between 2 specific time at Close price M1 ( as per pic attached )
Here is my preliminary code, I know there is something WRONG with it. Please help me