Responding to Forum Request free


Saw @linton.nkambule just wanted something nice and simple.

This cBot:

- Trades either against, or with, the previous candle.

- Has a set SL and TP equidistant from the entry price based upon a percentage of the previous bar's range.

If people want any more requests built, fire us an email at, or get in contact at:

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;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class FlipBot : Robot
        [Parameter("Trade Opposite to Previous Candle?", DefaultValue = false)]
        public bool TradeOpposite { get; set; }

        [Parameter("SL/TP Percent of Previous", DefaultValue = 50, MinValue = 0)]
        public double SLTPDistance { get; set; }

        private string outName;

        protected override void OnStart()
            outName = SymbolName + "_" + this.GetType().ToString() + "_" + TimeFrame.ToString();

        protected override void OnBar()
            // Get previous bar's range:
            double rangePrice = Bars.HighPrices.Last(1) - Bars.LowPrices.Last(1);

            // Convert to the percent difference, and then into pips:
            double percentRangePips = (rangePrice * (SLTPDistance / 100)) / Symbol.PipSize;

            // Find the direction of the last bar
            bool upBar = Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1);

            // Get which trade direction we want & 0.01 lot volume
            TradeType tradeType = GetTradeDirection(upBar, TradeOpposite);
            double volume = Symbol.QuantityToVolumeInUnits(0.01);
            volume = Symbol.NormalizeVolumeInUnits(volume);

            // Open the required position:
            ExecuteMarketOrder(tradeType, SymbolName, volume, outName, percentRangePips, percentRangePips);


        private TradeType GetTradeDirection(bool up, bool tradeFlip)
            bool upTrade;

            if (tradeFlip)
                upTrade = !up;
                upTrade = up;

            if (upTrade)
                return TradeType.Buy;
                return TradeType.Sell;