Well i am asking a simple thing from C# language
Well i am asking a simple thing from C# language
10 Jan 2023, 21:02
I have made this code with help of chatGPT and now Chat GPT sucks
i want to take a trade on last candle high for sell and last candle low for buy with stop loss and TP simple.. can someone help me fix this code..
using System;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class CandleTouchBot : Robot
{
[Parameter("Stop Loss (pips)", DefaultValue = 30)]
public int StopLoss { get; set; }
[Parameter("Take Profit (pips)", DefaultValue = 30)]
public int TakeProfit { get; set; }
[Parameter("Volume", DefaultValue = 1000, MinValue = 0)]
public int Volume { get; set; }
private double lastClosedCandleHigh;
private double lastClosedCandleLow;
protected override void OnStart()
{
// Initialize values for last closed candle high and low
lastClosedCandleHigh = Highest.pricesLastValue;
lastClosedCandleLow = lowest.pricesLastValue;
}
protected override void OnTick()
{
//update the last closed candle values
if (MarketSeries.OpenTime.LastValue > MarketSeries.OpenTime.Last(1) && (MarketSeries.CloseTime.LastValue - MarketSeries.OpenTime.LastValue).TotalMinutes >= Symbol.Period.ToMinutes())
{
lastClosedCandleHigh = MarketSeries.High.LastValue;
lastClosedCandleLow = MarketSeries.Low.LastValue;
}
// Check if current market price is touching last closed candle high
if (MarketSeries.LastValue >= lastClosedCandleHigh)
{
// Place a sell order
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Touching last closed candle high", StopLoss, TakeProfit);
}
// Check if current market price is touching last closed candle low
if (MarketSeries.LastValue <= lastClosedCandleLow)
{
// Place a buy order
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Touching last closed candle low", StopLoss, TakeProfit);
}
}
}
}