Topics
Replies
r.stipriaan
22 Oct 2023, 07:21
RE: Symbol.GetEstimatedMargin not working
PanagiotisChar said:
Hi there,
It is better to share a specific example that somebody can easily reproduce. Share the full cBot code, the broker and symbol you are running this code on.
Hi PanagiotisChar,
I just found out that Symbol.GetEstimatedMargin() is only not working in backtest.
I use this for every currency pair, my broker is pepperstone.
When i run backtest on the dollar pairs only the outcome of the low leverage 1:20 pairs AUDUSD & NZDUSD is correct.
Code for example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
protected override void OnStart()
{
Print (Symbol.GetEstimatedMargin(TradeType.Sell,2000000));
}
protected override void OnTick()
{
}
}
}
@r.stipriaan
r.stipriaan
23 Dec 2022, 10:35
i made it interactive as you can see in the code above, line stays when the bot stops but not when it starts again.
@r.stipriaan
r.stipriaan
01 Oct 2022, 23:22
( Updated at: 01 Oct 2022, 23:32 )
Hi Samm193,
Use this variable:
[Parameter(" Volume Percent", DefaultValue = 15, MinValue = 0)]
public double VolumePercent { get; set; }
var Stoploss = Math.Floor(Account.Balance * 1 * VolumePercent / 1000) * 1000;
@r.stipriaan
r.stipriaan
27 Sep 2022, 21:40
Hi hamirady60,
I think its not posible to close positon on bars, i use this method, it works with time.
var SellPosition = Positions.Find("Short", SymbolName, TradeType.Sell);
if (SellPosition != null && SellPosition.EntryTime.AddHours(5) < TimeInUtc)
{
ClosePosition(Positions.Find("Short", SymbolName, TradeType.Sell));
}
@r.stipriaan
r.stipriaan
13 Aug 2021, 22:43
( Updated at: 13 Aug 2021, 22:45 )
RE:
thanks for your answer Musleh, unfortunately it still doesn't work when I enter Bars.Last(55).OpenTime at the x axis. with the following error: unable to convert from int to System.DateTime do you know what's going wrong?
for example:
var trendLine = Chart.DrawTrendLine("trendLine",Bars.Last(55).OpenTime , 0.75555, Chart.LastVisibleBarIndex, Bars.HighPrices[Chart.LastVisibleBarIndex], Color.Red, 2, LineStyle.Dots);
trendLine.IsInteractive = true;
@r.stipriaan
r.stipriaan
07 Aug 2021, 11:44
RE:
thank you, the link has the following example:
protected override void Initialize() { var trendLine = Chart.DrawTrendLine("trendLine", Chart.FirstVisibleBarIndex, Bars.LowPrices[Chart.FirstVisibleBarIndex], Chart.LastVisibleBarIndex, Bars.HighPrices[Chart.LastVisibleBarIndex], Color.Red, 2, LineStyle.Dots); trendLine.IsInteractive = true; }
here a trendline is drawn from the first visible point to the last visible point. when I change FirstVisibleBarIndex to bar.last(55) it shows an error saying invalid arguments. can you please tell me how to enter this correctly?
@r.stipriaan
r.stipriaan
13 Mar 2021, 17:33
( Updated at: 21 Dec 2023, 09:22 )
RE:
PanagiotisCharalampous said:
Hi r.stipriaan,
unfortunately the data the bot reads is incorrect
Can you please provide some evidence for this so that we can reproduce this situation as well?
Best Regards,
Panagiotis
Hi PanagiotisCharalampous!
First of all, my apologies for being late reacting, was a bit busy lately and I didn't quite know how to explain this situation.
To give a clear picture of what exactly happened I printed all the prices in the log of the high and the low and tagged them exactly in the chart of the eur usd 1d. (see picture).
As we can see, the prices indicated by the indicator do not correspond at all to what is shown in the chart. We see 2 different channels.
I also added an order to only take a sell position when price is falling (see red and green dots on the bars). From this we can see that they do not correspond to one of the 2 channels.
Then did some research on the bot itself but this one is still too hard to read for me, if you want to see this one: https://ctrader.com/algos/indicators/show/71
(not sure if this ecxact is the same indicator as the built-in one. As far as visible everything is the same).
Thank you very much in advance. I am very curious how this can be explained and resolved!
Robin
@r.stipriaan
r.stipriaan
16 Feb 2021, 23:02
( Updated at: 21 Dec 2023, 09:22 )
RE:
PanagiotisCharalampous said:
Hi r.stipriaan,
Check your log and you will see the exception below
The problem is that you are trying to close a position even if there is no position open.
Best Regards,
Panagiotis
Hi Panagiotis,
Thanks for the quick reply!
The solution was more difficult than it seemed, after a few hours of trying still no results. Can you tell what is going wrong from the code?
The last 2 lines have been added but the bot does not return.
Thanks in advance,
Robin
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("Periods", DefaultValue = 14)]
public int Periods { get; set; }
private RelativeStrengthIndex rsi;
protected override void OnStart()
{
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
}
protected override void OnBar()
{
if (rsi.Result.LastValue > 70)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, 1000, "Short", 100, 100);
}
if (rsi.Result.LastValue < 30)
{
ClosePosition(Positions.Find("Short", SymbolName, TradeType.Sell));
}
if ((Positions.Find("Short", SymbolName, TradeType.Sell)) == null)
return;
}
}
}
@r.stipriaan
r.stipriaan
16 Feb 2021, 13:15
HI Panagiots,
Thank you so much for answering my question.
Robin
@r.stipriaan
r.stipriaan
29 Oct 2023, 19:40
Hi Sarvann,
You can make a array of the last bars and use the .min() and .max() function.
Or draw lines whenever a high is higher or low when lower.
@r.stipriaan