RSI + EMA
RSI + EMA
12 Aug 2020, 04:50
I keep trying and not succeeding. Perhaps because of my limitations as a programmer, or because my strategy is unorthodox. So again people help from some kind soul. my strategy consists of a rsi that gives me the direction of the trend and the crossing of moving means that give me the moment of entry But in spite of my constant attempts, I am unable to efficiently encode a media crossover. Please, does anyone have any idea how to code a crossover of medias?
THANK YOU VERY MUCH
THANK YOU VERY MUCH
(More precisely, a fast medium that crosses a slow average upwards and that implies selling and a fast average that crosses a slow average to low and that implies buying that's right, exactly the contrition of what most strategies do) Below is the model of my attempts.
using System;
using System.Linq;
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 bot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("Periods", DefaultValue = 14)]
public int Periods { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 20, MinValue = 1)]
public int StopLoss { get; set; }
[Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
public int Volume { get; set; }
[Parameter("Take_Profit", DefaultValue = 45, MinValue = 10)]
public int TakeProfit { get; set; }
[Parameter("Begin Trading Hour", DefaultValue = 5.0)]
public double Begin { get; set; }
[Parameter("Ending Trading Hour", DefaultValue = 19.0)]
public double Ending { get; set; }
[Parameter("Trigger When Gaining", DefaultValue = 50)]
public double TriggerWhenGaining { get; set; }
[Parameter("Trailing Stop Loss Distance", DefaultValue = 1)]
public double TrailingStopLossDistance { get; set; }
[Parameter("Step (pips)", DefaultValue = 10)]
public double Step { get; set; }
[Parameter("Buy")]
public bool Buy { get; set; }
private double _highestGain;
private bool _isTrailing;
private DateTime startTime;
private DateTime endTime;
public RelativeStrengthIndex _rsi;
private ExponentialMovingAverage _SlowMa;
private ExponentialMovingAverage _fastMa;
private const string label = "Sample Trend cBot";
protected override void OnStart()
{
}
protected override void OnTick()
{
{
startTime = Server.Time.Date.AddHours(Begin);
endTime = Server.Time.Date.AddHours(Ending);
if (Trade.IsExecuting)
return;
bool tradeTime = false;
if (Begin < Ending)
tradeTime = Server.Time.Hour >= Begin && Server.Time.Hour < Ending;
if (Ending < Begin)
tradeTime = Server.Time.Hour >= Begin || Server.Time.Hour <= Ending;
if (!tradeTime)
return;
}
var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);
var currentSlowMa = slowMa.Result.Last(1);
var currentFastMa = fastMa.Result.Last(1);
var previousSlowMa = slowMa.Result.Last(2);
var previousFastMa = fastMa.Result.Last(2);
_rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 48);
_SlowMa = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 6);
_fastMa = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 1);
{
if (_rsi.Result.LastValue < 45)
if (currentSlowMa > currentFastMa && shortPosition == null && Positions.Count(x => x.TradeType == TradeType.Sell) == 0)
{
if (longPosition != null)
ClosePosition(longPosition);
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "bot", StopLoss, TakeProfit);
}
{
if (_rsi.Result.LastValue > 55)
if (currentSlowMa < currentFastMa && shortPosition == null && Positions.Count(x => x.TradeType == TradeType.Buy) == 0)
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "bot", StopLoss, TakeProfit);
genappsforex
21 Aug 2020, 12:19
Sorry to say so .(and probably I shouldn't)
"Better get yourself a programmer if I look at your Code."
@genappsforex