Open trade after 3 bars
Created at 25 Jul 2022, 21:03
Open trade after 3 bars
25 Jul 2022, 21:03
Hello everyone,
I'm currently testing a bot that uses Renko bars, and it opens a trade every 2 bars. Now I was trying to figure out how to make the bot open a trade after 3 bars/bricks of the same color.
This is the code... how can i modify it for 3 or more bars?
protected override void OnBar()
{
if (Bars.ClosePrices.Last(1) > Bars.ClosePrices.Last(2))
{
Open(TradeType.Buy, InstanceName);
}
if (Bars.ClosePrices.Last(1) < Bars.ClosePrices.Last(2))
{
Open(TradeType.Sell, InstanceName);
}
}
Replies
angel773n
28 Jul 2022, 19:43
thank you for the link...you are right. This code looks "better" to work on Renko, but my knowledge is very limited, and still cannot figure out to change it to open after 2 bricks or 3 bricks of the same color in a row.
Any ideas?
using cAlgo.API;
using cAlgo.API.Extensions.Enums;
using cAlgo.API.Extensions.Models;
using cAlgo.API.Extensions.Series;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class RenkoBot : Robot
{
// Use RangeBars for Range bars
private RenkoBars _renkoBars;
// Rernko bar/box size in Pips
[Parameter("Size (Pips)", DefaultValue = 10)]
public double RankoSizeInPips { get; set; }
protected override void OnStart()
{
// You can pass any symbol and it will create its Renko/Range bars for you
_renkoBars = new RenkoBars(RankoSizeInPips, Symbol, this);
_renkoBars.OnBar += RenkoBars_OnBar;
}
// This method is called on new Renko/Range bars, you should use this method instead of OnBar method of your Robot
// The old bar is the latest completed/closed Renko/Range bar and the new bar it the current open bar
private void RenkoBars_OnBar(object sender, OhlcBar newBar, OhlcBar oldBar)
{
var positionsToClose = Positions.FindAll("RenkoBot");
if (oldBar.Type == BarType.Bullish)
{
foreach (var position in positionsToClose)
{
if (position.TradeType == TradeType.Buy) continue;
ClosePosition(position);
}
ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 1000, "RenkoBot", 10, 20);
}
else if (oldBar.Type == BarType.Bearish)
{
foreach (var position in positionsToClose)
{
if (position.TradeType == TradeType.Sell) continue;
ClosePosition(position);
}
ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 1000, "RenkoBot", 10, 20);
}
}
}
}
@angel773n
paolo.panicali
28 Jul 2022, 12:28
Have a look to this Indicator
Hi, check this post . Bar.Close won't work for Renko, you need an indicator to handle Renko. Bye
@paolo.panicali