Simple Grid

by jumpycalm in category Range at 08/07/2019
Description

This cBot is very simple but will make you great profit in the long run. Great for trading Forex as an investment. Please only run this cBot in the direction you have positive swap since this cBot will hold each position for very long time.

In this example, IC Markets has positive swap in the short position for EURUSD, therefore, you run this bot in the short position. During the last 1 year's back test, the cBot trippled your account. This bot works on other pairs and other products as well.

I am a software developer, I work for myself, there's no middleman involved. If you have a strategy and would like me to write the code for you. I can offer you the best price in the market. I only write cBot and cTrader indicators. I do not write MT4 and MT5 code.

For business contact, email me at info@mrkeyfob.com

 

Download
102 downloads
How to install
Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class JCSimpleGrid : Robot
    {
        [Parameter("Long position?", Group = "Basic Setup", DefaultValue = true)]
        public bool IfOpenBuy { get; set; }

        [Parameter("First order volume", Group = "Basic Setup", DefaultValue = 1000, MinValue = 1, Step = 1)]
        public double InitialVolume { get; set; }

        [Parameter("Grid size in points", Group = "Basic Setup", DefaultValue = 200, MinValue = 10)]
        public int GridSizeInPoints { get; set; }

        private string thiscBotLabel;

        protected override void OnStart()
        {
            // Set position label to cBot name
            thiscBotLabel = GetType().Name;
            // Normalize volume in case a wrong volume was entered
            if (InitialVolume != (InitialVolume = Symbol.NormalizeVolumeInUnits(InitialVolume)))
            {
                Print("Initial volume entered incorrectly, volume has been changed to ", InitialVolume);
            }
        }

        protected override void OnTick()
        {
            if (IfOpenBuy)
            {
                if (Positions.Count(x => x.TradeType == TradeType.Buy && x.SymbolName == SymbolName && x.Label == thiscBotLabel) == 0)
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, InitialVolume, thiscBotLabel,null, GridSizeInPoints * Symbol.TickSize / Symbol.PipSize);
                else if (Symbol.Ask <= Positions.FindAll(thiscBotLabel, SymbolName, TradeType.Buy).Last().EntryPrice - GridSizeInPoints * Symbol.TickSize)
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, InitialVolume * (Positions.Count(x => x.TradeType == TradeType.Buy && x.SymbolName == SymbolName && x.Label == thiscBotLabel) + 1), thiscBotLabel, null, GridSizeInPoints * Symbol.TickSize / Symbol.PipSize);
            }
            else
            {
                if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == thiscBotLabel) == 0)
                    ExecuteMarketOrder(TradeType.Sell, SymbolName, InitialVolume, thiscBotLabel, null, GridSizeInPoints * Symbol.TickSize / Symbol.PipSize);
                else if (Symbol.Bid >= Positions.FindAll(thiscBotLabel, SymbolName, TradeType.Sell).Last().EntryPrice + GridSizeInPoints * Symbol.TickSize)
                    ExecuteMarketOrder(TradeType.Sell, SymbolName, InitialVolume * (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == thiscBotLabel) + 1), thiscBotLabel, null, GridSizeInPoints * Symbol.TickSize / Symbol.PipSize);
            }
        }

        protected override void OnStop()
        {
            // Close all open positions opened by this cBot on stop during backtesting
            if (IsBacktesting)
            {
                foreach (var position in Positions)
                {
                    if (position.SymbolName == SymbolName && position.Label == thiscBotLabel)
                        ClosePosition(position);
                }
            }
        }
    }
}
Comments
0