Description
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class GBPUSDStrategy : Robot
{
[Parameter(DefaultValue = "GBPUSD")]
public string Symbol { get; set; }
[Parameter(DefaultValue = "H1")]
public string Timeframe { get; set; }
[Parameter(DefaultValue = 1000)]
public double Capital { get; set; }
[Parameter(DefaultValue = 0.02)]
public double RiskPerTrade { get; set; }
[Parameter(DefaultValue = 0.0001)]
public double PipSize { get; set; }
private Indicator EMA50;
private Indicator EMA100;
private Indicator RSI;
protected override void OnStart()
{
EMA50 = Indicators.ExponentialMovingAverage(MarketData.GetSeries(Symbol, Timeframe, "H1"), 50);
EMA100 = Indicators.ExponentialMovingAverage(MarketData.GetSeries(Symbol, Timeframe, "H1"), 100);
RSI = Indicators.RelativeStrengthIndex(MarketData.GetSeries(Symbol, Timeframe, "H1"), 14);
}
protected override void OnTick()
{
// Check if the conditions are met to open a buy order
if (EMA50.Result.LastValue > EMA100.Result.LastValue && RSI.Result.LastValue > 50)
{
// Open a buy order
ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeByRisk());
}
// Check if the conditions are met to open a sell order
else if (EMA50.Result.LastValue < EMA100.Result.LastValue && RSI.Result.LastValue < 50)
{
// Open a sell order
ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeByRisk());
}
}
private double VolumeByRisk()
{
private double stopLossPips = 50; // You can adjust this value
double volume = (RiskPerTrade * Account.Balance) / (stopLossPips * PipSize);
return volume;
}
}
}
javi.s.a.39
Joined on 28.11.2023
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: hiki khashix.algo
- Rating: 0
- Installs: 474
- Modified: 09/12/2023 09:14
theres no need for the PipSize property, simply use Symbol.PipSize that should do