Error CS1503: Argument 1: cannot convert from 'double' to 'cAlgo.API.Bars'
Error CS1503: Argument 1: cannot convert from 'double' to 'cAlgo.API.Bars'
11 Jun 2023, 18:42
Hello!
I got an error, it says this:
Error CS1503: Argument 1: cannot convert from 'double' to 'cAlgo.API.Bars'
My code is the following:
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 Elsőbotom : Robot
{
[Parameter(DefaultValue = "Hello world!")]
public string Message { get; set; }
//Indikátorok:
private MacdCrossOver macd;
private ParabolicSAR psar;
protected override void OnStart()
{
//Debugging:
// System.Diagnostics.Debugger.Launch();
Print ("Kezdés");
//Indikátorok betöltése indításkor:
macd = Indicators.MacdCrossOver(26, 11, 7);
psar = Indicators.ParabolicSAR( 0.001, 0.007, -30);
}
protected override void OnBar()
{
//A MACD cross-oláshoz szükséges adatok betöltése:
var Histogram = macd.Histogram.Last(1);
var PrevHistogram = macd.Histogram.Last(2);
//A Parabolic SAR cross-oláshoz szükséges adatok betöltése:
var Érték = psar.Result.Last(1);
var ElÉrték = psar.Result.Last(2);
//Mikor nyisson pozíciót?
if (Érték>ElÉrték)
{
if (Histogram > 0 & PrevHistogram < 0)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, 1000, "MACDL");
}
}
if (Érték<ElÉrték)
{
if (Histogram < 0 & PrevHistogram > 0)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, 1000, "MACDS");
}
}
//Pozíciók zárása:
if (Histogram < 0 && PrevHistogram > 0)
{
var position = Positions.Find("MACDL");
if (position != null)
{
ClosePosition(position);
}
}
else if (Histogram > 0 && PrevHistogram < 0)
{
var position = Positions.Find("MACDS");
if (position != null)
{
ClosePosition(position);
}
}
}
protected override void OnStop()
{
Print ("Vége");
}
}
}
My goal: I want the bot to take a long trade when the Parabolic SAR indicator goes up and the MACD indicator crosses
I want the bot to take short when the Parabolic SAR indicator goes down and the MACD indicator crosses
It says that the problem is with this line:
psar = Indicators.ParabolicSAR( 0.001, 0.007, -30);
And the bot doesn't work now, it doesn't executes trades.
How can I fix it?
firemyst
12 Jun 2023, 16:13 ( Updated at: 21 Dec 2023, 09:23 )
Of course you're getting that error.
See what the API is expecting?
Not a double value, which you have as "0.001".
You need to pass it the "Bars" you want, or remove the first parameter entirely to use the current chart's bars.
@firemyst