Description
This robot will check for volatility by using bolinger bands, whent they expand it will check for ma crossover, if fast ma is above the slow it will buy and trail the stop and vice versa. If the bands are contracting there is no trend so it wont buy, to avoid pullbacks. optimize it modify it the way u want its free. i give it for free. . IF YOU HAVE ANY SUGGESTIONS CONTACT ME via whatsapp TO IMPROVE IT.
// copyright: Lawrence
// the power
// 17/01/2023 at 14:00 made v0.1
// at 2042hrs added parameters for rsi perios and rsi source
// at 15:30hrs added trailling stop
// today to added breakeven
// to addED ma crossing
// the bot was returning erros saying 29/03/2023 08:00:00.366 |
//Crashed in OnBar with NullReferenceException: Object reference
//not set to an instance of an object SOLUTION WAS RSI VAR DECRARED BUT UNUSED ONBAR
// add bolinger for consolidations filter now if (consolidation >= ConsolidationPeriods) //no consolidati then we can do trade
// PUBLISHED DEBUUGED
// copyright: Lawrence Mujari(David MWABUKA)
//
// Break even with trailling
///
// YOU CAN Donate any amount EVEN 1USD my paypal - Davidmwabuka@gmail.com
///
//// If you want me to code your strategy check me on whatsapp +255717441440 Very affordable price
using System;
using System.Collections.Generic;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class MyBot : Robot
{
[Parameter("Take Profit", Group = "Risk Management", DefaultValue = 0)]
public int takeProfit { get; set; }
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1000, MinValue = 1000, Step = 1000)]
public double Quantity { get; set; }
[Parameter("Stop Loss", Group = "Risk Management", DefaultValue = 5)]
public int stopLoss { get; set; }
[Parameter("Include Trailing Stop", Group = "Risk Management", DefaultValue = true)]
public bool IncludeTrailingStop { get; set; }
[Parameter("Percent K", Group = "Stochastic", DefaultValue = 5, MinValue = 0, Step = 1, MaxValue = 1000)]
public int percentK { get; set; }
[Parameter("Percent K Slowing", Group = "Stochastic", DefaultValue = 3, MinValue = 0, Step = 1, MaxValue = 1000)]
public int percentKSlow { get; set; }
[Parameter("Percent D", Group = "Stochastic", DefaultValue = 3, MinValue = 0, Step = 1, MaxValue = 1000)]
public int percentD { get; set; }
[Parameter("stoch MA Type", Group = "Stochastic")]
public MovingAverageType stochMAType { get; set; }
[Parameter("Stoch-sell threshold", Group = "Stochastic", DefaultValue = 75)]
public int sellingstoch { get; set; }
[Parameter("Stoch-buy threshold", Group = "Stochastic", DefaultValue = 35)]
public int buyingstoch { get; set; }
[Parameter("Stoch-k index", Group = "Stochastic", DefaultValue = 1, MinValue = 0, Step = 1)]
public int indexK { get; set; }
[Parameter("Stoch-d index", Group = "Stochastic", DefaultValue = 1, MinValue = 0, Step = 1)]
public int indexD { get; set; }
[Parameter("Trailing Stop Trigger (pips)", Group = "Risk Management", DefaultValue = 20)]
public int TrailingStopTrigger { get; set; }
[Parameter("Trailing Stop Step (pips)", Group = "Risk Management", DefaultValue = 10)]
public int TrailingStopStep { get; set; }
[Parameter("Include Break-Even", Group = "Risk Management", DefaultValue = false)]
public bool IncludeBreakEven { get; set; }
[Parameter("Break-Even Trigger (pips)", Group = "Risk Management", DefaultValue = 10, MinValue = 1)]
public int BreakEvenPips { get; set; }
[Parameter("Break-Even Extra (pips)", Group = "Risk Management", DefaultValue = 2, MinValue = 1)]
public int BreakEvenExtraPips { get; set; }
//MA
[Parameter("MA Type", Group = "Moving Average")]
public MovingAverageType MAType { get; set; }
//MA SOURCE
[Parameter("Source", Group = "Moving Average")]
public DataSeries SourceSeries { get; set; }
// [Parameter("Slow Periods", Group = "Moving Average", DefaultValue = 100)]
// public int SlowPeriods { get; set; }
[Parameter("Fast Periods", Group = "Moving Average", DefaultValue = 5)]
public int FastPeriods { get; set; }
[Parameter("Number of bars to consider", DefaultValue = 2)]
public int BarsToConsider { get; set; }
//MA
[Parameter("bSource", Group = "Bollinger Bands")] ///bollonger
public DataSeries bSource { get; set; }
[Parameter("Band Height (pips)", Group = "Bollinger Bands", DefaultValue = 40.0, MinValue = 0)]
public double BandHeightPips { get; set; }
[Parameter("Bollinger Bands Deviations", Group = "Bollinger Bands", DefaultValue = 2)]
public double Deviations { get; set; }
[Parameter("Bollinger Bands Periods", Group = "Bollinger Bands", DefaultValue = 20)]
public int bPeriods { get; set; }
[Parameter("Bollinger Bands MA Type", Group = "Bollinger Bands")]
public MovingAverageType bMAType { get; set; }
[Parameter("Consolidation Periods", Group = "Bollinger Bands", DefaultValue = 2)] ///bollonger
public int ConsolidationPeriods { get; set; }
[Parameter("Number of Bars Above Top Band", Group = "Bollinger Bands", DefaultValue = 5)]
public int NumBarsAboveTop { get; set; }
[Parameter("Number of Bars Below Bottom Band", Group = "Bollinger Bands", DefaultValue = 5)]
public int NumBarsBelowBottom { get; set; }
[Parameter("Working TimeFrame", DefaultValue = "H4")]
public TimeFrame inpTF1 { get; set; }
BollingerBands bollingerBands;
int consolidation;
private MovingAverage slowMa;
private MovingAverage fastMa;
private const string label = "Kilimanjaro peaks cBot";
private StochasticOscillator stochasticOscillator;
protected override void OnStart()
{
fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
slowMa = Indicators.MovingAverage(SourceSeries, 50, MAType);
stochasticOscillator = Indicators.StochasticOscillator(percentK, percentKSlow, percentD, stochMAType);
bollingerBands = Indicators.BollingerBands(bSource, bPeriods, Deviations, bMAType);
}
protected override void OnTick()
{
if (IncludeTrailingStop)
{
SetTrailingStop();
}
if (IncludeBreakEven)
{
var allPositionsBySymbol = Positions.FindAll(string.Empty, SymbolName);
BreakEvenAdjustment(allPositionsBySymbol);
}
}
protected override void OnBar()
{
var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);
var currentSlowMa = slowMa.Result.Last(0);
var currentFastMa = fastMa.Result.Last(0);
var previousSlowMa = slowMa.Result.Last(1);
var previousFastMa = fastMa.Result.Last(1);
////////////////////////////////////////////////////bollinger filter////////////////////////////////////////////////////////////////////////////////////////////
var top = bollingerBands.Top.Last(1);
var bottom = bollingerBands.Bottom.Last(1);
/////check for sequencial bara on bolinger
if (top - bottom <= BandHeightPips * Symbol.PipSize)
{
consolidation = consolidation + 1;
Print("Consolidating");
}
else
{
consolidation = 0;
}
if (consolidation >= ConsolidationPeriods) //no consolidation
{
///my algo
if (currentFastMa > currentSlowMa && longPosition == null)
{
if (Bars.ClosePrices.Last(2) < Bars.HighPrices.Last(BarsToConsider + 1) && Bars.LowPrices.Last(2) < Bars.LowPrices.Last(BarsToConsider + 1))
{
// Higher highs and higher lows, check for sell signal
if (Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1) && stochasticOscillator.PercentK.Last(indexK) < buyingstoch && stochasticOscillator.PercentD.Last(indexD) < buyingstoch)
//&& rsi.Result.LastValue < buyRSI
{
if (shortPosition != null)
ClosePosition(shortPosition);
ExecuteMarketOrder(TradeType.Buy, SymbolName, Quantity, "Scalp", stopLoss, takeProfit);
}
}
}
}
if (consolidation >= ConsolidationPeriods) //no consolidation
{
if (currentFastMa < currentSlowMa && shortPosition == null)
{
if (Bars.ClosePrices.Last(2) > Bars.HighPrices.Last(BarsToConsider + 1) && Bars.LowPrices.Last(2) > Bars.LowPrices.Last(BarsToConsider + 1))
{
// lower lows and lower high, check for sell signal
if (Bars.ClosePrices.Last(1) < Bars.OpenPrices.Last(1) && stochasticOscillator.PercentK.Last(indexK) > sellingstoch && stochasticOscillator.PercentD.Last(indexD) > sellingstoch)
//&& rsi.Result.LastValue > sellRSI && stochasticOscillator.PercentK.Last(2) > sellingstoch
{
if (longPosition != null)
ClosePosition(longPosition);
ExecuteMarketOrder(TradeType.Sell, SymbolName, Quantity, "Scalp", stopLoss, takeProfit);
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////bollinger filter////////////////////////////////////////////////////////////////////////////////////////////
// bullish signal detected
}
private void SetTrailingStop()
{
var sellPositions = Positions.FindAll("Scalp", SymbolName, TradeType.Sell);
foreach (Position position in sellPositions)
{
double distance = position.EntryPrice - Symbol.Ask;
if (distance < TrailingStopTrigger * Symbol.PipSize)
continue;
double newStopLossPrice = Symbol.Ask + TrailingStopStep * Symbol.PipSize;
if (position.StopLoss == null || newStopLossPrice < position.StopLoss)
{
ModifyPosition(position, newStopLossPrice, position.TakeProfit);
}
}
var buyPositions = Positions.FindAll("Scalp", SymbolName, TradeType.Buy);
foreach (Position position in buyPositions)
{
double distance = Symbol.Bid - position.EntryPrice;
if (distance < TrailingStopTrigger * Symbol.PipSize)
continue;
double newStopLossPrice = Symbol.Bid - TrailingStopStep * Symbol.PipSize;
if (position.StopLoss == null || newStopLossPrice > position.StopLoss)
{
ModifyPosition(position, newStopLossPrice, position.TakeProfit);
}
}
}
/// break even plus (x) pips
/// </summary>
private void BreakEvenAdjustment(IList<Position> allPositions)
{
foreach (Position position in allPositions)
{
if (position.StopLoss != null)
return;
var entryPrice = position.EntryPrice;
var distance = position.TradeType == TradeType.Buy ? Symbol.Bid - entryPrice : entryPrice - Symbol.Ask;
// move stop loss to break even plus and additional (x) pips
if (distance >= BreakEvenPips * Symbol.PipSize)
{
if (position.TradeType == TradeType.Buy)
{
if (position.StopLoss <= position.EntryPrice + (Symbol.PipSize * BreakEvenExtraPips) || position.StopLoss == null)
{
ModifyPosition(position, position.EntryPrice + (Symbol.PipSize * BreakEvenExtraPips), position.TakeProfit);
Print("Stop Loss to Break Even set for BUY position {0}", position.Id);
}
}
else
{
if (position.StopLoss >= position.EntryPrice - (Symbol.PipSize * BreakEvenExtraPips) || position.StopLoss == null)
{
ModifyPosition(position, entryPrice - (Symbol.PipSize * BreakEvenExtraPips), position.TakeProfit);
Print("Stop Loss to Break Even set for SELL position {0}", position.Id);
}
}
}
}
}
}
}
davidmwabuka
Joined on 07.03.2023
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: 01.05 kilimanjaroXngorongoro v2 (2) + bb (2).algo
- Rating: 0
- Installs: 763
- Modified: 13/05/2023 08:29
Comments
Perhaps you should also a put a forum site on your blog to increase reader interaction.;*,”,How to become a payment processor
Perhaps you should also a put a forum site on your blog to increase reader interaction.;*,”,<a href="https://shawmerchantgroup.medium.com/credit-card-processing-residual-income-merchant-services-commission-structure-ffef0fa69fff">How to become a payment processor</a>
My partner and i favour your overall write-up. It could be great to look at any person describe inside terms from the aerobic in addition to lucidity because of this essential problem could be swiftly noticed.selling credit card processing
Hi. Thanks for this bot! I've found promising results when optimizing the bot. Maybe you can add the option to close the positons on the opposite signal? (true, false)
I SUPPOSE U CAN LIMIT NUMBER OF TRADES. THIS BT NEEDS TO BE LIMITED IN NUMER OF TRADES. DONT USE IT ON LIVE ACCOUNT
TRY THESE CBOTSET https://drive.google.com/file/d/1aUiAn6uCu5QCojMbs4c2vvxRJQHHslHU/view?usp=sharing
I suggest you first optimize with capital u like, and use tick data and save cbotset. regarding posting let me get back and give u cbotset okay let me do that again, i make a lot of cbots, i forgot about this. its a good cBOT THOUGH.
Interesting, can you add some backtest details? At a first quick attempt with different assets and different timeframes it does not open positions.
Clients marketing strategies that you choose to useful survey before establishing. It can be straightforward to jot down top-quality write-up like this. white label payment processing