Category Other  Published on 12/08/2024

RSI Combine with Three White Soldiers Three Black Crows

Description

 

 

 

This cAlgo trading bot, named CombinedTradingBot, automates trading decisions based on a combination of technical indicators and price patterns. Here's a summary of how it works:

Initialization (OnStart):

  • The bot initializes the Relative Strength Index (RSI) with a specified period.
  • It stores the initial values of high and low prices, as well as RSI values, to track changes.

On Each Price Update (OnTick):

  • The bot checks for bullish divergence (price is making lower lows while RSI makes higher lows) and bearish divergence (price is making higher highs while RSI makes lower highs).
  • It also detects potential order blocks (zones where the price has strong support or resistance).
  • If a bullish divergence is detected and the RSI is below 25, it opens a buy trade after closing any sell positions.
  • If a bearish divergence is detected and the RSI is above 80, it opens a sell trade after closing any buy positions.

On Bar Close (OnBarClosed):

  • The bot executes trades based on price action patterns:
    • If a bullish reversal is detected, it opens a sell position.
    • If a bearish reversal is detected, it opens a buy position.

On Every New Bar (OnBar):

  • The bot looks for specific candlestick patterns:
    • Three White Soldiers: If three consecutive bullish candles appear, a buy trade opens.
    • Three Black Crows: If three consecutive bearish candles appear, a sell trade opens.

Order Block Detection (DetectOrderBlock):

  • The bot checks for prices being near recent highs or lows to confirm strong support or resistance levels (order blocks).

Position Management:

  • The bot closes positions when the trade conditions change and opens new positions when new conditions are met.

This bot is designed to capture reversals and continuations based on divergences, price action, and key support/resistance zones.


using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CombinedTradingBot : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", DefaultValue = 14)]
        public int Periods { get; set; }

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Stop Loss (pips)", DefaultValue = 10)]
        public int StopLossInPips { get; set; }

        [Parameter("Take Profit (pips)", DefaultValue = 20)]
        public int TakeProfitInPips { get; set; }

        [Parameter(DefaultValue = 100000)]
        public double Volume { get; set; }

        [Parameter(DefaultValue = 20)]
        public double Stoploss { get; set; }

        [Parameter(DefaultValue = 10)]
        public double Takeprofit { get; set; }

        private RelativeStrengthIndex rsi;
        private double lastHighPrice;
        private double lastLowPrice;
        private double lastRsiHigh;
        private double lastRsiLow;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
            lastHighPrice = Bars.HighPrices.Last(1);
            lastLowPrice = Bars.LowPrices.Last(1);
            lastRsiHigh = rsi.Result.LastValue;
            lastRsiLow = rsi.Result.LastValue;
        }

        protected override void OnTick()
        {
            var currentRsi = rsi.Result.LastValue;
            var currentHighPrice = Bars.HighPrices.Last(1);
            var currentLowPrice = Bars.LowPrices.Last(1);

            bool bullishDivergence = currentLowPrice < lastLowPrice && currentRsi > lastRsiLow;
            bool bearishDivergence = currentHighPrice > lastHighPrice && currentRsi < lastRsiHigh;

            bool isOrderBlock = DetectOrderBlock();

            if (bullishDivergence && isOrderBlock && currentRsi < 25)
            {
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (bearishDivergence && isOrderBlock && currentRsi > 80)
            {
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }

            lastHighPrice = currentHighPrice;
            lastLowPrice = currentLowPrice;
            lastRsiHigh = currentRsi > lastRsiHigh ? currentRsi : lastRsiHigh;
            lastRsiLow = currentRsi < lastRsiLow ? currentRsi : lastRsiLow;
        }

        protected override void OnBarClosed()
        {
            if (Bars.Last(0).Close > Bars.Last(0).Open && Bars.Last(1).Close < Bars.Last(1).Open &&
            Bars.Last(0).Close > Bars.Last(1).Open)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, Volume, InstanceId, Stoploss, Takeprofit);
            }

            if (Bars.Last(0).Close < Bars.Last(0).Open && Bars.Last(1).Close > Bars.Last(1).Open &&
            Bars.Last(0).Close < Bars.Last(1).Open)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, Volume, InstanceId, Stoploss, Takeprofit);
            }
        }

        protected override void OnBar()
        {
            //Three White Soldiers
            if (Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1)
                && Bars.ClosePrices.Last(2) > Bars.OpenPrices.Last(2)
                && Bars.ClosePrices.Last(3) > Bars.OpenPrices.Last(3))
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, Volume, "",Stoploss,Takeprofit);
            }

            //Three Black Crows
            if (Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1)
                && Bars.ClosePrices.Last(2) > Bars.OpenPrices.Last(2)
                && Bars.ClosePrices.Last(3) > Bars.OpenPrices.Last(3))
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, Volume, "",Stoploss,Takeprofit);
            }
        }

        private bool DetectOrderBlock()
        {
            var recentHigh = Bars.HighPrices.Take(5).Max();
            var recentLow = Bars.LowPrices.Take(5).Min();

            return Bars.ClosePrices.Last(1) > recentHigh || Bars.ClosePrices.Last(1) < recentLow;
        }

        private void Close(TradeType tradeType)
        {
            foreach (var position in Positions.FindAll("RSI", SymbolName, tradeType))
                ClosePosition(position);
        }

        private void Open(TradeType tradeType)
        {
            var position = Positions.Find("RSI", SymbolName, tradeType);
            var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);

            if (position == null)
            {
                var stopLossInPrice = StopLossInPips * Symbol.PipSize;
                var takeProfitInPrice = TakeProfitInPips * Symbol.PipSize;
                ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "RSI", stopLossInPrice, takeProfitInPrice);
            }
        }
    }
}


WE
Wetrader$king$

Joined on 11.08.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: LiquidityZoneBot_withSourceCode.algo
  • Rating: 5
  • Installs: 276
  • Modified: 12/08/2024 10:59
Comments
Log in to add a comment.
WE
Wetrader$king$ · 2 months ago

@ctid7027352  , @jim.tollan 
enyjoy its free

WE
Wetrader$king$ · 2 months ago

hello everyone the algo file is now available to download 
remember don't be too greedy 
and use it at your own risk 

 

WE
Wetrader$king$ · 2 months ago

i will be posting it shortly 

its taking longer than I expected 

CT
ctid7027352 · 3 months ago

would also like to try a demo version. is there a way to contact you?

JI
jim.tollan · 3 months ago

hi @tambekema how do we test this one out?? do you have a time limited demo?

looking fwd to giving this a try if you do.

cheers

jim

JI
jim.tollan · 3 months ago

hi @tambekema how do we test this one out?? do you have a time limited demo?

looking fwd to giving this a try if you do.

cheers

jim