different time
different time
03 Oct 2014, 14:58
hello
Does it exist a solution to set various indicators (in the same robot) with different time.
for example;
Indicator 1 = 5mn
Indicator 2 = 1h
Indicator 3 = 4h
cordially
Replies
tradermatrix
04 Oct 2014, 13:05
RE:
Spotware said:
When you create an indicator you can pass DataSeries or MarketSeries object:
protected override void OnStart() { var m1_series = MarketData.GetSeries(TimeFrame.Minute); var sma_m1 = Indicators.SimpleMovingAverage(m1_series.Close, 14); var m5_series = MarketData.GetSeries(TimeFrame.Minute5); var aroon_m5 = Indicators.Aroon(m5_series, 21); }
hello
I Experienced the method on simple robots.
I always found the same error
example;
sample RSI cBot
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 SampleRSIcBot : Robot
{
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("Periods", DefaultValue = 14)]
public int Periods { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 10, MinValue = 1)]
public int StopLoss { get; set; }
[Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
public int Volume { get; set; }
private RelativeStrengthIndex rsi;
protected override void OnStart()
{
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
}
protected override void OnTick()
{
if (rsi.Result.LastValue < 30)
{
Close(TradeType.Sell);
Open(TradeType.Buy);
}
else if (rsi.Result.LastValue > 70)
{
Close(TradeType.Buy);
Open(TradeType.Sell);
}
}
private void Close(TradeType tradeType)
{
foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType))
ClosePosition(position);
}
private void Open(TradeType tradeType)
{
var position = Positions.Find("SampleRSI", Symbol, tradeType);
if (position == null)
ExecuteMarketOrder(tradeType, Symbol, Volume, "SampleRSI");
}
}
}
corrected robot;
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 SampleRSIcBot : Robot
{
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("Periods", DefaultValue = 14)]
public int Periods { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 10, MinValue = 1)]
public int StopLoss { get; set; }
[Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
public int Volume { get; set; }
private RelativeStrengthIndex rsi; //message d erreur : Error CS0649: Field 'cAlgo.SampleRSIcBot.rsi' is never assigned to, and will always have its default value null.
//04/09/2014 03:01:00.000 | Crashed in OnTick with NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
protected override void OnStart()
{
var m5_series = MarketData.GetSeries(TimeFrame.Minute5);
var rsi_m5 = Indicators.RelativeStrengthIndex(m5_series.Close, 14);
}
protected override void OnTick()
{
if (rsi.Result.LastValue < 30)
{
Close(TradeType.Sell);
Open(TradeType.Buy);
}
else if (rsi.Result.LastValue > 70)
{
Close(TradeType.Buy);
Open(TradeType.Sell);
}
}
private void Close(TradeType tradeType)
{
foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType))
ClosePosition(position);
}
private void Open(TradeType tradeType)
{
var position = Positions.Find("SampleRSI", Symbol, tradeType);
if (position == null)
ExecuteMarketOrder(tradeType, Symbol, Volume, "SampleRSI");
}
}
}
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
can you help me to correct the error.
in order to set various indicators (in the same robot) with different time.
cordially
@tradermatrix
Pannekoek
04 Oct 2014, 15:18
In your OnStart method, you create a new variable (rsi_m5) and assign the RSI indicator to it. Instead you should have used the "rsi" variable.
@Pannekoek
tradermatrix
04 Oct 2014, 16:03
RE:
Pannekoek said:
In your OnStart method, you create a new variable (rsi_m5) and assign the RSI indicator to it. Instead you should have used the "rsi" variable.
yes, thank you
the solution;
protected override void OnStart()
{
var _m5_series = MarketData.GetSeries(TimeFrame.Minute5);
rsi = Indicators.RelativeStrengthIndex(_m5_series.Close, 14);
}
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
several indicators;
protected override void OnStart()
{
var _m5_series = MarketData.GetSeries(TimeFrame.Minute5);
rsi = Indicators.RelativeStrengthIndex(_m5_series.Close, 14);
var m3_series = MarketData.GetSeries(TimeFrame.Minute3);
var sma_m3 = Indicators.SimpleMovingAverage(m3_series.Close, 54);
var m30_series = MarketData.GetSeries(TimeFrame.Minute30);
var aroon_m30 = Indicators.Aroon(m30_series, 21);
}
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
very advantageous method (with optimization)
++ Can choose a different period for the chart
cordialement
@tradermatrix
Spotware
03 Oct 2014, 17:35
When you create an indicator you can pass DataSeries or MarketSeries object:
@Spotware