New to cAlgo, could someone spot my errors?
New to cAlgo, could someone spot my errors?
25 Apr 2020, 21:34
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.RegressionRobot
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class RegressionRobot : Robot
{
[Parameter("Period", DefaultValue = 100)]
public int Period { get; set; }
[Parameter("SL", DefaultValue = 1)]
public double SL { get; set; }
[Parameter("TP", DefaultValue = 1)]
public double TP { get; set; }
[Parameter("Buy Limit", DefaultValue = 0)]
public double BuyLimit { get; set; }
[Parameter("Sell Limit", DefaultValue = 0)]
public double SellLimit { get; set; }
[Parameter("Lotsize", DefaultValue = 1000, MinValue = 0)]
public int Lotsize { get; set; }
private const string label = "Regression Bot";
private LinearRegressionRSquared rSquared;
private LinearRegressionIntercept intercept;
private StandardDeviation stdev;
private double buyLimit = 0;
private double sellLimit = 0;
private int volume = 1000;
protected override void OnStart()
{
}
protected override void OnTick()
{
if (Positions != null)
{
if (Position.TradeType = TradeType.Buy)
{
double distance = Symbol.Bid - Position.EntryPrice;
if (distance < 0)
{
double newStopLossPrice = Symbol.Bid - Symbol.PipSize;
if (Position.StopLoss == null || newStopLossPrice > Position.StopLoss)
{
ModifyPosition(Position, newStopLossPrice, Position.TakeProfit);
}
}
}
if (Position.TradeType = TradeType.Sell)
{
double distance = Position.EntryPrice - Symbol.Ask;
if (distance < 0)
{
double newStopLossPrice = Symbol.Ask + 1 * Symbol.PipSize;
if (position.StopLoss == null || newStopLossPrice < position.StopLoss)
{
ModifyPosition(Position, newStopLossPrice, Position.TakeProfit);
}
}
}
}
else if (Positions = null)
{
if (LinearRegressionRSquared.LastVaue >= buyLimit)
{
if (Bar.Close.LastValue <= intercept.LastValue - stdev.LastValue * TP)
{
Robot.ExecuteMarketOrder(TradeType.Buy, Bars.SymbolName, volume);
return;
}
}
else if (LinearRegressionRSquared.LastValue <= sellLimit)
{
if (Bar.Close.LastValue >= intercept.LastValue + stdev.LastValue * TP)
{
Robot.ExecuteMarketOrder(TradeType.Sell, Bars.SymbolName, volume);
return;
}
}
else
return;
}
}
protected override void OnStop()
{
}
}
}
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Position.TradeType.get'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Position.EntryPrice.get'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Position.StopLoss.get'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Position.StopLoss.get'
Error CS0118: 'cAlgo.API.Position' is a 'type' but is used like a 'variable'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Position.TakeProfit.get'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Position.TradeType.get'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Position.EntryPrice.get'
Error CS0103: The name 'position' does not exist in the current context
Error CS0103: The name 'position' does not exist in the current context
Error CS0118: 'cAlgo.API.Position' is a 'type' but is used like a 'variable'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Position.TakeProfit.get'
Error CS0200: Property or indexer 'cAlgo.API.Internals.Algo.Positions' cannot be assigned to -- it is read only
Error CS0029: Cannot implicitly convert type 'cAlgo.API.Positions' to 'bool'
Error CS0117: 'cAlgo.API.Indicators.LinearRegressionRSquared' does not contain a definition for 'LastVaue'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Bar.Close.get'
Error CS1061: 'cAlgo.API.Indicators.LinearRegressionIntercept' does not contain a definition for 'LastValue' and no extension method 'LastValue' accepting a first argument of type 'cAlgo.API.Indicators.LinearRegressionIntercept' could be found (are you missing a using directive or an assembly reference?)
Error CS1061: 'cAlgo.API.Indicators.StandardDeviation' does not contain a definition for 'LastValue' and no extension method 'LastValue' accepting a first argument of type 'cAlgo.API.Indicators.StandardDeviation' could be found (are you missing a using directive or an assembly reference?)
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Robot.ExecuteMarketOrder(cAlgo.API.TradeType, string, double)'
Error CS0117: 'cAlgo.API.Indicators.LinearRegressionRSquared' does not contain a definition for 'LastValue'
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Bar.Close.get'
Error CS1061: 'cAlgo.API.Indicators.LinearRegressionIntercept' does not contain a definition for 'LastValue' and no extension method 'LastValue' accepting a first argument of type 'cAlgo.API.Indicators.LinearRegressionIntercept' could be found (are you missing a using directive or an assembly reference?)
Error CS1061: 'cAlgo.API.Indicators.StandardDeviation' does not contain a definition for 'LastValue' and no extension method 'LastValue' accepting a first argument of type 'cAlgo.API.Indicators.StandardDeviation' could be found (are you missing a using directive or an assembly reference?)
Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.Robot.ExecuteMarketOrder(cAlgo.API.TradeType, string, double)'
Thank you very much.
PanagiotisCharalampous
27 Apr 2020, 09:17
Hi maxhemmerich3,
There are a lot basic programming errors in your code. You probably just copied and pasted code and you expect it work. If you don't know how to program, you can ask somebody to help you by posting a Job or contacting a Consultant.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous