Category Other  Published on 21/04/2023

Break even Trailling stop - Template

Description

FINALLY.!!!!!!! I have successfully been able to code this. It has no sell or buy algorithm or strategy. THIS  IS A TEMPLATE YOU CAN PUT YOUR STRATEGY IN ONBAR, OR WHEREVER. LET IT DO ITS MAGIC. COMMENT PLEASE Its my first post On CBOTS. I  give it for FREE FREE FREE 

KINDLY Donate any amount my paypal - Davidmwabuka@gmail.com

If you have  a strategy you want me to code it for you,  EMAIL ME, check me on whatsapp, phone number is on top of this cbot section. 


// copyright: Lawrence Mujari(David MWABUKA)
//
// Break even with trailling
///
// Donate any amount my paypal - Davidmwabuka@gmail.com
///
//// If you want me to code your strategy check me on whatsapp +255717441440 Very affordable price


using System;
using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class BreakevenTrailingRobot : Robot
    {
        [Parameter("Breakeven Pips", DefaultValue = 10)]
        public int BreakevenPips { get; set; }

        [Parameter("Trailing Stop Pips", DefaultValue = 10)]
        public int TrailingStopPips { get; set; }

        private Position position;

        protected override void OnStart()
        {
            position = null;
        }

        protected override void OnTick()
        {
            if (position == null)
            {
                // If we don't have a position, check if we should open one
                if (IsBuySignal())
                {
                    var volumeInUnits = Symbol.QuantityToVolume(1);
                    var result = ExecuteMarketOrder(TradeType.Buy, Symbol, volumeInUnits, "Buy", null, null);
                    position = result.Position;
                }
                else if (IsSellSignal())
                {
                    var volumeInUnits = Symbol.QuantityToVolume(1);
                    var result = ExecuteMarketOrder(TradeType.Sell, Symbol, volumeInUnits, "Sell", null, null);
                    position = result.Position;
                }
            }
            else
            {
                // If we have a position, check if we need to adjust the stop loss
                if (position.TradeType == TradeType.Buy)
                {
                    var stopLossPrice = (byte)Math.Max(position.EntryPrice + Symbol.PipSize * BreakevenPips, position.StopLoss ?? 0);
                    var takeProfitPrice = position.EntryPrice + Symbol.PipSize * TrailingStopPips;
                    var result = ModifyPosition(position, stopLossPrice, takeProfitPrice, false);
                    if (result.IsSuccessful)
                    {
                        position = result.Position;
                    }
                }
                else if (position.TradeType == TradeType.Sell)
                {
                    var stopLossPrice = (byte)Math.Min(position.EntryPrice - Symbol.PipSize * BreakevenPips, position.StopLoss ?? 0);
                    var takeProfitPrice = position.EntryPrice - Symbol.PipSize * TrailingStopPips;
                    var result = ModifyPosition(position, stopLossPrice, takeProfitPrice, false);
                    if (result.IsSuccessful)
                    {
                        position = result.Position;
                    }
                }
            }
        }

        private bool IsBuySignal()
        {
            // Check if the current bar is the first bar of the day
            if (MarketSeries.OpenTime.Last(1).Day != MarketSeries.OpenTime.LastValue.Day)
            {
                return true;
            }
            return false;
        }

        private bool IsSellSignal()
        {
            // Insert your sell signal logic here
            return false;
        }
    }
}


DA
davidmwabuka

Joined on 07.03.2023

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: BREAKevernTRAIILLING WORKING (template).algo
  • Rating: 0
  • Installs: 675
  • Modified: 21/04/2023 07:52
Comments
Log in to add a comment.
MA
martinnoha18 · 1 year ago

Great job, and you give it out for free !!!
Thanks.

AM
ameen.thaer95 · 1 year ago

Hello, I sent you a message on gmail, please reply

DA
dajiba1021 · 1 year ago

This is the type of information I’ve long been trying to find. Thank you for writing this information.우리카지노

AR
arhamabdul429 · 1 year ago

I discovered your blog post site on google and appearance a few of your early posts. Always keep within the great operate. I just now additional increase RSS feed to my MSN News Reader. Looking for toward reading more from you finding out at a later date!…Packers and Movers Bangalore

24
24evawillson · 1 year ago

It is really a great information and now I can also finally take some help from it, I am an owner of a military UK patches and I was here to find some new stuff and found it, this information helped me a lot so thanks!