Topics
Replies
marian.kosa
27 Jul 2021, 10:45
RE:
PanagiotisCharalampous said:
Hi Sam,
Your code will stop the cBot completely on the specific days. Try something like this instead
var day = Server.Time.DayOfWeek; if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday) { // Trade }
Best Regards,
Panagiotis
I was trying similar stuff, like this, but i am getting error "Error CS0103: The name 'DayOfWeek' does not exist in the current context". Did something changed since than?
@marian.kosa
marian.kosa
05 Mar 2021, 11:08
( Updated at: 21 Dec 2023, 09:22 )
RE:
Aha, I only saw this. That is why i was so confused. I did not know that i dont see everything by default in log...
Thanks for help and sorry for my ignorance :)
Regards,
Marian
PanagiotisCharalampous said:
Hi marian.kosa,
You can see the error message in the log, as shown above.
Best Regards,
Panagiotis
@marian.kosa
marian.kosa
05 Mar 2021, 09:13
RE: RE:
Ok. the volume needs to be at least 1000, not 100. I missunderstood tooltips there. Wonder why i did not get any error message during backtesting...
marian.kosa said:
I tried it on 2 random forex pairs (eurUsd, UsdJpy), I am backtesting it on my demo account, volume should not be a problem. In Log i see only those print() numbers. 313132313232 etc... nothing about orders.
PanagiotisCharalampous said:
Hi marian.kosa,
On which symbol do you run this? Is the volume appropriate? Do you get any messages in the log?
Best Regards,
Panagiotis
@marian.kosa
marian.kosa
05 Mar 2021, 08:52
RE:
I tried it on 2 random forex pairs (eurUsd, UsdJpy), I am backtesting it on my demo account, volume should not be a problem. In Log i see only those print() numbers. 313132313232 etc... nothing about orders.
PanagiotisCharalampous said:
Hi marian.kosa,
On which symbol do you run this? Is the volume appropriate? Do you get any messages in the log?
Best Regards,
Panagiotis
@marian.kosa
marian.kosa
04 Mar 2021, 18:27
RE:
Hope this helps.
using System.Linq;
using cAlgo.API;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
public class MACD : Robot
{
protected override void OnStart()
{
_MACD = Indicators.MacdCrossOver(26, 12, 9);
}
protected override void OnBar()
{
if (Positions.Count() == 0)
{
if (_MACD.MACD.IsRising())
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, 100);
Print("1");
}
else if (_MACD.MACD.IsFalling())
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, 100, "sell");
Print("2");
}
Print("3");
}
}
}
}
PanagiotisCharalampous said:
Hi marian.kosa,
To assist you further, please provide us with the complete cBot code and exact steps to reproduce this behavior.
Best Regards,
Panagiotis
@marian.kosa
marian.kosa
25 Feb 2021, 16:04
RE: RE:
Yes, You must remember that SL and TP are in pips. And bars are in actual price, and ATR is the change of price. To get pips from it you need to divide (or multiply?, i forgot) it by Symbol.PipSize or 10000.
At least that is what worked for me in SL and TP calculation.
jackhpfilerrowson said:
Also i there a way to set the SL as the High of the last bar and to determine the TP distance from the ATR?
@marian.kosa
marian.kosa
15 Feb 2021, 15:42
RE:
"pretty basic" is good estimate of my programming skills. :)
Thanks for respond. I was not sure where to look. I should be able figure it out now.
JerryTrader said:
I don't know your level of programming skills, but a pretty basic way of doing it without knowing anything about the cBot API would be to:
- Create a field or property in your class
- When you execute the market order, store the bar index in the field/property
- Add a condition to check if the current bar index is greater than your field/property + 3
I think the best way to perform what you are looking for is to override the OnTimer method to set a flag like CanExecuteMarketOrder and stop the timer.
As soon as you execute a market order, you reset the flag and start the timer with Timer.Start() with the timespan you wanna wait before setting the CanExecuteMarketOrder flag.
@marian.kosa
marian.kosa
12 Feb 2021, 11:35
RE:
I was trying to Last(), but i probably wrote it wrong.
Anyway i wrote it that way now "double FL = _fractalChaosBands.Low.Last(1);"
Aaand as i was writing my next question, i realized, that i was writing stoploss in price, not in pips....
Thanks, for your time, I should be able to continue from here.
PanagiotisCharalampous said:
Hi marian.kosa,
The index represents the index of the current bar being calculated and as you can see it is passed as a parameter to the Calculate method. So you can use it only inside this method. It is a local variable. If you want to access the values of the indicator inside the cBot, you should consider using Last() method.
Best Regards,
Panagiotis
@marian.kosa
marian.kosa
12 Feb 2021, 10:14
RE:
I want to extract price from that indicator to use it later as stoploss.
I am trying to figure out what that index represent, because with it, i am getting several errors, depending how i adjust the code.
For example "Error CS0115: 'cAlgo.bot.OnBar(int)': no suitable method found to override" or "Error CS0103: The name 'index' does not exist in the current context"
Current simplified code:
using System.Linq;
using cAlgo.API;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
public class bot: Robot
{
[Parameter("Volume", DefaultValue = 10000)]
public int volume { get; set; }
[Parameter(DefaultValue = 15, MinValue = 1)]
public int TakeProfit { get; set; }
public FractalChaosBands _fractalChaosBands;
protected override void OnBar()
{
_fractalChaosBands = Indicators.FractalChaosBands();
double FL = _fractalChaosBands.Low[index];
double FH = _fractalChaosBands.High[index];
if (***)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, volume, "BOT", FL, TakeProfit, "buy");
}
if (***)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, volume, "BOT", FH, TakeProfit, "sell");
}
}
}
}
@marian.kosa
marian.kosa
27 Jul 2021, 12:36
RE:
Thank you. That was the piece of information i was missing. I guess, i can delete other lines with "using System.xxxx;"
amusleh said:
@marian.kosa