House, design, renovation, decor.  Courtyard and garden.  With your own hands

House, design, renovation, decor. Courtyard and garden. With your own hands

» A script that trades from horizontal lines. Forex scripts to simplify trading

A script that trades from horizontal lines. Forex scripts to simplify trading

Semi-automatic trading system

"Trade along the lines".

Principle of operation.

The utility "Line trading" is designed to facilitate the work of a trader. Everything is very simple: using a special utility, we put a channel of 4 lines on the chart. Two lines will be required to enter, the other two will be required to exit. Then you can change the angle of inclination of each line, change the distance between them, etc. When the price reaches one of the entry lines, a buy or sell entry occurs. After that, when the price reaches one of the exit lines, the deal will be fixed with a profit (take profit) or with a loss (stop loss). Thus, you can easily organize trading by price channels and other strategies.

  • Setting stop or limit orders based on custom lines (horizontal or trend);
  • User adjustment of the position of the lines after the start of the advisor (robot);
  • Tracking open and close prices according to trend lines;
  • Calculation of the risk of all open positions for the current instrument;
  • Calculation of risk based on the percentage of the deposit set by the user;
  • Calculation of the Risk / Profit ratio;
  • Calculation of the channel width.

Installation and preparation for work.

1. Install the system in MetaTrader4, indicating the correct path.


2. Launch MetaTrader 4 (exit and enter again if MetaTrader 4 was loaded before installing the add-ons).

