Mixing Matingale with RSI indicator
Mixing Matingale with RSI indicator
08 Jan 2023, 18:42
Hi, I am a beginer to C#, i am trying to make blend RSI bot from sample with Matingale and it has an Error:
Error CS0161: "MartinGaleRSI.OpenPosition()': Not a code path return a value (C:\User\ADMIN\Document\cAlgo\Sources\Robots\MartinGale + RSMartinGale + RSMartinGale + RSI.cs, line 84, column: 27)
how do i fix it? I would be very appriciate to everyone's help.
Here is my bot:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MartinGaleRSI : Robot
{
[Parameter("Initial Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.001, Step = 0.01)]
public double InitialQuantity { get; set; }
[Parameter("Stop Loss", Group = "Protection", DefaultValue = 40)]
public int StopLoss { get; set; }
[Parameter("Take Profit", Group = "Protection", DefaultValue = 40)]
public int TakeProfit { get; set; }
[Parameter("Source", Group = "RSI")]
public DataSeries Source { get; set; }
[Parameter("Periods", Group = "RSI", DefaultValue = 14)]
public int Periods { get; set; }
private RelativeStrengthIndex rsi;
protected override void OnStart()
{
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
Positions.Closed += OnPositionsClosed;
ExecuteOrder(InitialQuantity, OpenPosition());
}
private void ExecuteOrder(double quantity, TradeType tradeType)
{
var volumeInUnits = Symbol.QuantityToVolumeInUnits(quantity);
var result = ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI", StopLoss, TakeProfit);
if (result.Error == ErrorCode.NoMoney)
Stop();
}
private void OnPositionsClosed(PositionClosedEventArgs args)
{
Print("Closed");
var position = args.Position;
if (position.Label != "SampleRSI" || position.SymbolName != SymbolName)
return;
if (position.GrossProfit >= 0)
{
ExecuteOrder(InitialQuantity, OpenPosition());
}
else
{
ExecuteOrder(position.Quantity * 2, position.TradeType);
}
}
private TradeType OpenPosition()
{
if (rsi.Result.LastValue < 25)
{
OnpositionOpen(TradeType.Sell);
}
else if (rsi.Result.LastValue > 75)
{
OnpositionOpen(TradeType.Buy);
}
}
private void OnpositionOpen(TradeType tradeType)
{
var volumeInUnits = Symbol.QuantityToVolumeInUnits(InitialQuantity);
var Valueposition = Positions.Find("SampleRSI", SymbolName, tradeType);
if (Valueposition == null)
ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleRSI", StopLoss, TakeProfit);
}
}
}
Replies
Chanvodibo
09 Jan 2023, 13:46
( Updated at: 09 Jan 2023, 13:48 )
RE:
PanagiotisChar said:
Hi there,
The code is nonsensical. Did you copy and paste from somewhere? Or did you use ChatGPT :) ?
Need help? Join us on Telegram
Need premium support? Trade with us
Thanks for your attention.You're completely right, I just copy and try to find out how it's works
@Chanvodibo
PanagiotisChar
09 Jan 2023, 10:25
Hi there,
The code is nonsensical. Did you copy and paste from somewhere? Or did you use ChatGPT :) ?
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar