Topics
Replies
irmscher9
07 Feb 2018, 12:41
Actually, this problem wouldn't exist if cAlgo would let us save the backtesting results.
@irmscher9
irmscher9
07 Feb 2018, 12:30
So I guess nothing can be done about this?
It's really annoying, my backtesting takes 1 hour, then I need to study my backtesting results so I leave my pc on sleep mode duting night to sart right of analysing the results in the morning. Only to discover Blue Screen of Death or black screen on return from sleep. Note, on my both laptop and desktop pc. Then I need to wait another hour for my backtesting to finish... It's a bit annoying, are you sure nothing can be done about it? at least try?
@irmscher9
irmscher9
30 Jan 2018, 16:10
( Updated at: 21 Dec 2023, 09:20 )
Oops, wait, the wrong one. Here's the right one:
@irmscher9
irmscher9
30 Jan 2018, 13:34
Hey, I have similar issue with USDCHF on 25DEC 2015 (screenshot):
https://1drv.ms/i/s!AvJJop5QTya740_K6VN79zfJw4Go
@irmscher9
irmscher9
23 Jan 2018, 20:08
Hey Panagiotis thanks for prompt reply :)
Do I delete the whole UK100 folder then?
@irmscher9
irmscher9
22 Jan 2018, 15:39
Yes, they said you should use MarketRange at your cAlgo. Should I contact them again? what should I say then? Are use sure this one is not a real slippage?
@irmscher9
irmscher9
22 Jan 2018, 14:57
Here is the bot. It's not about the bot actually. You will get the same problem with ANY bot when those fractures happen, usually after the weekends and holidays. I actually program my bots not to trade on Fridays after 20:00 pm and Mondays before 4:00 am and it's kinda a solution but this fracture above happened on 13th of April 2017 which is Thursday, then there are 2 bars which are dated by 16th which is Sunday and it's weird. Well, may be Bank holiday or something.
So the thing is, I can program my bot NOT to trade and close all existing trades on Firidays after 20.00pm, but how do I do with the rest which are not weekends? That's why I tought marketRangePips might help.
Here's the bot:
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 NewcBot : Robot { //--TODO: //-- 1. Chaikin Volotility, if above 500 - don't trade for X amount of time. [Parameter("Source")] public DataSeries SourceSeries { get; set; } [Parameter("Lot Size", DefaultValue = 1)] public double lot { get; set; } private MarketSeries m30; private RelativeStrengthIndex _rsi; private MacdHistogram _mcd; private CommodityChannelIndex _cci; private DonchianChannel _dnc; private BollingerBands _blb; private DirectionalMovementSystem _dms; private ExponentialMovingAverage _ema14; private ExponentialMovingAverage _ema21; private ExponentialMovingAverage _ema30; private ExponentialMovingAverage _ema100; private ExponentialMovingAverage _ema150; public double haOpen; public double haClose; public double candle; public double candle1; public double candle2; public double candle3; public double candle4; public double upShadow; public double upShadow1; public double upShadow2; public double upShadow3; public double upShadow4; public double downShadow; public double downShadow1; public double downShadow2; public double downShadow3; public double downShadow4; public double HeikenC; public double HeikenC2; public double haOpen_30m; public double candle_30m; public int buyPeriods; public int sellPeriods; public int fractal65; public int fractal35; public int buyMode; public int sellMode; public int noBuyMode; public int noSellMode; public bool BUYcond; public bool SELLcond; public double BUYprice; public double SELLprice; public double A; public double HeikenCinit; public long volume; protected override void OnStart() { Positions.Closed += OnPositionsClosed; m30 = MarketData.GetSeries(TimeFrame.Minute30); volume = Symbol.QuantityToVolume(lot); _rsi = Indicators.RelativeStrengthIndex(SourceSeries, 21); _mcd = Indicators.MacdHistogram(70, 35, 15); _cci = Indicators.CommodityChannelIndex(20); _dnc = Indicators.DonchianChannel(20); _blb = Indicators.BollingerBands(SourceSeries, 20, 2, MovingAverageType.Simple); _dms = Indicators.DirectionalMovementSystem(14); _ema14 = Indicators.ExponentialMovingAverage(SourceSeries, 14); _ema21 = Indicators.ExponentialMovingAverage(SourceSeries, 21); _ema30 = Indicators.ExponentialMovingAverage(SourceSeries, 30); _ema100 = Indicators.ExponentialMovingAverage(SourceSeries, 90); _ema150 = Indicators.ExponentialMovingAverage(SourceSeries, 170); haClose = 0; haOpen = 0; candle = 0; candle1 = 0; candle2 = 0; candle3 = 0; candle4 = 0; upShadow = 0; upShadow1 = 0; upShadow2 = 0; upShadow3 = 0; upShadow4 = 0; downShadow = 0; downShadow1 = 0; downShadow2 = 0; downShadow3 = 0; downShadow4 = 0; HeikenC = 0; HeikenC2 = 0; haOpen_30m = 0; candle_30m = 0; buyPeriods = 0; sellPeriods = 0; fractal65 = 0; fractal35 = 0; noBuyMode = 0; noSellMode = 0; BUYprice = 0; SELLprice = 0; BUYcond = false; SELLcond = false; } protected override void OnTick() { //-- var positionBUY1 = Positions.Find("Buy1"); var positionSELL1 = Positions.Find("Sell1"); //----- Fractals if (_rsi.Result.Last(2) <= 49 && _rsi.Result.Last(2) > 31 && MarketSeries.Low.Last(1) > MarketSeries.Low.Last(2) && MarketSeries.Low.Last(2) > MarketSeries.Low.Last(3) && MarketSeries.Low.Last(3) < MarketSeries.Low.Last(4) && MarketSeries.Low.Last(4) < MarketSeries.Low.Last(5)) { fractal35 = 25; } //-- _rsi.Result.Last(2) < 67 && if (_rsi.Result.Last(2) >= 51 && _rsi.Result.Last(2) < 69 && MarketSeries.High.Last(1) < MarketSeries.High.Last(2) && MarketSeries.High.Last(2) < MarketSeries.High.Last(3) && MarketSeries.High.Last(3) > MarketSeries.High.Last(4) && MarketSeries.High.Last(4) > MarketSeries.High.Last(5)) { fractal65 = 25; //Print("haClose = ", haClose); } //-- Cancelling fractal if (_rsi.Result.LastValue > 70) { fractal65 = 0; } if (_rsi.Result.LastValue < 30) { fractal35 = 0; } //-- noBuy noSell if (Server.Time.DayOfWeek == DayOfWeek.Friday && Server.Time.Hour == 21) { noBuyMode = 7; noSellMode = 7; } //-- current price double ask = Math.Round(Symbol.Ask, 5); double bid = Math.Round(Symbol.Bid, 5); double current_price = (ask + bid) / 2; //-- Coefficients and differences double rsiC = _rsi.Result.Last(0) - _rsi.Result.Last(1); //-- bools bool cci450_17 = _cci.Result.Maximum(17) >= 450; bool cciM450_17 = _cci.Result.Minimum(17) <= -450; bool cci300_5 = _cci.Result.Maximum(5) > 300; bool cciM300_5 = _cci.Result.Minimum(5) < -300; bool rsi25_30 = _rsi.Result.Minimum(30) <= 25; bool rsi75_30 = _rsi.Result.Maximum(30) >= 75; bool rsi30_10 = _rsi.Result.Minimum(10) < 30; bool rsi70_10 = _rsi.Result.Maximum(10) > 70; bool rsi33_5 = _rsi.Result.Minimum(10) < 30; bool rsi67_5 = _rsi.Result.Maximum(10) > 70; //-- double opn = MarketSeries.Open.LastValue; double cls = MarketSeries.Close.LastValue; //----- dmsC double dmsD0 = _dms.DIPlus.Last(0) - _dms.DIMinus.Last(0); double dmsD1 = _dms.DIPlus.Last(1) - _dms.DIMinus.Last(1); double dmsC = dmsD0 - dmsD1; //-- HeikenC2 = (candle + candle1 + candle2) / 30; if (current_price > _blb.Top.LastValue) { A = (current_price - _blb.Top.LastValue) * 1000; } if (current_price < _blb.Bottom.LastValue) { A = (current_price - _blb.Bottom.LastValue) * 1000; } double trend = (_ema21.Result.LastValue - _ema30.Result.LastValue) * 1000; if (_rsi.Result.LastValue < 39) { buyMode = 25; } if (_rsi.Result.LastValue > 60 && buyMode > 0) { buyMode = 0; } //-- && HeikenC > -17 if (buyMode > 0 && HeikenC > -5 && current_price < _dnc.Middle.LastValue && cciM300_5 == false && noBuyMode == 0 && positionBUY1 == null && positionSELL1 == null) { ExecuteMarketOrder(TradeType.Buy, Symbol, volume, "Buy1", 500, 750, 750); buyPeriods = 0; buyMode = 0; //Print("A = ", A); Print("HeikenCinit = ", HeikenCinit); Print("HeikenC = ", HeikenC); //Print("C1 = ", C1); //Print("C2 = ", C2); Print("________________"); } //-- && HeikenC < 17 if (_rsi.Result.LastValue > 70 && positionBUY1 == null && positionSELL1 == null) { //ExecuteMarketOrder(TradeType.Sell, Symbol, 1, "Sell1", 50, 75); //sellPeriods = 0; //Print("A = ", A); //Print("HeikenC = ", HeikenC); } //-- Closing positions if (positionBUY1 != null) { //--0 if (buyPeriods > 1 && (Server.Time.DayOfWeek == DayOfWeek.Friday || Server.Time.DayOfWeek == DayOfWeek.Saturday) && Server.Time.Hour >= 20) { //ClosePosition(positionBUY1); } //--1 if (buyPeriods > 20 && MarketSeries.High.Last(2) > _ema100.Result.LastValue && MarketSeries.High.Last(2) < _ema150.Result.LastValue && MarketSeries.High.Last(0) < MarketSeries.High.Last(1) && MarketSeries.High.Last(1) < MarketSeries.High.Last(2) && MarketSeries.High.Last(2) > MarketSeries.High.Last(3) && MarketSeries.High.Last(3) > MarketSeries.High.Last(4)) { //ClosePosition(positionBUY1); //Print("fractal BUY1 close"); } //--2 if (buyPeriods > 10 && positionBUY1.Pips > 30 && _cci.Result.HasCrossedBelow(330, 0)) { //ClosePosition(positionBUY1); //Print("cci330 BUY1 close"); } } if (positionSELL1 != null && rsiC < 7) { //--0 if (sellPeriods > 20 && positionSELL1.Pips >= 20 && _cci.Result.HasCrossedAbove(-150, 0)) { //ClosePosition(positionSELL1); } //--1 if (sellPeriods > 20 && MarketSeries.Low.Last(2) < _ema100.Result.LastValue && MarketSeries.Low.Last(2) > _ema150.Result.LastValue && MarketSeries.Low.Last(0) > MarketSeries.Low.Last(1) && MarketSeries.Low.Last(1) > MarketSeries.Low.Last(2) && MarketSeries.Low.Last(2) < MarketSeries.Low.Last(3) && MarketSeries.Low.Last(3) < MarketSeries.Low.Last(4)) { //ClosePosition(positionSELL1); //Print("fractal SELL1 close"); } //--2 if (sellPeriods > 10 && positionSELL1.Pips > 30 && _cci.Result.HasCrossedAbove(-330, 0)) { //ClosePosition(positionSELL1); //Print("cci330 BSELL1 close"); } } } protected override void OnBar() { //-- positions //-- find positions var positionBUY1 = Positions.Find("Buy1"); var positionSELL1 = Positions.Find("Sell1"); var positionBUY1a = Positions.Find("Buy1a"); var positionSELL1a = Positions.Find("Sell1a"); var positionBUY2 = Positions.Find("Buy2"); var positionSELL2 = Positions.Find("Sell2"); //-- buy && sell periods if (positionBUY1 != null) { buyPeriods++; } if (positionSELL1 != null) { sellPeriods++; } //-- Countdowners if (fractal35 > 0) { fractal35--; } if (fractal65 > 0) { fractal65--; } //-- BuyMode if (buyMode > 0) { buyMode--; } if (sellMode > 0) { sellMode--; } //-- NoBuyMode if (noBuyMode > 0) { noBuyMode--; } if (noSellMode > 0) { noSellMode--; } //-- HeikenC & HeikenAshi if (candle1 != candle) { if (candle1 != 0) { candle4 = candle3; candle3 = candle2; candle2 = candle1; candle1 = candle; } else { candle1 = candle; } } if (upShadow1 != upShadow) { if (upShadow1 != 0) { upShadow4 = upShadow3; upShadow3 = upShadow2; upShadow2 = upShadow1; upShadow1 = upShadow; } else { upShadow1 = upShadow; } } if (downShadow1 != downShadow) { if (downShadow != 0) { downShadow4 = downShadow3; downShadow3 = downShadow2; downShadow2 = downShadow1; downShadow1 = downShadow; } else { downShadow1 = downShadow; } } //-- Heiken Ashi 30m double open2_30m = m30.Open.Last(2); double high2_30m = m30.High.Last(2); double low2_30m = m30.Low.Last(2); double close2_30m = m30.Close.Last(2); double open1_30m = m30.Open.Last(1); double high1_30m = m30.High.Last(1); double low1_30m = m30.Low.Last(1); double close1_30m = m30.Close.Last(1); double haClose1_30m = (open2_30m + high2_30m + low2_30m + close2_30m) / 4; double haClose_30m = (open1_30m + high1_30m + low1_30m + close1_30m) / 4; if (haOpen_30m > 0) haOpen_30m = (haOpen_30m + haClose1_30m) / 2; else haOpen_30m = (open1_30m + close1_30m) / 2; candle_30m = (haOpen_30m - haClose_30m) * -100; //-- Heiken Ashi local double open2 = MarketSeries.Open.Last(2); double high2 = MarketSeries.High.Last(2); double low2 = MarketSeries.Low.Last(2); double close2 = MarketSeries.Close.Last(2); double open1 = MarketSeries.Open.Last(1); double high1 = MarketSeries.High.Last(1); double low1 = MarketSeries.Low.Last(1); double close1 = MarketSeries.Close.Last(1); double haClose1 = (open2 + high2 + low2 + close2) / 4; haClose = (open1 + high1 + low1 + close1) / 4; if (haOpen > 0) { haOpen = (haOpen + haClose1) / 2; //haOpen1 = (haOpen1 + haClose2) / 2; } if (haOpen == 0) { haOpen = (open1 + close1) / 2; //haOpen1 = (open2 + close2) / 2; } double haHigh = Math.Max(Math.Max(high1, haOpen), haClose); double haLow = Math.Min(Math.Min(low1, haOpen), haClose); if (candle >= 0) { upShadow = (haHigh - haClose) * 10000; downShadow = (haOpen - haLow) * -10000; } if (candle < 0) { upShadow = (haHigh - haOpen) * 10000; downShadow = (haClose - haLow) * -10000; } //candle0 = (haOpen0 - haClose1) * -10000; candle = (haOpen - haClose) * -10000; //-- New HeikenC 20 and -20 critical values if (candle4 != 0) { double zero = candle + upShadow + downShadow; double one = candle1 + upShadow1 + downShadow1; double two = candle2 + upShadow2 + downShadow2; double three = candle3 + upShadow3 + downShadow3; double four = candle4 + upShadow4 + downShadow4; double multiplier = (four + three) / (two + one + zero); double C1 = MarketSeries.Close.Last(1) - MarketSeries.Open.Last(1); double C2 = MarketSeries.Close.Last(2) - MarketSeries.Open.Last(2); HeikenCinit = (zero + one + two + three + four) / 50000; HeikenC = ((zero + one + two + three + four) / 50000) + C1 * 1.25 + C2 * 0.75; //Print("HeikenCinit = ", HeikenCinit); //Print("HeikenC = ", HeikenC); //Print("C1 = ", C1); //Print("C2 = ", C2); //Print("________________"); //HeikenC = ((candle + upShadow + downShadow) + (candle1 + upShadow1 + downShadow1) + (candle2 + upShadow2 + downShadow2) + (candle3 + upShadow3 + downShadow3) + (candle4 + upShadow4 + downShadow4)) / 5000; //HeikenC = ((candle + upShadow + downShadow) + (candle1 + upShadow1 + downShadow1) + (candle2 + upShadow2 + downShadow2)) / 30000; } //Print("candle = ", candle); //Print("candle1 = ", candle1); //Print("candle2 = ", candle2); //Print("candle3 = ", candle3); //Print("candle4 = ", candle4); //Print("________________"); //Print("HeikenC = ", HeikenC); } private void OnPositionsClosed(PositionClosedEventArgs args) { var position = args.Position; if (position.Label == "Buy1") { noBuyMode = 5; Print("noBuyMode = ", noBuyMode); } if (position.Label == "Sell1") { } } protected override void OnStop() { // Put your deinitialization logic here } } }
I'm testing it on TickMode between 28/03/2016 and present day.
Thanks :)
@irmscher9
irmscher9
22 Jan 2018, 12:53
( Updated at: 21 Dec 2023, 09:20 )
Ok.
I was actually looking for solution to this:
As you can see there's a fracture (if I said it correctly) all of a sudden and thus ignoring my Stop Loss and drawing down my whole account. So I thought Market Range would help to avoid these.
@irmscher9
irmscher9
20 Jan 2018, 15:03
Yeah,
[Parameter("Lot Size", DefaultValue = 1)]
public double lot { get; set; }
long volume = Symbol.QuantityToVolume(lot);
ExecuteMarketOrder(TradeType.Buy, Symbol, volume, "Buy1", 50, 75);
Works just fine
@irmscher9
irmscher9
11 Jan 2018, 13:40
Hey Panagiotis,
Yes, it works better. Thanks.
Could you please explain what these things:
[h2.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index])]
Thanks a lot!
@irmscher9
irmscher9
10 Jan 2018, 21:21
Ok, when I'm using
double open = MarketSeries.Open[index - 1]; double close = MarketSeries.Close[index - 1];
It works just fine.
Does that mean it's NOT possible to use a different timeframe data in indicators?
@irmscher9
irmscher9
07 Jan 2018, 16:59
Yes, but Windows crashes only when I leave cAlgo software open when going to sleep. Otherwise no problems.
@irmscher9
irmscher9
21 Dec 2017, 11:11
( Updated at: 21 Dec 2023, 09:20 )
On my desktop PC I'm getting Blue screen of death every time I send computer to sleep with the opened cAlgo software:
@irmscher9
irmscher9
11 Dec 2017, 17:17
Backtesting on Accurate mode is very slow. It takes AGES to fine-tune my bots. I've been working on my bots for almost a year now and still didn;t launch any of them to a full-scale extent. It's a bit disapointing to be honest. Most of the time is wasted waiting for backtesting to finish.
@irmscher9
irmscher9
27 Nov 2017, 19:01
Ok, I maanged to put it together myself through "onbar":
protected override void OnBar() { var open2 = MarketSeries.Open.Last(2); var high2 = MarketSeries.High.Last(2); var low2 = MarketSeries.Low.Last(2); var close2 = MarketSeries.Close.Last(2); var open1 = MarketSeries.Open.Last(1); var high1 = MarketSeries.High.Last(1); var low1 = MarketSeries.Low.Last(1); var close1 = MarketSeries.Close.Last(1); haClose1 = (open2 + high2 + low2 + close2) / 4; haClose = (open1 + high1 + low1 + close1) / 4; if (haOpen > 0) { haOpen = (haOpen + haClose1) / 2; } if (haOpen == 0) { haOpen = (open1 + close1) / 2; } haHigh = Math.Max(Math.Max(high1, haOpen), haClose); haLow = Math.Min(Math.Min(low1, haOpen), haClose); }
@irmscher9
irmscher9
10 Feb 2018, 15:28
How do I create Directional Movement System instance of a different timeframe?
private MarketSeries m5;
@irmscher9