Category Other  Published on 14/07/2014

MT2cTrader Trade Copier

Description

This cBot allows traders to send their signals from any metatrader (MT4/5) platform to an unlimited amount of cTrader platforms ( Limited to available RAM resources on instance) through reading/writing to a CSV file. MT4/5 writes the trading activity to csv file, while cAlgo reads the file to copy the trades. 

[siamfx] - July 04, 2014 @ 04:14

Error: - Copy and paste over existing code in catch (Exception e) with the code below. 

 

catch (Exception e)

            {

                Print("Exception: " + e.Message); 

                 return;

            }

 

 

 

  • MT EA loops every 250ms for new trading activity 
  • cBot will open and close Market orders to match the csv file
  • No additional trading can be performed on ctrader slave. 
  • All trading must be done on the master MT account.
  • Limited to one MT master account with unlimited cTrader accounts 
  • Trader passwords required for access of all accounts and designed for Server Based. 

You will need to update the Orders Input File Path: Unique for every PC

Sample: C:\\Users\\trader\\AppData\\Roaming\\MetaQuotes\\Terminal\\69420FB8433504FEA0FA029C390238DB\\MQL4\\Files\\TradeCopy.csv

Version 1.0:

Todo list includes

  1. Add Market Depth 
  2. Use Limit Orders
  3. Only Positive Slippage

 

This is the MetaTrader EA below - download. Copy this code into a new Experts sample, paste, compile. Attach to M1 chart. Only 1 chart to trade ALL currency pairs. MT4 - Build 600+ -July 2014  (old source -http://code.google.com/p/mt4-trade-copy/)

http://siamfx.net/wp-content/uploads/2014/07/MT2cTrader_MT2.zip

// ---------------------------------------------------------------------------------------
//
//    CSV reader to open and close market orders  
//    mt4 writes to file 
//    version1 
//    lotsize calculation fixed _july1_siamfx
//
// ---------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    //AccessRights.FullAccess

    public class MT2cTrader : Robot
    {

        [Parameter("Orders Input File Path", DefaultValue = "C:\\Users\\trader\\AppData\\Roaming\\MetaQuotes\\Terminal\\69420FB8433504FEA0FA029C390238DB\\MQL4\\Files\\TradeCopy.csv")]
        // C:\\Users\\trader\\CSV\\TradeCopy.csv

        public string orders_input_file { get; set; }

        [Parameter("Slippage", DefaultValue = 3.5)]
        public double slippage { get; set; }


        [Parameter("Delimiter", DefaultValue = ";")]
        public string delimiter { get; set; }

        protected override void OnStart()
        {

        }

        private bool debug = true;

        protected override void OnTick()
        {
            //todo, check M.D.
            //price = marketDepth.AskEntries[0].Price; 
            //volume = marketDepth.AskEntries[0].Volume;

            string[] lines = new String[0];

            try
            {
                lines = File.ReadAllLines(orders_input_file);

            } catch (Exception e)
            {
                Print("Exception: " + e.Message);
            }

            List<string> existing_positions = new List<string>();

            foreach (string line in lines)
            {

                OrderData order = new OrderData(line.Split(delimiter.Length > 0 ? delimiter[0] : ','), MarketData);
                existing_positions.Add(order.label);

                if (debug)
                    Print(line);

                if (order.isCorrect() && (Positions.Find(order.label) == null))
                    ExecuteMarketOrder(order.type, order.symbol, order.lot, order.label, order.sl, order.tp, slippage);
            }

            for (int pos = 0; pos < Positions.Count; pos++)
                if (!existing_positions.Contains(Positions[pos].Label))
                    ClosePosition(Positions[pos]);
        }

    }

    public class OrderData
    {

        private const long mt_lot_coefficient = 100000;
        //corrected_100000_july1
        public Symbol symbol;
        public TradeType type;
        public long lot;
        public int sl;
        public int tp;
        public string label;
        private bool initialized_properly = true;

        public OrderData(string[] raw_pieces, MarketData market_data)
        {
            try
            {
                this.label = raw_pieces[0].Trim();
                this.symbol = market_data.GetSymbol(raw_pieces[1].Trim());
                this.setType(Convert.ToInt32(raw_pieces[2].Trim()));
                this.lot = Convert.ToInt64(this.parseDouble(raw_pieces[3]) * mt_lot_coefficient);
                double price = this.parseDouble(raw_pieces[4]);
                this.sl = this.getPipDistance(price, this.parseDouble(raw_pieces[5]));
                this.tp = this.getPipDistance(price, this.parseDouble(raw_pieces[6]));
            } catch (Exception e)
            {
                this.initialized_properly = false;
            }
        }

        public bool isCorrect()
        {
            return this.initialized_properly;
        }

        private double parseDouble(string value)
        {
            return double.Parse(value.Trim().Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture);
        }





        private void setType(int mt_type)
        {
            this.type = mt_type == 0 ? TradeType.Buy : TradeType.Sell;
        }

        private int getPipDistance(double basic_price, double close_price)
        {
            return Convert.ToInt32(Math.Round(Math.Abs(basic_price - close_price) / this.symbol.PipSize));
        }

    }

}


SI
siamfx

Joined on 01.07.2014

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: MT2cTrader.algo
  • Rating: 2.5
  • Installs: 3743
  • Modified: 13/10/2021 09:55
Comments
Log in to add a comment.
ctrader.guru's avatar
ctrader.guru · 1 month ago

I recommend using Copiix https://copiix.com 100% free with superpower

CA
caqua · 2 months ago

To copy trades from MT4 or MT5 to cTrader I'm using Duplikium Trade Copier.

It's cloud based, so nothing to install and you can access it from your mobile phone anytime.

Check it here: https://www.trade-copier.com

ME
megamemo · 9 years ago

hey man i can not find the ea version the link is down somebody please cut pass me that is count of urgent

 

ME
megamemo · 9 years ago

hey man thanks alot is really usefull

 

KA
kamol · 9 years ago

16/02/2015 23:55:36.797 | TradeCopierReceiver, USDJPY, h1 | Failed to read file: Arguments mismatch at line: X

What does it meal? What I have to do?

SwapBridgeCapital's avatar
SwapBridgeCapital · 9 years ago

Can this be converted to use from cTrader to cTrader with same method?

aisaac's avatar
aisaac · 10 years ago

and copy pending orders.

aisaac's avatar
aisaac · 10 years ago

is possible copy to ctrade at mt4 ?

 

no mt4 to ctrade, the opposite.

 

thanks.

SI
siamfx · 10 years ago

Error: - Copy and paste over existing code in catch (Exception e) with the code below. 

 

catch (Exception e)

            {

                Print("Exception: " + e.Message); 

                 return;

            }

MT
mt2ct · 10 years ago

One more trade copier: mt2ct.com

SI
siamfx · 10 years ago

Yes, cBot works onTick. cTrader recently added onTimer support. The whole onTick function can be copied into the onTimer to achieve the looping every 250ms.  Currently, MT4 loops every 250ms, and cBot opens/closes onTick

 

 

Invalid's avatar
Invalid · 10 years ago

As far as I see, you read file in OnTick method. In this case bellow statement is not guaranteed

  • MT EA loops every 250ms for new trading activity