In order to get assistance, you should share your cBot code first. Then explain how can somebody reproduce your problem
Sorry, here is the code, the positions are not opening according to the assumption that if the blue average, as in the screenshot, crosses the red one from top to bottom, it is short and every time the blue average 33 is below the red, and the price returns and touches the blue 33, it is short again. A SL crossing red 144
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators;
namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class MovingAverageCrossEA : Robot { [Parameter("WWS Period 33", DefaultValue = 33)] public int Period33 { get; set; }
[Parameter("WWS Period 144", DefaultValue = 144)] public int Period144 { get; set; }
[Parameter("Stop Loss Multiplier", DefaultValue = 2.0)] public double StopLossMultiplier { get; set; }
// Sprawdź, czy doszło do przecięcia średnich kroczących bool crossedAbove = wwsHigh33.Result.Last(1) > wwsLow33.Result.Last(1) && wwsHigh144.Result.Last(1) > wwsLow144.Result.Last(1); bool crossedBelow = wwsHigh33.Result.Last(1) < wwsLow33.Result.Last(1) && wwsHigh144.Result.Last(1) < wwsLow144.Result.Last(1);
if (crossedAbove) { // Otwórz pozycję short z dynamicznym stop loss ExecuteMarketOrder(TradeType.Sell, Symbol, 1, "Przecięcie WWS Short", 0, 0, stopLossLevel, "Opening short position on WWS crossover"); } else if (crossedBelow) { // Otwórz pozycję long z dynamicznym stop loss ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "Przecięcie WWS Long", 0, 0, stopLossLevel, "Opening long position on WWS crossover"); } } } }
creatorn906
27 Oct 2023, 17:03 ( Updated at: 21 Dec 2023, 09:23 )
RE: Seeking Assistance for Simple Moving Average Crossover Bot
PanagiotisChar said:
Sorry, here is the code, the positions are not opening according to the assumption that if the blue average, as in the screenshot, crosses the red one from top to bottom, it is short and every time the blue average 33 is below the red, and the price returns and touches the blue 33, it is short again. A SL crossing red 144
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MovingAverageCrossEA : Robot
{
[Parameter("WWS Period 33", DefaultValue = 33)]
public int Period33 { get; set; }
[Parameter("WWS Period 144", DefaultValue = 144)]
public int Period144 { get; set; }
[Parameter("Stop Loss Multiplier", DefaultValue = 2.0)]
public double StopLossMultiplier { get; set; }
private WeightedMovingAverage wwsHigh33;
private WeightedMovingAverage wwsLow33;
private WeightedMovingAverage wwsHigh144;
private WeightedMovingAverage wwsLow144;
private double stopLossLevel;
protected override void OnStart()
{
wwsHigh33 = Indicators.WeightedMovingAverage(MarketSeries.High, Period33);
wwsLow33 = Indicators.WeightedMovingAverage(MarketSeries.Low, Period33);
wwsHigh144 = Indicators.WeightedMovingAverage(MarketSeries.High, Period144);
wwsLow144 = Indicators.WeightedMovingAverage(MarketSeries.Low, Period144);
}
protected override void OnBar()
{
// Oblicz poziom dynamicznego stop lossa
stopLossLevel = Math.Max(wwsLow144.Result.Last(1), stopLossLevel);
// Sprawdź, czy doszło do przecięcia średnich kroczących
bool crossedAbove = wwsHigh33.Result.Last(1) > wwsLow33.Result.Last(1) && wwsHigh144.Result.Last(1) > wwsLow144.Result.Last(1);
bool crossedBelow = wwsHigh33.Result.Last(1) < wwsLow33.Result.Last(1) && wwsHigh144.Result.Last(1) < wwsLow144.Result.Last(1);
if (crossedAbove)
{
// Otwórz pozycję short z dynamicznym stop loss
ExecuteMarketOrder(TradeType.Sell, Symbol, 1, "Przecięcie WWS Short", 0, 0, stopLossLevel, "Opening short position on WWS crossover");
}
else if (crossedBelow)
{
// Otwórz pozycję long z dynamicznym stop loss
ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "Przecięcie WWS Long", 0, 0, stopLossLevel, "Opening long position on WWS crossover");
}
}
}
}
@creatorn906