Help with a Renko bot
05 Sep 2017, 17:51
I'm currently working on a robot that uses 'tmc's' excellent Renko indicator (link below). It's a great indicator but I’m having trouble creating a robot with it.
What I would like to do is have the bot create one trade per renko bar. I do not wish to have just one trade active, but multiple trades, with each one created with each new renko bar. At the moment when I use 'ExecuteMarketOrder' or a pending limit/stop order it creates multiple trades within one renko bar.
To expand on this: for each Bullish renko bar it would create a new buy trade | for each Bearish renko bar it would create a new sell trade
If there are those out there with suggestions and guidance your help would be greatly appreciated.
The code I have developed thus far is below.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot()]
public class RENKO : Robot
{
//################################################## - Bot Label - ##################################################
[Parameter(DefaultValue = "TEST")]
public string cBotLabel { get; set; }
//################################################## - RENKO details - #############################################
[Parameter(DefaultValue = 100)]
public double RenkoPips { get; set; }
//public double RenkoPips = 50;
public int BricksToShow = 10000;
private Renko renko;
//################################################## - Other parameters - #############################################
[Parameter(DefaultValue = 1000)]
public int Volume { get; set; }
[Parameter("Take Profit (pips)", DefaultValue = 2000)]
public double TakeProfit { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 500)]
public double StopLoss { get; set; }
//################################################## - Dynamic stops - #############################################
[Parameter("Break Even Trigger", DefaultValue = 100)]
public double SL1Trigger { get; set; }
[Parameter("Break Even", DefaultValue = 25)]
public double SL1 { get; set; }
[Parameter("Trailing Stop Trigger", DefaultValue = 525)]
public double SL2Trigger { get; set; }
[Parameter("Trailing Stop Level", DefaultValue = 500)]
public double SL2 { get; set; }
//################################################## - Buy/Sell range - #############################################
[Parameter("Target Price 1", DefaultValue = 25)]
public double TP1 { get; set; }
[Parameter("Target Price 2", DefaultValue = 50)]
public double TP2 { get; set; }
[Parameter("Target Price 3", DefaultValue = 75)]
public double TP3 { get; set; }
[Parameter("Target Price 4", DefaultValue = 100)]
public double TP4 { get; set; }
[Parameter(DefaultValue = 4)]
public int MaxPositions { get; set; }
//################################################## - OnStart - ##################################################
protected override void OnStart()
{
renko = Indicators.GetIndicator<Renko>(RenkoPips, BricksToShow, 3, "SeaGreen", "Tomato");
}
//################################################## - OnTick - ##################################################
protected override void OnTick()
{
var cBotPositions = Positions.FindAll(cBotLabel);
foreach (var order in PendingOrders)
{
var MaxOrderPositions = PendingOrders.Count;
if (MaxOrderPositions > MaxPositions)
{
Stop();
}
}
bool lastBullish = renko.Close.LastValue > renko.Open.LastValue;
bool lastBearish = renko.Close.LastValue < renko.Open.LastValue;
double Close = renko.Close.LastValue;
double Open = renko.Open.LastValue;
double Target1 = Close + (TP1 * Symbol.PipSize);
double Target2 = Close + (TP2 * Symbol.PipSize);
double Target3 = Close + (TP3 * Symbol.PipSize);
double Target4 = Close + (TP4 * Symbol.PipSize);
double Target5 = Close - (TP1 * Symbol.PipSize);
double Target6 = Close - (TP2 * Symbol.PipSize);
double Target7 = Close - (TP3 * Symbol.PipSize);
double Target8 = Close - (TP4 * Symbol.PipSize);
// -- Condition to buy --
if (Symbol.Ask > Open)
{
PlaceStopOrder(TradeType.Buy, Symbol, Volume, Target1, cBotLabel, StopLoss, TakeProfit);
//PlaceStopOrder(TradeType.Buy, Symbol, Volume, Target2, cBotLabel, StopLoss, TakeProfit);
//PlaceStopOrder(TradeType.Buy, Symbol, Volume, Target3, cBotLabel, StopLoss, TakeProfit);
//PlaceStopOrder(TradeType.Buy, Symbol, Volume, Target4, cBotLabel, StopLoss, TakeProfit);
}
// -- Condition to sell --
else if (Symbol.Bid < Open)
{
PlaceStopOrder(TradeType.Sell, Symbol, Volume, Target5, cBotLabel, StopLoss, TakeProfit);
//PlaceStopOrder(TradeType.Sell, Symbol, Volume, Target6, cBotLabel, StopLoss, TakeProfit);
//PlaceStopOrder(TradeType.Sell, Symbol, Volume, Target7, cBotLabel, StopLoss, TakeProfit);
//PlaceStopOrder(TradeType.Sell, Symbol, Volume, Target8, cBotLabel, StopLoss, TakeProfit);
}
StopLossOne();
StopLossTwo();
}
//################################################## - Stop Loss Details - ##################################################
protected void StopLossOne()
{
var positions = Positions.FindAll(cBotLabel);
if (positions == null)
return;
foreach (var position in positions)
{
if (position.Pips >= SL1Trigger)
{
if (position.TradeType == TradeType.Buy)
{
var newStopLoss = position.EntryPrice + SL1 * Symbol.PipSize;
if (position.StopLoss < newStopLoss)
ModifyPosition(position, newStopLoss, position.TakeProfit);
}
else if (position.TradeType == TradeType.Sell)
{
var newStopLoss = position.EntryPrice - SL1 * Symbol.PipSize;
if (position.StopLoss > newStopLoss)
ModifyPosition(position, newStopLoss, position.TakeProfit);
}
}
}
}
protected void StopLossTwo()
{
var positions = Positions.FindAll(cBotLabel);
if (positions == null)
return;
foreach (var position in positions)
{
if (position.Pips >= SL2Trigger)
{
if (position.TradeType == TradeType.Buy)
{
var newStopLoss2 = Symbol.Bid - SL2 * Symbol.PipSize;
if (position.StopLoss < newStopLoss2)
ModifyPosition(position, newStopLoss2, position.TakeProfit);
}
else if (position.TradeType == TradeType.Sell)
{
var newStopLoss2 = Symbol.Ask + SL2 * Symbol.PipSize;
if (position.StopLoss > newStopLoss2)
ModifyPosition(position, newStopLoss2, position.TakeProfit);
}
}
}
}
}
}
Again, any help would be greatly appreciated.
And the limk to tmc's geat indicator: /algos/indicators/show/1086

spinmaker
23 Jun 2018, 06:32
RE:
Hello, did you end up getting this going?
@spinmaker