making ALGO hedging bot Bias utilizing trend lines

Created at 14 Mar 2024, 17:23
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
LU

lucasnauta

Joined 03.03.2024

making ALGO hedging bot Bias utilizing trend lines
14 Mar 2024, 17:23


i have a working Hedging bot.  a crude Random buy sell Generator That has Set TP SL.  but i wanted to implement a Trendline bias That Adjusts the Bots Bias and maybe Closes opposite direction trades (losing trades).     here is original code




using cAlgo.API;

using System;


 

namespace cAlgo.Robots

{

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

public class RandomComplexTradingBot : Robot

{

private Random _random;


 

[Parameter("Volume (Lots)", DefaultValue = 0.1)]

public double VolumeInLots { get; set; }


 

[Parameter("Stop Loss (Pips)", DefaultValue = 10)]

public int StopLossInPips { get; set; }


 

[Parameter("Take Profit (Pips)", DefaultValue = 10)]

public int TakeProfitInPips { get; set; }


 

[Parameter("Label", DefaultValue = "RandomComplexBot")]

public string Label { get; set; }


 

[Parameter("Max Bars Back", DefaultValue = 10)]

public int MaxBarsBack { get; set; }


 

[Parameter("Min Bars Back", DefaultValue = 5)]

public int MinBarsBack { get; set; }


 

protected override void OnStart()

{

_random = new Random();

}


 

protected override void OnBar()

{

// Randomly choose to buy or sell

TradeType tradeType = _random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;


 

// Use fixed volume

var volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);


 

// Randomly choose an entry point within the last MinBarsBack to MaxBarsBack bars

int barsBack = _random.Next(MinBarsBack, MaxBarsBack + 1);


 

// Execute market order with fixed volume

var position = ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, Label, StopLossInPips, TakeProfitInPips);

}

}

}









Here is All i can come up with. i dont know What im doing Here maybe some direction here would help me alot



using cAlgo.API;

using System;


 

namespace cAlgo.Robots

{

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

public class LineGuidedRandomTrader : Robot

{

private Chart _chart;

private ChartTrendLine _bullishLine;

private ChartTrendLine _bearishLine;

private bool _isBullishLineActive = false;

private bool _isBearishLineActive = false;

private TradeType _bias = TradeType.Buy; // Default bias is Buy


 

protected override void OnStart()

{

_chart = Chart;

_chart.MouseDown += OnChartMouseDown;


 

// Start random trading

ExecuteRandomTrade();

}


 

private void OnChartMouseDown(ChartMouseEventArgs args)

{

if (!_isBullishLineActive)

{

DrawAngledLine(args, Color.Green, ref _bullishLine);

_isBullishLineActive = true;

_isBearishLineActive = false;

_bias = TradeType.Buy; // Set bias to Buy

}

else if (!_isBearishLineActive)

{

DrawAngledLine(args, Color.Red, ref _bearishLine);

_isBearishLineActive = true;

_isBullishLineActive = false;

_bias = TradeType.Sell; // Set bias to Sell

}

}


 

private void DrawAngledLine(ChartMouseEventArgs args, Color color, ref ChartTrendLine line)

{

// Your code to draw an angled line goes here

}


 

private void ExecuteRandomTrade()

{

// Randomly choose to buy or sell based on the bias

TradeType tradeType = _bias;


 

// Use fixed volume

var volumeInUnits = Symbol.QuantityToVolumeInUnits(0.1); // Example volume


 

// Execute market order with fixed volume

var position = ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "RandomTrade", null, null);

}


 

protected override void OnTick()

{

// Your breakout trading logic here

}

}

}


 

Thanks to anyone who replies any help would be great 

my random trading bot is very profitable IF the market is sideways.. Trying to solve it    i believe with Simplicity we can Potentially make a profitable trading bot
 


@lucasnauta