Couldn't quite crack this one. Managed around -1% ROI when optimised:Archery1969 wrote: ↑Tue Jan 02, 2024 12:15 pmNot really sure why people are saying you cant make money out of Forex Trading. There are some things you need to be aware of that move the markets like Tokyo, London, New York openings but its not difficult. Just look for breakouts on any Forex charts at certain times of a 24 hour day.
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class BreakoutStrategy : Robot
{
[Parameter("Volume", DefaultValue = 1000)]
public int Volume { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 10)]
public int StopLoss { get; set; }
[Parameter("Take Profit (pips)", DefaultValue = 20)]
public int TakeProfit { get; set; }
[Parameter("MA Period", DefaultValue = 14)]
public int MAPeriod { get; set; }
private Bars _hourBars;
private double _stopLossPips;
private double _takeProfitPips;
private MovingAverage _ma;
protected override void OnStart()
{
_hourBars = MarketData.GetBars(TimeFrame.Hour);
_stopLossPips = StopLoss * Symbol.PipSize;
_takeProfitPips = TakeProfit * Symbol.PipSize;
_ma = Indicators.MovingAverage(_hourBars.ClosePrices, MAPeriod, MovingAverageType.Simple);
}
protected override void OnBar()
{
Print("New bar: ", _hourBars.OpenTimes.LastValue);
// Check market open times and significant price movement over last 3 bars
if ((_hourBars.OpenTimes.LastValue.Hour == 7 || _hourBars.OpenTimes.LastValue.Hour == 12) &&
(_hourBars.HighPrices.Last(1) - _hourBars.LowPrices.Last(1) >= 0.0002 ||
_hourBars.HighPrices.Last(2) - _hourBars.LowPrices.Last(2) >= 0.0002 ||
_hourBars.HighPrices.Last(3) - _hourBars.LowPrices.Last(3) >= 0.0002))
{
Print("Market open time detected: ", _hourBars.OpenTimes.LastValue);
double currentOpen = _hourBars.OpenPrices.LastValue;
double currentHigh = _hourBars.HighPrices.LastValue;
double currentLow = _hourBars.LowPrices.LastValue;
double currentClose = _hourBars.ClosePrices.LastValue;
double maValue = _ma.Result.LastValue;
Print("Current prices - Open: ", currentOpen, " High: ", currentHigh, " Low: ", currentLow, " Close: ", currentClose, " MA: ", maValue);
if (currentClose > maValue)
{
Print("Executing Buy order");
ExecuteMarketOrder(TradeType.Buy, SymbolName, Volume, "BreakoutStrategy", StopLoss, TakeProfit);
}
else if (currentClose < maValue)
{
Print("Executing Sell order");
ExecuteMarketOrder(TradeType.Sell, SymbolName, Volume, "BreakoutStrategy", StopLoss, TakeProfit);
}
}
}
protected override void OnStop()
{
Print("cBot stopped");
}
}
}