Supertrend + EMA 200 + Stoch Robot ERRORS ???
Supertrend + EMA 200 + Stoch Robot ERRORS ???
04 Jan 2023, 14:52
In the below code I get 7 errors, please see the provided .JPG.
I currently use the free version of Visual Code 2022. cAutomate is added.
Also, when renaming the file to .algo - cTrader gives me "Invalid file format" and does not install the bot to cTrader?
Anyone sees what is wrong?
Thanks
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 AutoTrader : Robot
{
[Parameter("EMA Period", DefaultValue = 200)]
public int EMAPeriod { get; set; }
[Parameter("Stochastic Period", DefaultValue = 14)]
public int StochasticPeriod { get; set; }
[Parameter("Stochastic D Period", DefaultValue = 3)]
public int StochasticDPeriod { get; set; }
[Parameter("Stochastic K Period", DefaultValue = 3)]
public int StochasticKPeriod { get; set; }
[Parameter("Stochastic Overbought Level", DefaultValue = 80)]
public double StochasticOverboughtLevel { get; set; }
[Parameter("Stochastic Oversold Level", DefaultValue = 20)]
public double StochasticOversoldLevel { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 30)]
public int StopLoss { get; set; }
[Parameter("Take Profit (pips)", DefaultValue = 60)]
public int TakeProfit { get; set; }
private ExponentialMovingAverage ema;
private Supertrend supertrend;
private StochasticOscillator stochastic;
protected override void OnStart()
{
ema = Indicators.ExponentialMovingAverage(Bars.ClosePrices, EMAPeriod);
supertrend = Indicators.Supertrend(Bars.HighPrices, Bars.LowPrices, EMAPeriod, 2.0);
stochastic = Indicators.StochasticOscillator(Bars.HighPrices, Bars.LowPrices, Bars.ClosePrices, StochasticPeriod, StochasticKPeriod, StochasticDPeriod);
}
protected override void OnTick()
{
var position = Positions.Find(Symbol, PositionType.Any);
if (position == null)
{
// Check if we should open a long position
if (Bars.ClosePrices.LastValue > ema.Result.LastValue && supertrend.Trend.LastValue == 1 && stochastic.PercentD.LastValue < StochasticOversoldLevel)
{
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Long", StopLoss, TakeProfit);
}
// Check if we should open a short position
if (Bars.ClosePrices.LastValue < ema.Result.LastValue && supertrend.Trend.LastValue == -1 && stochastic.PercentD.LastValue > StochasticOverboughtLevel)
{
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Short", StopLoss, TakeProfit);
}
}
else
{
// Check if we should close the position
if ((position.TradeType == TradeType.Buy && Bars.ClosePrices.LastValue < ema.Result.LastValue) ||
(position.TradeType == TradeType.Sell && Bars.ClosePrices.LastValue > ema.Result.LastValue))
{
ClosePosition(position);
}
}
}
}
}
Replies
robban
04 Jan 2023, 15:54
RE:
PanagiotisChar said:
Hi robban,
The errors are self explanatory. Did you just copy and paste the code from somewhere?
Also, when renaming the file to .algo - cTrader gives me "Invalid file format" and does not install the bot to cTrader?
Which file do you rename? You can't just rename a file to .algo. These files are only compiled by cTrader.
Need help? Join us on Telegram
Need premium support? Trade with us
So VS cant built it?
What do you mean with copy in?
@robban
PanagiotisChar
04 Jan 2023, 15:59
Hi robban,
The VS will build it after you fix the errors. I am asking where did you find this code. Did you write it yourself? Because the errors are clear what the problem is. A programmer can easily fix them. It seems that you just copied source code from somewhere and you are trying to build it.
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar
robban
04 Jan 2023, 16:50
RE:
PanagiotisChar said:
Hi robban,
The VS will build it after you fix the errors. I am asking where did you find this code. Did you write it yourself? Because the errors are clear what the problem is. A programmer can easily fix them. It seems that you just copied source code from somewhere and you are trying to build it.
Thank you for you answer.
I have been reading on https://help.ctrader.com/ctrader-automate/creating-and-running-a-cbot/ and using openAI chatGPT to in different approaches yes.
Unfortunately I am better with medicine than programming as for now... This trading is a hobby, but I know what strategy I wanna run.
Again, thank you
@robban
PanagiotisChar
05 Jan 2023, 08:36
Hi robban,
chatGPT is too good to be true :) I tried it too, unfortunately the produced code is always buggy. If you don't know how to program, you should contact a professional instead.
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar
robban
05 Jan 2023, 09:48
RE:
PanagiotisChar said:
Hi robban,
chatGPT is too good to be true :) I tried it too, unfortunately the produced code is always buggy. If you don't know how to program, you should contact a professional instead.
I signed up for a course instead, maby that helps :)
If the error now is so simple, why not just tell what is wrong so Iatleats can look it up specifically?
Best regards, Robert
@robban
PanagiotisChar
05 Jan 2023, 10:57
Hi robban,
The error messages are very clear I think e.g. Supertrend does not take 4 arguments, Stochastic Oscillator does not take 6 arguments, Volume and PositionType do not exist, SuperTrend does not have a Trend member etc. It's just nonsense code.
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar
Xammo
10 Jan 2023, 13:41
Hi robban
PanagiotisChar is right (as always/top bloke!) ChatGPT is giving it a go but getting some things badly wrong that it is going to throw all those errors
I made this video yesterday (to try and keep my mind off the 4.1 connection issues!) to walk through how I would go about fixing the code - take note I am by far no professional developer/100% self taught and no doubt a lot of bad habits/ways about doing things but hopefully it gives you something to go on to develop your own style of working things out
Cheers
Max
PS - I later realised what the supertrend = 1 was probably meaning if the Up/DownTrend was áctive or not (it reports as NaN when not being caluclated in the indicator) so to trigger when it is not NaN I would suggest using !double.IsNaN(SuperTrend.UpTrend.LastValue)
@Xammo
PanagiotisChar
04 Jan 2023, 15:22
Hi robban,
The errors are self explanatory. Did you just copy and paste the code from somewhere?
Which file do you rename? You can't just rename a file to .algo. These files are only compiled by cTrader.
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar