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){ return(DoubleToStr(p, Digits)); } /* alternately 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); } //++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl } */
(If the search function is down again just Google site:mql4.com whatever)
Hi,
Thanks - had a play now and 'winning' - I got a line to show, changed properties, deleted etc.
Thanks for your support.
'ola, it is I, Simon! (wink, LOL)
Can somebody please help code this:
- when I put HLine on chart, with DESCRIPTION
'buy', I want EA to trail this HLine on BuyHLineTF (time frame), HLineBB (bars back), and vice-versa,
'sell', I want EA to trail HLine on SellHLineTF, HLineBB.
Time frame selectable, x bars back from bar HiLo, which is already defined as:
BuyHLineTS = iLow (NULL, TrailHLineTF, iLowest (NULL, TrailHLineTF, MODE_LOW, TrailHLineBB, 1)) - (TrailHLinePipsHiLo * Point); SellHLineTS = iHigh (NULL, TrailHLineTF, iHighest (NULL, TrailHLineTF, MODE_HIGH, TrailHLineBB, 1)) + (TrailHLinePipsHiLo * Point);
Last part (...PipsHiLo) can be ignored.
So, when I put HLine with description 'buy', EA would trail this line up (while price also goes up on the chart), ex. at low of 3 bars back. Now, when price passes this 'buy' line downside, the EA will (at least it should, it had no problem doing it till now) rename it to 'triggered: buy' (thank you, prof. 7bit, bow), and execute propriate actions (well, you know, like taking the waste sums of real money from the market into my LIVE account! LOL!). So the trailing code will not recognize it anymore and leave it alone.
With my current coding knowledge, which is far far far away from sufficient for this job (yea, yea, I know, another CTRL+C CTRL+V guy), the code looks like this: LOL!
#include <CommonFunChi.mqh> extern int TrailHLineTF = 60; extern int TrailHLineBB = 3; int TrailHLinePipsHiLo = 0; double BuyHLineTS, SellHLineTS; string font = "Courier"; int SizeInfo = 15; int x = 50; int StartYDist = 100; int Corner = 0; // ----- expert initialization function ----- int init() { return(0); } // ----- expert deinitialization function ----- int deinit() { ObjectDelete ("Buy_HLine"); ObjectDelete ("Sell_HLine"); return(0); } // ----- expert start function ----- int start() { BuyHLineTS = iLow (NULL, TrailHLineTF, iLowest (NULL, TrailHLineTF, MODE_LOW, TrailHLineBB, 1)) - (TrailHLinePipsHiLo * Point); SellHLineTS = iHigh (NULL, TrailHLineTF, iHighest (NULL, TrailHLineTF, MODE_HIGH, TrailHLineBB, 1)) + (TrailHLinePipsHiLo * Point); checkLines(); if (ObjectFind ("buy", OBJPROP_PRICE1 != BuyHLineTS)) { ObjectSet ("buy", /*double*/ OBJPROP_PRICE1, BuyHLineTS); } // ObjectFind ("sell", 0, 0, 0); if (ObjectFind ("sell", OBJPROP_PRICE1 != SellHLineTS)) { ObjectSet ("sell", /*double*/ OBJPROP_PRICE1, SellHLineTS); } return(0); } // ----- custom functions ----- void checkLines() { int y = 16; if (crossedLine ("buy")) { label ("Buy_HLine", x, StartYDist + 1 * y, Corner, "I am Buy HLine.", SizeInfo, font, RoyalBlue); } if (crossedLine ("sell")) { label ("Sell_HLine", x, StartYDist + 2 * y, Corner, "I am Sell HLine.", SizeInfo, font, Red); } }
Afkorsa, when done, it will be in user-defined function. Yes, I know this doesn't work, I have coded it myself! No copy-paste this time (this is why it does not work). LOL! But you must admit it is written very logicaly - if price of this 'buy' line is not same as low of ex. 3 bars back on 60m time frame, move it there! Simple! Actually, briliant! LOL. Don't get me to serious. Sleepless nights, oh those sleepless nights...
Thank you for help,
Besta regarda, mi amici,
Simon
S love nia
Aloha!
I am back. With proper code, this time. Also no copy-pasteta! The result of many many many seconds (LOL, actually minutes, but, hey, who's D MEN! LOL!) of my coding (on the go!). Both variants work, I like non-commented-out more, because I do not know what is the second parameter ('0') in commented-out code (ObjectMove...).
void trailHLine() { if (ObjectFind ("buy") == 0) // object "buy" is on main window { ObjectSet ("buy", OBJPROP_PRICE1, BuyHLineTS); // ObjectMove ("buy", 0, Time[1], BuyHLineTS); } if (ObjectFind ("sell") == 0) { ObjectSet ("buy", OBJPROP_PRICE1, SellHLineTS); // ObjectMove ("sell", 0, Time[1], SellHLineTS); } // return(0); }
And I have figure it out (briliant as I are LOL) that I do not want to 'catch' object description (which is already occupied), but object name, which this code actually does (not to mention that, briliant as I are, I have no idea how to select object by its description). LOL! Huraaay! Me briliant!
This would be the last code part in my EA. Me happy! Me earn money now! Me no no donate money to FX! LOL!
Best regards,
have fun,
Simon
S love nia
I like non-commented-out more, because I do not know what is the second parameter ('0') in commented-out code (ObjectMove...).

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Sorry it sounds so simple but I'd just like to see some sample code - then play around. (Any sample code for dealing with 'objects' would be great.)
I just want to place a horizontal line as my own trailing stop.
I guess I want to create an object then continually modify.
[when I use the search facility I just keep getting "An Error Occurred. Please try again later" ]