3. Using the mouse pointer, drag the script for drawing lines LinesToChart onto the chart. The settings window will appear.

  • The settings are very simple. After drawing lines on the chart, you can move them as you like. Variables require clarification UpLowCorrection and UpperLowerPercent. UpperLowerPercent determines the distance in percentage between the main and additional lines and is calculated in a given percentage of the channel width (see figure). UpLowCorrection in disabled state (false) does not change the position of the channel lines Up / Low... Thus, we can script the lines for the first time, define the channel lines, then reapply the script with UpLowCorrection = false, additional lines will be determined by themselves in accordance with the selected UpperLowerPercent... There is one important rule: The lines must be in strict order, if you count from top to bottom, then the order is as follows: Upper, Up, Low, Lower. Everything is described in the screenshot below.

  • After drawing the lines, you need to load the advisor. Drag the LinesToOrders line trading advisor onto the chart. The settings window will appear.
  • All descriptions on the chart are also included here. Clarification is required by the variable TradeType(see pictures).

  • The utility is now ready to work. The stops and open prices will move in line with the line. After receiving a new tick, the EA will place two pending buy and sell orders. You can change the position of lines, change risks, disable control of buy and sell positions.
  • System requirements.

      operating system Microsoft® Windows®98/2000/ XP / Vista / Windows 7

      Pentium® 4 2Ghz or higher processor

      terminal MetaTrader4 build 600 and higher

    A script is a small program that performs a one-time action.
    Unlike Expert Advisors or Indicators, which work constantly, the script performs its function and is disabled.
    In MT4, Scripts are located in the Navigator window after indicators and advisors.
    Expand the list with Scripts by clicking on the + opposite the section.

    In order to run the script, it is enough to transfer it to the chart of the currency pair.
    Press and hold the required script with the left mouse button, drag it onto the chart and release it.
    After executing its function, the script will be automatically removed from the chart.
    Some scripts have terms of use.

    For example: execute the function when the price is 1.3500 or execute the function on 08/20/2014 at 15.30.
    Such scripts remain active on the chart and wait for the conditions to be met.
    But if you need to stop the script, then just right-click on the chart and Delete script.

    To add new scripts (you can download them at the end of the article) launch Metatrader 4.
    In the terminal, click File -> Open Data Directory.

    A directory with MT4 files will open.
    We need to go to the section MQL4 to catalog Scripts.

    Copy the script files that you downloaded.
    Then close the folder and restart the Metatrader 4 terminal.
    When the terminal starts up, click Ctrl + O.
    In the settings window, select the tab Advisors and set permission for automatic trading.

    Now the list with Scripts in the Navigator window has been replenished.
    But they do not work and do not react in any way to dragging and dropping a currency pair onto the chart.
    And marked with a gray diamond.

    We have script files in the original MQL4 SourceFile format ( .mq4), and the terminal works with files “EX4” ( .ex4)
    It is necessary to convert / compile mq4 to ex4.
    To do this, right-click on the script and select Change.

    The program will open MetaEditor where you need to press the button Compile and close MetaEditor.

    Now in the MT4 terminal navigation the script is marked with a yellow diamond and can be used on the chart.

    This simple operation must be done with all format scripts ( .mq4).

    As you can see, everything is very fast and easy.

    There are some useful scripts in the archive at the end of the article.
    They will help you if you work with advisors or trade hands.

    • Two informational scripts AccountInfo.mq4 and MarketInfo.mq4 displaying all information about the account and the complete specification of the instrument.

    • Script Trend_Line.mq4 draws trend lines on the chart of a currency pair. It is necessary to drag the script onto the chart, and depending on the time point at which the script was dropped, the way the script draws the lines depends.

    Scripts:

    • CloseAllLosses.mq4 - Closes all trades with a loss at the moment.
    • CloseAllOrders.mq4 - Closes all deals
    • CloseAllProfit.mq4 - Closes all trades with a profit at the moment.

    Useful scripts, but the main thing is not to confuse them. 🙂

    • SimulateTick.ex4 - the script is indispensable when working with Expert Advisors on weekends. When dropped onto a chart, it sends one tick to it. Why such a miracle is necessary?

    A common situation: I attach an Expert Advisor to the chart on the weekend. Almost all Expert Advisors start at the first tick of the price. The next tick will only be on Monday. And I would like the advisor to show an information window right now to check that everything is OK. This is where SimulateTick comes in.

    • Script put_market_order 3.0 opens an order at the market price with a specified lot, take, stop, Comment and Magik number, which is seen by the advisors.
    • Script put_pending_order 3.0 opens a pending order at a specified price with a specified lot, take, stop, Comment and Magik number, which the advisors see.

    Settings:

    Direction: order direction (Direction = 1 buy order, -1 sell order).
    StopLossPips and TakeProfitPips: stop loss and take profit orders in points (if 0, then disabled).
    StopLoss and TakeProfit: explicit setting of stop loss and take profit of the order (if 0, then disabled).
    LotSize: lot size of the order.
    Magic: order magic.
    comment: order comment.

    In the script put_pending_order 3.0 when placing an order below or above the price, the script independently places BuyLimit or BuyStop if parameter Direction: 1 and SellLimit or SellStop if parameter Direction: -1.

    You can create ready-made settings with the specified parameters and the required Magik number or compile the script with different settings separately.
    Why is this necessary?
    A common situation: your Expert Advisor, due to a failure on the VPS server, did not place or did not open an order. The Expert Advisors do not see orders opened by their hands. This is where the put_market_order 3.0 or put_pending_order 3.0 script comes in. You can open an order with a Magik number and your advisor will follow it further.

    It is convenient to use magic for manual trading as well. For example, you are trading several strategies on one account. For each strategy, you can use your own magic. Then the results of each strategy can be easily analyzed, for example, using the myfxbook service or the free one.

    Few people know that hotkeys can be assigned to scripts in the MT4 terminal. This is done very simply. You need to select a script in the Scripts section in the Navigator window, click right mouse button, select the item " Assign hotkey»And select the desired key combination.

    For manual scalping on a small timeframe, a delay of a few seconds can be critical. In such a situation, it is desirable for the script to place a trade order by pressing a combination of hot keys without unnecessary questions. With the simplest manipulations, the attached scripts can be configured in this way. I'll tell you how to do this using the put_market_order script as an example. Select the put_market_order script in the Scripts section of the Navigator window, click right mouse button, choose “ Change". The MetaEditor window opens. In it we find the line

    #property show_inputs

    and comment on it, i.e. replace with

    // # property show_inputs

    In the next lines, we set the desired values ​​of the parameters with which the script will run. For example, we want to open a buy order with 0.2 lot without stop loss and take profit. Then we only change Direction and LotSize:

    extern int Direction = 1;
    extern double LotSize = 0.2;

    Everything! Push Save(Control + S) and Compile... Now our script will be launched by pressing the hotkey and instantly place a buy order with 0.2 lots without any questions. Separately, you can create a script for sell orders, name the scripts accordingly and assign different hotkeys to them. To make changes to the settings, you need to change the script code again and compile it again.

    For more details on how this is done, see the video:

    Download: A selection of essential scripts

    Place horizontal lines on the chart and call them “BUY” (for the first buy order) and / or “SELL” (for the first sell order).

    As soon as the closing price of the bar (past) becomes above the “BUY” line, a BUY order is placed (for a sell order, the closing price of the bar must be below the “SELL” line)

    Further, the averaging lines come into operation. They can have any name and can be located anywhere on the chart. They do not need to be renamed, the Expert Advisor will understand what lines are needed for what. If the horizontal line is above the buy order, it will delete it, and if it is below it, it will consider it as its averaging line. At the same time, it will repaint it blue and make it dotted. The averaging line is the order line on which the lot will be opened with the lot increased by the coefficient K. Next, the advisor will recalculate the take profit of all orders and place it at the distance of the general breakeven.

    Example of work:

    We put a line and name it Sell.

    The price crossed the line and as soon as the candlestick closed below the line, a Sell order was placed. We put the averaging line above the open sell order (this can be done in advance along with the installation of the first line). There can be any number of averaging lines.

    As soon as the candlestick closed below the averaging line, a Sell order was placed with an increased lot. At the same time, the breakeven point (marked with a red price label) shifted higher and the take-profits of both orders were also recalculated.

    You can use the EA as a strategy tester, for this, it must be put into the tester with visualization at low speed. Next, hang the necessary indicators there and set the necessary lines in the direction of travel. Thus, you can test almost any strategy on history without ordering the development of specialized advisors.

    Greetings to dear readers. Today I want to publish some Forex scripts that have been helping me in my work for many years. Let me remind you that a script, unlike an Expert Advisor, is intended for a one-time execution of any planned action.

    Typically, scripts are run by the user, perform their function, and stop running. Scripts are usually used in cases where it is necessary to avoid the routine of the same type of work that takes time, for example, closing all positions, setting a general stop loss for the grid of orders, moving positions to breakeven, and the like.

    Scripts are installed in a folder Scripts the data catalog of the MT4 trading terminal, instructions for finding the data catalog and installing advisors, scripts, indicators are given in the article.

    Forex scripts are launched from the "Scripts" section of the navigator by double-clicking or dragging the script onto the price chart.

    I also use a wonderful function built into the MT4 terminal - setting hotkeys that allow you to call a script or indicator.

    It is very convenient if you urgently need to close all orders for the current instrument, just press the keyboard shortcuts and enjoy the result, rather than looking for the required script in the navigator, not to mention using the standard methods for managing positions provided by the Metatrader functions.
    To set the hotkey by which the script will be called, you need to select the required Forex script in the navigator, press the right mouse button and select the "Set hotkey" section in the context menu that appears. Next, in the window that opens, for the selected script, set our unique keyboard shortcut Alt with a letter, or Ctrl with a letter. Carefully study the manual of the terminal itself so as not to override the default keyboard shortcuts that operate in the terminal itself.

    So, here are the main forex scripts that I use almost every day:

    The first group includes scripts for simultaneous closing of positions and pending orders.
    KS_CloseAll- the script quickly closes all existing open positions and pending orders. It is convenient for multicurrency trading, when you need to fix the current achieved trading result. This script compares favorably with its counterparts in that it will do everything possible to complete the closing. Script fights against such phenomena as requotes, price changes, busyness of the trade flow, new order openings by other advisors or scripts, and other “intrigues” of the DC. In the script settings, you can set:

    Close all positions - Close open positions
    Delete Pended Orders - Delete pending orders
    Magic Number (-1 for all) - Use magic number
    Slippage - Allowable slippage

    west_close- the script closes all positions and deletes pending orders without first displaying a window asking whether to run the script or not, and even without displaying the parameters window. It is activated immediately after launch and works quickly. Very handy for scalping, the script sits on my hotkey Alt + K (from English Kill).

    The following scripts require dragging the script itself from the navigator window to a specific place on the price chart with the mouse.

    KS_Splitter- script for partial closing of the selected position. To select the desired position, you need to drop the script itself on the price chart directly on the order and set the volume of partial closing in lots in the window that opens.

    west_SLTP_drop- a script for the simultaneous installation of Stop-Loss and Take-Profit for all positions and orders of the current instrument at the price at which the script was thrown. Depending on which side of the position the script was thrown from, it is automatically determined by the script itself whether to set a stop or take. It is very convenient when there are many positions, when the entry is performed in parts or by a grid of orders.

    Important! To perform trade operations, the “Auto-trade” button must be pressed. Watch for this when you run scripts that perform any manipulations with positions and orders.

    And the bonus: west_objdelete- a script that removes all constructions on the chart, clears it completely from objects, even from those that have the property “not displayed in the list of objects. I also have the script on the Alt_C hotkey (from Clear - clear).

    Download forex scripts:


    Use the proposed Forex scripts and your productivity will undoubtedly increase.

    An Expert Advisor for trading along trend lines opens signals for a transaction (order) in case of contact between the price and the trend line. Trading is carried out on the pullback principle. This means that when the price crosses the support line, a BUY order will open, and when the price contacts the resistance line, a SELL order will open.

    Interested in pullback trading? Choose the right robot and start

    .

    The program monitors two lines in parallel, which the trader sets up manually. Having designated trend lines, the user needs to indicate their names given in the EA settings. After opening an order, the advisor adds its commentary to the trend line. Please note that if you do not delete this description, then the program will not open an order at the right time.

    The EA is suitable for online trading. More than one user can work on the same currency pair, if each one has his own Magic_Number settings. To start working with the Expert Advisor, you need to set trend lines and name them in accordance with the Support_Line_Name and Resistance_Line_Name parameters. Please note that it is not necessary to use two lines at the same time. If one is absent, this will normally be accepted by the program and will not cause any failures.

    Do you want to download a robot for effective trading? Use our website

    Trend lines are considered the most convenient and effective method for determining the trend that is relevant in the Forex market. The tool is suitable for identifying profitable trade entry points, and due to the simplicity of the trend line, it is realistic to use the market reversal to your advantage. So that your trading activity is not accompanied by unnecessary difficulties, use trading advisors. This is a universal assistant that you can use when composing any currency pairs. To download it for free, our Forex portal is at your service. Here you will find a lot of useful thematic information and trading robots to simplify the automation of many processes. Waiting for you.

    If you are interested in using Fractals effectively, then it is worth considering using an Expert Advisor.

    Settings:

    Support_Line_Name = "SP" - Support line name
    Resistance_Line_Name = "RS" - Resistance line name
    It is by these names that the expert will determine which lines he will work with.
    Invers_Orders = false - Inverting deals. If you enable (true) this parameter, then a Buy order will open on the resistance line instead of a Sell order, and a Sell order will open on the support line instead of a Buy order.
    SL = 50 - Stoploss size in points.
    TP = 50 - Takeprofit size in points.
    Lot = 0.1 - the volume of positions opened by the Expert Advisor.
    Show_Alert = true when this parameter is enabled, signals about opening a position.
    Magic_Number = 818798 - the unique identifier of the Expert Advisor.