Topics
Replies
martin100181@gmail.com
11 Jul 2019, 18:10
RE:
Panagiotis Charalampous said:
Hi martin100181@gmail.com,
Why do you set -1 in Last() function? e.g. below
slowMa.Result.Last(-1)Best regards,
Panagiotis
That was a Mistake! thank you.
@martin100181@gmail.com
martin100181@gmail.com
11 Jul 2019, 17:19
( Updated at: 21 Dec 2023, 09:21 )
Also I discovered I´m getting wrong EMAs values. They don´t match the ones on chart. help please!!
@martin100181@gmail.com
martin100181@gmail.com
11 Jul 2019, 16:56
Maybe my code is not so good because I´m not a coder. The Idea is to make the bot trade when price make a retracement inside both EMAs and get out of them. Long or Short will depend on EMAs direction.
The way I find to make this was assigning a status code for the different stages of the cicle. Maybe there´s a much better way, of course.
@martin100181@gmail.com
martin100181@gmail.com
11 Jul 2019, 15:43
RE:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class FrankiRangetraderv1 : Robot { [Parameter("Source")] public DataSeries SourceSeries { get; set; } [Parameter("Slow Periods", DefaultValue = 50)] public int SlowPeriods { get; set; } [Parameter("Fast Periods", DefaultValue = 14)] public int FastPeriods { get; set; } [Parameter("Volumen", DefaultValue = 10000)] public double volumen { get; set; } [Parameter("TP", DefaultValue = 6)] public double SL { get; set; } [Parameter("SL", DefaultValue = 6)] public double TP { get; set; } public int status; private ExponentialMovingAverage slowMa; private ExponentialMovingAverage fastMa; protected override void OnStart() { fastMa = Indicators.ExponentialMovingAverage(SourceSeries, FastPeriods); slowMa = Indicators.ExponentialMovingAverage(SourceSeries, SlowPeriods); status = 0; } protected override void OnBar() { int index = MarketSeries.Close.Count; Print("------------------ New Bar ------------------"); Print("Close: " + MarketSeries.Close.Last(1)); Print("Fast MA: " + fastMa.Result.Last(1)); Print("Slow MA: " + slowMa.Result.Last(1)); if (slowMa.Result.Last(1) < fastMa.Result.Last(1)) { Print("Configuracion de Compra"); switch (status) { case 0: Print("Entro en case 0 de compra"); if (MarketSeries.Close.Last(1) > fastMa.Result.Last(1)) status = 0; if (MarketSeries.Close.Last(1) < fastMa.Result.Last(1) && MarketSeries.Close.Last(1) > slowMa.Result.Last(1)) status = 1; if (MarketSeries.Close.Last(1) < slowMa.Result.Last(1)) status = -1; break; case 1: Print("Entro en case 1 de compra"); if (MarketSeries.Close.Last(1) > fastMa.Result.Last(1)) status = 2; if (MarketSeries.Close.Last(1) < fastMa.Result.Last(1) && MarketSeries.Close.Last(1) > slowMa.Result.Last(1)) status = 1; if (MarketSeries.Close.Last(1) < slowMa.Result.Last(1)) status = -1; break; case 2: Print("Entro en case 2 de compra"); if (MarketSeries.Close.Last(1) > fastMa.Result.Last(1)) status = 0; if (MarketSeries.Close.Last(1) < fastMa.Result.Last(1) && MarketSeries.Close.Last(1) > slowMa.Result.Last(1)) status = 1; if (MarketSeries.Close.Last(1) < slowMa.Result.Last(1)) status = -1; break; case -1: Print("Entro en case -1 de compra"); if (MarketSeries.Close.Last(1) > fastMa.Result.Last(1)) status = 0; if (MarketSeries.Close.Last(1) < fastMa.Result.Last(1) && MarketSeries.Close.Last(1) > slowMa.Result.Last(1)) status = -1; if (MarketSeries.Close.Last(1) < slowMa.Result.Last(1)) status = -1; break; } Print("Status: " + status); int Open_trades = Positions.Count(p => p.SymbolName == Symbol.Name); int Open_orders = PendingOrders.Count(p => p.SymbolCode == Symbol.Name); if (Open_trades == 0 && Open_orders == 0 && status == 2) { ExecuteMarketOrder(TradeType.Buy, Symbol, volumen, "Compra", SL, TP); Print("Abre Compra"); } { } } if (slowMa.Result.Last(1) > fastMa.Result.Last(1)) { Print("Configuración de Venta"); switch (status) { case 0: Print("Entro en case 0 de venta"); if (MarketSeries.Close.Last(1) > slowMa.Result.Last(-1)) status = -1; if (MarketSeries.Close.Last(1) <= slowMa.Result.Last(-1) && MarketSeries.Close.Last(1) >= fastMa.Result.Last(-1)) status = 1; if (MarketSeries.Close.Last(1) < fastMa.Result.Last(-1)) status = 0; break; case 1: Print("Entro en case 1 de venta"); if (MarketSeries.Close.Last(1) > slowMa.Result.Last(-1)) status = -1; if (MarketSeries.Close.Last(1) < slowMa.Result.Last(-1) && MarketSeries.Close.Last(1) > fastMa.Result.Last(-1)) status = 1; if (MarketSeries.Close.Last(1) < fastMa.Result.Last(-1)) status = 2; break; case 2: Print("Entro en case 2 de venta"); if (MarketSeries.Close.Last(1) > slowMa.Result.Last(-1)) status = -1; if (MarketSeries.Close.Last(1) < slowMa.Result.Last(-1) && MarketSeries.Close.Last(1) > fastMa.Result.Last(-1)) status = 1; if (MarketSeries.Close.Last(1) < fastMa.Result.Last(-1)) status = 0; break; case -1: Print("Entro en case -1 de venta"); if (MarketSeries.Close.Last(1) > slowMa.Result.Last(-1)) status = -1; if (MarketSeries.Close.Last(1) < slowMa.Result.Last(-1) && MarketSeries.Close.Last(1) > fastMa.Result.Last(-1)) status = -1; if (MarketSeries.Close.Last(1) < fastMa.Result.Last(-1)) status = 0; break; } Print("Status: " + status); int Open_trades = Positions.Count(p => p.SymbolName == Symbol.Name); int Open_orders = PendingOrders.Count(p => p.SymbolCode == Symbol.Name); if (Open_trades == 0 && Open_orders == 0 && status == 2) { ExecuteMarketOrder(TradeType.Sell, Symbol, volumen, "Venta", SL, TP); Print("Status: " + status); Print("Abre Venta"); } } Print("---------------------------------------------"); } } }
Panagiotis Charalampous said:
Hi martin100181@gmail.com,
Can you post the complete cBot code?
Best Regards,
Panagiotis
@martin100181@gmail.com
martin100181@gmail.com
25 Jun 2019, 23:32
Thank you Panagiotis.
Could you please take a look a this simple code? can´t find the error:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Range_Franki_v1 : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Parameter("Renko Pips", DefaultValue = 10)] public double RenkoPips { get; set; } public int BricksToShow = 100; private Renko renko; protected override void OnStart() { { Print("ON-ST-(renko O;C) [", i, "]: ", MarketSeries.Open.Last(i), ";", MarketSeries.Close.Last(i)); } } protected override void OnTick() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
@martin100181@gmail.com
martin100181@gmail.com
25 Jun 2019, 05:44
Also, when trying to use the indicator I get this error:
Error CS0246: The type or namespace name 'Renko' could not be found (are you missing a using directive or an assembly reference?)
How can I solve it?
@martin100181@gmail.com
martin100181@gmail.com
25 Jun 2019, 05:04
Dear Panagiotis,
is there any way to backtest with range bars or renko?
With built in range and renko I cant, is it possible somehow with an indicator?
BR
Martin
@martin100181@gmail.com
martin100181@gmail.com
10 Jun 2019, 23:48
More:
In fact I need the following:
1. I create a pending order with a defined target price and a label. Lets say "Long_1".
2. Sometime after that, it is possible that the bot stoped or whatever, so on the start I need the bot to check if Long_1 exists as a Pending order or if it was executed and its now a position and get the entry pice value (or target price if it´s still a pending order).
3. As a result I need to have that price stores in a variable.
I hope I could explain myself.
Thank you!
@martin100181@gmail.com
martin100181@gmail.com
11 Jul 2019, 18:12
RE:
Panagiotis Charalampous said:
I use default parameters.
GER30, Range bars 3 pips.
Slow EMA 50
Fast EMA 10
6 pips SL
6 pips TP
@martin100181@gmail.com