Topics
Replies
admin
19 Nov 2012, 12:09
We will add the ability to access the timeframe from the cAlgo API soon.
For the time being you might be able to use a workaround method. Please see this sample code: /forum/calgo-reference-samples/163
@admin
admin
19 Nov 2012, 12:05
OBSOLETE
OBSOLETEUse Timeframe Instead
See: Multi-timeframe robots/indicators
// ------------------------------------------------------------------------------- // // This is a Template used as a guideline to build your own Robot. // Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API. // // ------------------------------------------------------------------------------- using System; using cAlgo.API; namespace cAlgo.Robots { [Robot] public class SampleTimeFrame : Robot { private TimeSpan _timeFrame; protected override void OnStart() { // Get the timeframe in timespan format _timeFrame = GetTimeFrame(); Print("{0}", _timeFrame); // convert the timeframe to it's name representation string timeFrameName = GetTimeFrameName(_timeFrame); if (timeFrameName == "0") Print("Not enough data."); else Print("{0}", timeFrameName); } /// <summary> /// Get the name representation of the timeframe used /// </summary> /// <param name="timeFrame">Time span between two consecutive bars OpenTime</param> /// <returns>The name representation of the TimeFrame</returns> private string GetTimeFrameName(TimeSpan timeFrame) { int totalMin = (int)timeFrame.TotalMinutes; string timeFrameName; if (totalMin > 10080) timeFrameName = "M1"; else { switch (totalMin) { case 1: timeFrameName = "m1"; break; case 2: timeFrameName = "m2"; break; case 3: timeFrameName = "m3"; break; case 4: timeFrameName = "m4"; break; case 5: timeFrameName = "m5"; break; case 10: timeFrameName = "m10"; break; case 15: timeFrameName = "m15"; break; case 30: timeFrameName = "m30"; break; case 60: timeFrameName = "h1"; break; case 240: timeFrameName = "h4"; break; case 720: timeFrameName = "h12"; break; case 1440: timeFrameName = "D1"; break; case 10080: timeFrameName = "W1"; break; default: timeFrameName = "0"; break; } } return timeFrameName; } /// <summary> /// Get the time span between two consecutive bars OpenTime /// </summary> private TimeSpan GetTimeFrame() { if (MarketSeries.Close.Count > 0) { int currentIndex = MarketSeries.Close.Count - 1; DateTime currentOpenTime = MarketSeries.OpenTime[currentIndex]; DateTime previousOpenTime = MarketSeries.OpenTime[currentIndex - 1]; TimeSpan timeFrame = currentOpenTime - previousOpenTime; if (currentOpenTime.DayOfWeek == DayOfWeek.Monday && previousOpenTime.DayOfWeek != DayOfWeek.Monday) { currentOpenTime = previousOpenTime; previousOpenTime = MarketSeries.OpenTime[currentIndex - 2]; timeFrame = currentOpenTime - previousOpenTime; } return timeFrame; } // if bars are not available return TimeSpan.Zero; } } }
@admin
admin
15 Nov 2012, 14:34
It is already on Spotware cAlgo where you can test it and it is due for release on all the other broker platforms very soon.
You can use MarketDepth and MarkeData interfaces to access Depth of Market for various symbols.
For instance:
private MarketDepth GBPUSD; private MarketDepth _md; protected override void Initialize() { _md = MarketData.GetMarketDepth("EURUSD"); GBPUSD = MarketData.GetMarketDepth(Symbol); GBPUSD.Updated += OnGbpUsdUpdated; } void OnGbpUsdUpdated() { // Implement this function according to what you want to do // when the Depth of Market gets updated }
@admin
admin
15 Nov 2012, 12:23
We tested a robot that references DirectionalMovementSystem Indicator, more specifically your code above and it does not crash. Please explain a bit more what exactly are the circumstances under which your robot crashes and what is exactly the code that you receive a technical error for.
using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Robots { [Robot] public class DMIRobot :Robot { private DirectionalMovementSystem _dms; [Parameter("Volume", DefaultValue = 10000)] public int Volume { get; set; } protected override void OnStart() { _dms = Indicators.DirectionalMovementSystem(14); } protected override void OnBar() { if(Trade.IsExecuting) return; int index = MarketSeries.Close.Count - 2; if (_dms.DIPlus[index] > _dms.DIMinus[index]) { Trade.CreateBuyMarketOrder(Symbol, Volume); } else if (_dms.DIPlus[index] < _dms.DIMinus[index]) { Trade.CreateSellMarketOrder(Symbol, Volume); } } } }
@admin
admin
20 Nov 2012, 11:27
The technical error is due to the take profit value in the CreateBuyStopOrder. It cannot be the same as the target price.
@admin