Topics
Replies
JXTA
26 Jul 2024, 07:22
RE: RE: RE: Copy from one broker to another broker
PanagiotisCharalampous said:
TradeExpert said:
Thank you, and if the symbol is mapped correctly, then there is no problem to copy trades from one broker to another, right?
PanagiotisCharalampous said:Hi there,
There is a mapping between symbols with different names. If you think a symbol is not mapped correctly accross symbols, feel free to share more information about it.
Best regards,
Panagiotis
Yes this is correct
Which means when my robot execute #USSPX500 in FxPro, for my investor who using ICMarket will execute US500 at the same time when my robot trigger execution but there might be different spread/commission/swap which lead to different PnL result, investor account will execute any order whenever strategy provider account execute any order, is that correct?
@JXTA
JXTA
06 Dec 2023, 02:00
( Updated at: 06 Dec 2023, 06:16 )
RE: RE: RE: How to stop/pause closing an existing position countinuously if given criteria have already been met once?
firemyst said:
JINGXUAN said:
PanagiotisCharalampous said:
Hi there,
Unfortunately it is a lot of work to create a comprehensive example. If I find some time later, I will.
Best regards,
Panagiotis
Okay, many thanks in advanced ! PanagiotisCharalampous let me know when there are any example I can refer to, I will pay attention to any update of this link, have a great day ahead!
I keep track of every position I open internally using Dictionary objects:
private Dictionary<int, double> _positionEntryPricePoints; private Dictionary<int, double> _positionEntryVolumes; private Dictionary<int, DateTime> _positionEntryPriceTimes; private Dictionary<int, double> _increasePositionSizePoints;
The “key” is the position number and the “value” is the name of the Dictionary.
So for instance, if I open a German40 position with 3 lots @ 15:00 at the 12345 point, then:
price points would be (1,12345)
entry volume wouldbe (1,3)
entry price times would be (1, 2023/12/05 15:00)
Now if I increase my size by 1.5 lots at 12400 around 16:00, then:
price points would be (1,12345), (2,12400)
entry volume wouldbe (1,3), (2,1.5)
entry price times would be (1, 2023/12/05 15:00), (2, 2023/12/05 16:00)
increase position size points would now be (2,12400)
You get the gist.
I continuously update my Dictionary objects as appropriate so I know exactly where I'm at and what I've done.
You can do something similar for your closings.
Hi firemyst, thanks for your patient answer also very detailed explain, I will try it out and update when I get what I want! Thanks again! Very appreciated it
@JXTA
JXTA
04 Dec 2023, 12:57
RE: How to stop/pause closing an existing position countinuously if given criteria have already been met once?
PanagiotisCharalampous said:
Hi there,
Unfortunately it is a lot of work to create a comprehensive example. If I find some time later, I will.
Best regards,
Panagiotis
Okay, many thanks in advanced ! PanagiotisCharalampous let me know when there are any example I can refer to, I will pay attention to any update of this link, have a great day ahead!
@JXTA
JXTA
04 Dec 2023, 11:11
RE: How to stop/pause closing an existing position countinuously if given criteria have already been met once?
PanagiotisCharalampous said:
Hi there,
You should create your own structure where you should save the status of your position and keep track of what happened e.g.
public class PositionDetails { public Position position; public bool PartialTPTriggered; }
Then keep a list with one entry per position. When the partial tp is triggered set the PartialTPTriggered for that position to true. If it is triggered, do not trigger it again for that position.
Best regards,
Panagiotis
Hi Panagiotis, thanks for your quick reply, tho I understand(maybe) the concept of what you are trying to tell me, but I don't have advanced knowledge in programming, it would be great if you could please show me detail example of the code or any link I could refer to? Really appreciate it.
@JXTA
JXTA
18 Oct 2023, 13:06
( Updated at: 21 Dec 2023, 09:23 )
RE: RE: RE: Is there any way to retrieve the bar's bar count at which the position was entered?
firemyst said:
JINGXUAN said:
and it says :
‘Position[]’ does not contain a definition for ‘EntryTime’ and no accessible extension method ‘EntryTime’ accepting a fist argument of type ‘Position[]’ could be found
Of course it doesn't contain a definition. Your getting Long/Short positions returns arrays of Position objects; my example is with a single Position object.
The property “EntryTime” is for a single Position object, not an array of Position objects.
I see, pardon my mistake on that what I've asked, I am not a programmer,
Anyway, from what you have showed me previously
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 XXX: Robot
{
Position p;
protected override void OnStart()
{
int barIndex = Bars.OpenTimes.GetIndexByTime(p.EntryTime);
}
protected override void OnBar()
{
... ...
}
}
}
is that possible to extend it into something to define the current position trade type and then get that specific bar index ? or is there anyway to do it?
I will explain my idea here with code and photo
I have created a timer to let it count once a position is opened, but I doesnt know how to command it count specifically after a Buy order is opened or a Sell order is opened, because I am allowing my strategy to execute another trade type before one is closed, so I am needing this so much
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 TimerExample : Robot
{
//******************************************Generals******************************************
[Parameter("Volume (Lots)", DefaultValue = 0.1, MaxValue = 5, MinValue = 0.1, Step = 0.1)]
public double VolumeInLots { get; set; }
//******************************************Timer******************************************
private int _barCountToPosition;
private bool _startTimer;
//******************************************SMAs******************************************
[Parameter("SMA Source")]
public DataSeries SMASource { get; set; }
[Parameter("SMA_A Period", DefaultValue = 30)]
public int Sma_30_Period { get; set; }
[Parameter("SMA_B Period", DefaultValue = 60)]
public int Sma_60_Period { get; set; }
private SampleSMA _sma30;
private SampleSMA _sma60;
protected override void OnStart()
{
//Positions Timer
Positions.Opened += PositionOnOpened;
//SMA
_sma30 = Indicators.GetIndicator<SampleSMA>(SMASource, Sma_30_Period);
_sma60 = Indicators.GetIndicator<SampleSMA>(SMASource, Sma_60_Period);
}
void PositionOnOpened(PositionOpenedEventArgs obj)
{
_startTimer = true;
}
protected override void OnBar()
{
//LongLogic
if
( Positions.Find("LONG", SymbolName, TradeType.Buy) == null
&&
_sma30.Result.LastValue > _sma60.Result.LastValue || Bars.ClosePrices.LastValue > _sma30.Result.LastValue
)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInLots, "LONG");
}
//ShortLogic
if
( Positions.Find("SHORT", SymbolName, TradeType.Sell) == null
&&
_sma30.Result.LastValue < _sma60.Result.LastValue || Bars.ClosePrices.LastValue < _sma30.Result.LastValue)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInLots, "SHORT");
}
//LongTP
else if
(
Bars.ClosePrices.LastValue < _sma60.Result.LastValue && Positions[0].NetProfit > 0
)
{
ClosePosition(Positions.Find("LONG", SymbolName, TradeType.Buy));
}
//ShortTP
else if
(
Bars.ClosePrices.LastValue > _sma60.Result.LastValue && Positions[0].NetProfit > 0
)
{
ClosePosition(Positions.Find("SHORT", SymbolName, TradeType.Sell));
}
//LongStopLoss
/* (I want to write a Long stop loss based on the LowPrices of the Bar where the latest position was entered) */
else if
(
Bars.ClosePrices.Last(1) < Bars.LowPrices.Last( /*LongPositionEnteredBarIndex*/ ) && Positions[0].NetProfit < 0
)
{
ClosePosition(Positions.Find("LONG", SymbolName, TradeType.Buy));
}
//ShortStopLoss
/* (I want to write a Short stop loss based on the HighPrices of the Bar where the latest position was entered) */
else if
(
Bars.ClosePrices.LastValue > Bars.HighPrices.Last( /*ShortPositionEnteredBarIndex*/ ) && Positions[0].NetProfit < 0
)
{
ClosePosition(Positions.Find("SHORT", SymbolName, TradeType.Sell));
}
}
}
}
Could you help me with it ? How should I get that bar index
or Anyone could help me with this, thanks in advanced !
@JXTA
JXTA
18 Oct 2023, 09:38
RE: Is there any way to retrieve the bar's bar count at which the position was entered?
firemyst said:
To get the index of the bar where the latest position was opened:
Position p; //get your position information
//then get the index:
int barIndex = Bars.OpenTimes.GetIndexByTime(p.EntryTime);
Hi Firemyst just saw your comment! Thanks for your help! It helps me a lot!
I use the below code instead of Position p; you gave me
public Position[] LongPositions
{
get
{
return Positions.FindAll(LongLabel);
}
}
public Position[] ShortPositions
{
get
{
return Positions.FindAll(ShortLabel);
}
}
and it says :
‘Position[]’ does not contain a definition for ‘EntryTime’ and no accessible extension method ‘EntryTime’ accepting a fist argument of type ‘Position[]’ could be found
Is there any way to define current position type by Buy and Sell separately ? Because my strategy is allowing buy and sell logic execute at the same time
@JXTA
JXTA
15 Oct 2023, 05:35
( Updated at: 16 Oct 2023, 04:03 )
RE: Help creating an new indicator that will calculate and return a single result as output
PanagiotisChar said:
Hi there,
You cannot do this in C#. To do this you need to create a new IndicatorDataSeries and add the values one by one inside the calculate method.
Hi, thanks for reply, do you mean calculate in cbot onbar() area or in a new indicator then refer it to cbot?
I have a new post here with my indicator, can we please move our future discussion to here? Many thanks!
https://ctrader.com/forum/calgo-support/42069
@JXTA
JXTA
11 Oct 2023, 15:54
RE: Is there any way to retrieve OHLC info of the bar of our latest Entry/Position ?
PanagiotisChar said:
Do you mean the bar at which the position was entered?
yes sir! Thats what I was trying to ask. How should I do it? that bar's LowPrices
@JXTA
JXTA
11 Oct 2023, 13:22
RE: Is there any way to retrieve OHLC info of the bar of our latest Entry/Position ?
PanagiotisChar said:
Do you mean the bar at which the position was entered?
yes sir! Thats what I was trying to ask. How should I do it? that bar's LowPrices
@JXTA
JXTA
18 Sep 2023, 09:43
RE: how should I shift the value of Donchian's Low
PanagiotisChar said:
Hi there,
Just take the _donchianChannel.Bottom.Last(10) value. More generally use _donchianChannel.Bottom.Last(1 + offset)
Thank you so much!
@JXTA
JXTA
15 Sep 2023, 05:05
( Updated at: 21 Dec 2023, 09:23 )
RE: Backtesting Bug? (Spread)
JINGXUAN said:
see this, 1st photo is the backtesting provided deal map
2nd photo is the realtime deal map
Stop loss in the same level but the spread pips are not included in the backtesting system
I have found the source of causing this problem, when we are backtesting we should use the “Tick data from Server”, this will simulate the real time environment including all the spreads and commission
@JXTA
JXTA
08 Sep 2023, 06:26
RE: Creating Standard Deviation with SMA as source in cBot Robot
PanagiotisChar said:
Here you go
var sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 50);
var sd = Indicators.StandardDeviation(sma.Result,50, MovingAverageType.Simple);
Thanks Panagiotis, I found another problem while creating multiple SMAs and trying to use it as source in standard deviation it’s not possible to add up these SMAs, it says operator ‘+’ cannot be applied to operands of type ’SimpleMoving Average’ and ’SimpleMoving Average’, can you help me with the problem?
eg:
var sma1 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 50);
var sma2 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 100);
var sma3 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 150);
var sma4 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 200);
var sma_1234 = (((sma1+sma2)/2) + ((sma3+sma4)/2))/2
var sd = Indicators.StandardDeviation(sma_1234.Result,50, MovingAverageType.Simple);
@JXTA
JXTA
07 Sep 2023, 00:00
( Updated at: 07 Sep 2023, 05:44 )
RE: Problmes with referring custom indicator's to cBot causing none executed trade in Backtesting
PanagiotisChar said:
Hi there,
Check your log and you will see an exception. You do not initialize BotPositions anywhere
Need help? Join us on Telegram
Thanks Panagiotis
@JXTA
JXTA
26 Jul 2024, 09:13 ( Updated at: 26 Jul 2024, 10:44 )
RE: RE: RE: RE: RE: Copy from one broker to another broker
PanagiotisCharalampous said:
Thank you for your confirmation Panagiotis
@JXTA