Topics
Replies
alexander.n.fedorov
14 May 2018, 09:03
Dear Panagiotiis:
This is the piece of code:
protected override void OnStart()
{
Instance = defaultInstance + ", " + Symbol.Code + ", " + Account.BrokerName + ", " + Account.Number.ToString();
BB = Indicators.BollingerBands(Source, periods, deviations, MovingAverageType.Simple);
atr = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
ma = Indicators.MovingAverage(Source, maPeriods, MovingAverageType.Simple);
equity = Account.Equity;
minQuantity = 0.01;
Quantity = minQuantity * Math.Floor(Risk);
volume = Symbol.QuantityToVolumeInUnits(Quantity);
Print("Quantity = {0}, math.floor(Risk)= {1}, volume = {2}", minQuantity, Math.Floor(Risk), volume);
Print("close last bar on start {0} ", MarketSeries.Close.LastValue);
Print("open last bar on start {0} ", MarketSeries.Open.LastValue);
}
protected override void OnBar()
{
tradeManagement();
var position = Positions.Find(Instance);
if (position != null)
{
if (position.TradeType == TradeType.Buy)
{
if (BB.Main.IsFalling())
ClosePosition(position);
}
if (position.TradeType == TradeType.Sell)
{
if (BB.Main.IsRising())
ClosePosition(position);
}
}
if (position == null)
{
Print("Close = {0}, Open = {1}", MarketSeries.Close.Last(0), MarketSeries.Open.Last(0));
Print("close last bar {0} ", MarketSeries.Close.LastValue);
Print("open last bar {0} ", MarketSeries.Open.LastValue);
and this is the backtesting printout:
16/04/2018 00:01:00.000 Backtesting started
16/04/2018 00:01:00.000 Quantity = 0.01, math.floor(Risk)= 1, volume = 1000
16/04/2018 00:01:00.000 close last bar on start 1.23292
16/04/2018 00:01:00.000 open last bar on start 1.23307
16/04/2018 01:00:00.000 Quantity = 0.02, volume = 2000, equity = 3000
16/04/2018 01:00:00.000 Close = 1.2329, Open = 1.2329
16/04/2018 01:00:00.000 close last bar 1.2329
16/04/2018 01:00:00.000 open last bar 1.2329
My question is why OnStart ()
MarketSeries.Open.Last(0)
and
MarketSeries.close.Last(0)
show different values, but OnBar() - the same?
@alexander.n.fedorov
alexander.n.fedorov
13 May 2018, 12:37
another question is:
I tried to print and what I recevied that
MarketSeries.Close.LastValue=MarketSeries.Open.LastValue.
That is really strange. How then would I know if the last bar is boolish or bearish?
@alexander.n.fedorov
alexander.n.fedorov
07 Apr 2018, 14:49
Volume with different brokers
there is another thing:
this is the piece of code:
"
...
protected override void OnStart()
{
Print("Broker name =: {0}, SymbolCode =: {1}, MinVolume =: {2},", Account.BrokerName.ToString(), Symbol.Code, Symbol.VolumeMin.ToString());
...
"
and this is the printout for two different symbols:
"
...
07/04/2018 14:39:37.704 | Broker name =: Kawase, SymbolCode =: EURUSD, MinVolume =: 1000,
...
"
"
...
07/04/2018 14:42:58.157 | Broker name =: Kawase, SymbolCode =: SWITZERLAND 20, MinVolume =: 0,
...
"
with a differen broke the result is:
"
07/04/2018 14:45:18.795 | Broker name =: FxPro, SymbolCode =: #Swiss20, MinVolume =: 1,
"
"
07/04/2018 14:46:45.958 | Broker name =: FxPro, SymbolCode =: EURUSD, MinVolume =: 1000,
"
@alexander.n.fedorov
alexander.n.fedorov
06 Apr 2018, 19:12
Pangiotis,
to be more correct the printout is this:
"
06/04/2018 19:09:24.677 | cBot "New Yourk Range v.3" was started successfully for SWITZERLAND 20, m15.
06/04/2018 19:09:24.802 | Instance NYR v.3 SWITZERLAND 20 1.0%
06/04/2018 19:09:24.833 | The Range Filter: Start the Trade = True
06/04/2018 19:09:24.896 | Stop Loss= 34.05, Take Profit = 61.2, symbol.Digitis = 2, Symbol.PipSize 1, PipDigits = 2
06/04/2018 19:09:24.911 | last trade: The were no trades on this pair
06/04/2018 19:09:25.005 | check 1
06/04/2018 19:09:25.005 | normCostofRange = 37.1665937909926
06/04/2018 19:09:25.005 | This is the volume checked = 0, Quantity = 26.2592021611765, PipSize = 1, PipDigits = 2
06/04/2018 19:09:25.005 | AmountRisked = 975.9651, Quantity = 26.2592021611765, normCostOfRange = 37.1665937909926
06/04/2018 19:09:25.005 | check 2
06/04/2018 19:09:25.021 | Placing Stop Order to Buy 0 SWITZERLAND 20 (Price: 8711.00, SL: 35.7, TP: 61.2)
06/04/2018 19:09:25.146 | → Placing Stop Order to Buy 0 SWITZERLAND 20 (Price: 8711.00, SL: 35.7, TP: 61.2) FAILED with error "BadVolume"
"
The first printout did was after commented command to print normCostofRange
Regards,
Sasha
@alexander.n.fedorov
alexander.n.fedorov
02 Apr 2018, 11:15
Hi Panagiotis,
Yes, it is working. As a matter of fact that is what I do, but when you do a lot of files, there is too much file management to do. I thought this is what automation is for.
For example, in Excel I can always automated with the use of Excel VBA.
:)
Regards,
Sasha
@alexander.n.fedorov
alexander.n.fedorov
30 Mar 2018, 10:04
Profitable bot
Dear Panagiotis,
Of course you helped! Three month ago I did not know that cAlgo existed. I could not write a line of code on c#.
If you give me your private mail, I will send you a bot with pleasure, as well as some, as I hope, very interesiting ideas.
You know, we in Russia say that "there is a share of joke in every joke." The meaning of it that not everything in a joke is a joke.
I am very confident that a good mathematics can make much more then 10% - 20% a year
Just in case you would like to continue with me my private mail is:
alexander.n.fedorov@gmail.com
I will be waiting for your reply.
Best regards,
Alexander
@alexander.n.fedorov
alexander.n.fedorov
29 Mar 2018, 23:23
( Updated at: 21 Dec 2023, 09:20 )
Profitable bot
Kind of like this
@alexander.n.fedorov
alexander.n.fedorov
26 Mar 2018, 16:07
even like that:
int PipDigits = Symbol.Digits - (int)Math.Log10(1 / Symbol.PipSize);
@alexander.n.fedorov
alexander.n.fedorov
26 Mar 2018, 16:03
Dear Pangiotis,
Nice and elegant. There is only one correction:
PipDigits=Symbol.Digits-Math.Log10(1 / Symbol.PipSize);
And then
SL= Math.Round(range/Symbol.PipSize,0,AwayFromZero);
Thank you
@alexander.n.fedorov
alexander.n.fedorov
25 Mar 2018, 19:14
Techincall Error when placing an order
The solution that seem to be working:
"
private int PipDigits;
....
for (int i = 0; i <= Symbol.Digits; i++)
{
if (1 / Symbol.PipSize == Math.Pow(10, i))
{
PipDigits = i;
break;
}
}
var StopLossInPips= Math.Round(range / Symbol.PipSize, PipDigits, MidpointRounding.AwayFromZero);
.....
"
But I don't think it is very elegant :(
@alexander.n.fedorov
alexander.n.fedorov
21 Mar 2018, 09:41
As a matter of fact, If I new how to interface an SQL server with print messages, then I could have all the history reported and automated
@alexander.n.fedorov
alexander.n.fedorov
21 Mar 2018, 09:39
Half close
If you could just give me an idea, how to get access to an Excel file, or even better - I store all of my trades there - to an SQL server.
Just small example will probably do
@alexander.n.fedorov
alexander.n.fedorov
21 Mar 2018, 06:12
Half close
Or maybe you mean that I have to keep list on a separate application list, like an Excel for example?
In my particular case after I close half, I do the trailing, so in this case position.Takeprofit equals to there could serve as a flag, I quesss, but it is not clean solution.
@alexander.n.fedorov
alexander.n.fedorov
20 Mar 2018, 17:57
Half close
Panagiotis,
nice Idea, the problem would be if the robot stops for some reason, restarting it you are going to loose a list, cause on restart everything is reinitialized.
It has to be smth on the server, like position information. Can I keep the list on a server? Probably not, that's why I wanted to use the position comment
Regards.
Sasha
@alexander.n.fedorov
alexander.n.fedorov
13 Mar 2018, 14:12
Pangiotis,
You very kind. It worked. Thank you
Regards
Alexander
@alexander.n.fedorov
alexander.n.fedorov
13 Mar 2018, 14:04
I was able to this:
"
...
foreach(HistoricalTrade trade in History)
{
if (trade.Label == Instance)
Print("closed trade ID = {0}, trade closing time = {1}", trade.ClosingDealId, trade.ClosingTime );
}
...
13/03/2018 15:00:00.941 | closed trade ID = 47704059, trade closing time = 12.03.2018 13:06:03
...
"
The I could cycle through the trades and find the last one, but what would be the syntax for "Find.Last" . How do I invoke the label there?
@alexander.n.fedorov
alexander.n.fedorov
14 May 2018, 10:02
Thank you Panagiotis, Clear enough as always
Sasha
@alexander.n.fedorov