Trendline Break Executor

 

Friends, I would like a script that executes a buy or sell order with stop loss and take profit when price crosses a trendline that is drawn on the chart. Also, it would be nice if the script had the ability to disable the buy/sell function and only generate an alert when the trendline is crossed by the price. It would be a script, not an EA, in that it would execute only once after it was applied to the chart which could be any timeframe. Any suggestions how to do this. I wish you all the best in 2006!

 

is the trend line drawn manually or from an indicator?

 

The trendline is drawn manually using the trendline drawing function provided with the MT4 platform. There are three line drawing functions provides with the platform: Vertical Line, Horizontal Line, and Trendline. These are represent by three buttons on the upper left toolbar with the appropriate symbols. The trendline function is represented by a diagonal line "/ " foward slash symbol. When the trendline is drawn it is registered in the program by a number in the Object List, for example, Trendline 45321. The Object List can be accessed by right clicking on the chart and selecting Object List. The Script could reference the trendline by its reference number.

 

It's possible, but why do you need it if you need to execute the script by hand anyway? You said you need script not EA. Script is executed manually, but EA is executed automatically when new tick arrives. You can disable auto trade execution of EA if you want to, cos it's configuratable. Maybe you are confused?

 

Friends, the Expert Advisor Wizard in the MetaEditor of the MQL4 language allows for the creation of three distinct types of user defined programs: the Expert Advisor program, the Custom Indicator program, and the Script program. While the expert advisor contains a loop function that allows it to be executed repeatedly, the script program is designed for single use only. You do not need to execute the script by hand, you only need place it on the chart once similar to the expert advisor. The difference is that it only executes one time, not repeatedly. The script I have in mind is similar to a buy stop or a sell stop, but the difference is that whereas a buy or sell stop is fixed to a single price (a horizontal line), a diagonal line would trigger at a changing price depending on where price crossed the line. My idea is to trigger a trade on a breakout without having to constantly monitor the charts.

 

Because if trendline is diagonal, the order price must be constantly modified to go along with the line. So if order price is needed to be constantly modified, it's the job of Expert Advisor not script, because script, like you said, run only one-time when you double click on it.

By the time I described to you, I've coded the expert advisor for you already, so check it out in Forward Testing not Backtesting. You must draw a trendline and name it tx (case sensitive). Attach the expert to the same chart that trendline is drawn. Then you can choose to open only Long, Short, Both, or none in the settings window. When bid price crosses up the trendline, buy at market price. When bid price crosses down the trendline, sell at market price.

Enjoys!

Files:
 

Thank you scorpion, works great! I just put it on a 15 min chart to test and it has given an alert and I made a trade. In fact, I had the alert set and it must have crossed the tx trendline a couple of times because I got two alerts. This is just what I wanted, thank you.

 

You're welcome mate.

Forgot to mention that the expert supports multiple pairs as well. You can trade eurusd, gbpusd, etc at the same time.

 

could you explain the 4 TS settings, are these trailing stop features and if so is there a trailingstop feature that will begin to trail immediately.

also could you script this?

/*

NEED A ONE TIME EXECUTEALBLE SCRIPT

*/

extern double TradeType=1 // 1=buy 2=sell // could also make a buy script and a sell script

extern double StopLoss=30;

extern double TakeProfit=500;

extern double TrailingStop=15;

extern bool TrailImmediately=true;

extern double Slippage=1;

extern double Lots=0.1;

extern int OrderTries=5;

// Build unique magic number for multiple positions/pairs/monitor trailing/adjusttrailing stops

// IS THIS EVEN POSSIBLE???

THANKS!

 

bro scorpio...can u give screenshoot for trendlineonline ?...and step by step to use that thing..so sorry, im newbie in this forex....

 

im interested in this one too. thanks!

Reason: