using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
namespace EURUSD60PipsStrategy
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class EURUSD60PipsStrategy : Robot
{
[Parameter("Short-term MA Period", DefaultValue = 10)]
public int ShortMAPeriod { get; set; }
[Parameter("Long-term MA Period", DefaultValue = 50)]
public int LongMAPeriod { get; set; }
[Parameter("Stop Loss (in pips)", DefaultValue = 20)]
public int StopLossPips { get; set; }
[Parameter("Take Profit (in pips)", DefaultValue = 50)]
public int TakeProfitPips { get; set; }
private MovingAverage shortMA;
private MovingAverage longMA;
protected override void OnStart()
{
shortMA = Indicators.MovingAverage(Bars.ClosePrices, ShortMAPeriod, MovingAverageType.Simple);
longMA = Indicators.MovingAverage(Bars.ClosePrices, LongMAPeriod, MovingAverageType.Simple);
}
protected override void OnTick()
{
int index = MarketSeries.Close.Count - 1;
if (shortMA.Result[index] > longMA.Result[index] && shortMA.Result[index - 1] <= longMA.Result[index - 1]&& IsTimeToHedge())
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, Symbol.NormalizeVolumeInUnits(Symbol.LotSize), "Buy Order", 20, 60);
}
else if (shortMA.Result[index] < longMA.Result[index] && shortMA.Result[index - 1] >= longMA.Result[index - 1])
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, Symbol.NormalizeVolumeInUnits(Symbol.LotSize), "Sell Order", 20, 60);
}
}
private bool IsTimeToHedge()
{
// Check if the current time is 12:00 PM
if (Time.Hour == 12 && Time.Minute == 0)
{
return true; // It's time to hedge
}
return false; // It's not time to hedge
}
}
}