No clues unfortunately. Can you record a video demonstrating the whole UI and the entire process of adding an instance and reproducing the issue? Maybe it can provide some information we are missing
Hi Panagiotis, hope you are well. Look. I need help to code an increase with the lotsize while my position progresses. For example, when 2 pips positive, double the lot. But the Chatgpt is saying it is not possible to increase Lotsize in Ctrader. Although, we have a button on Ctrader that do Just that, Double the.position size.
Can you help me please
Hi there,
Please create a separate thread with your question and make it more specific. Tell me what information is missing and what is stopping you from implementing this yourself so that I can help you.
The entry price of the position is the average entry price of the deals composing the position. If the position has only one opening deal, then the opening price should not change. If more opening deals are involved e.g. you have increased the size of the position after entering it, the entry price might change as partial volume is closed and deals removed from the position.
Best regards,
Panagiotis
Ok, thanks, that's helpful. I can see from logging that when the volume of a position is INCREASED the calculation of its new Position.Pips value is exactly: (oldPips * oldVol - spreadAsPips * increaseInVol) / newVol which is correctly distributing the pips on the old portion plus the immediate pip loss of the new portion (due to spread) across the new larger volume (and so the EntryPrice will be that many pips from the current price and represent the weighted average). Rounding of the calculation seems usually to the nearest 0.1 pip but sometimes goes the other way, possibly to correct for accumulated rounding error. That's all fine.
HOWEVER, I'm seeing the remaining portion of a position after a REDUCTION in volume ALSO has its Position.Pips altered. Why is that? Possibly the position was not combined really (in the live server or backtest memory) but rather kept as a collection of parts from each modification that increased volume, so that when it is later reduced some specific part is closed, in a LIFO or FIFO order or some other rule? Is this broker driven?
So maybe ModifyPosition does not really modify a position in the sense of ending up with one homogeneous position with a single EntryPrice & Pips profit? Can't brokers running cTrader handle merging modification deals into one net holding?
If not, please could the doc say so, and how do we know what the separate parts are so we can predict partial closing results (without laboriously keeping track of all modifications)? Is there any information in a Position that can tell a cBot the position's stats will not react in a predictable way if later PARTIALLY closed ('predictable' meaning Entry & Pips stay unchanged, profit prorata etc)?
I'm coming to the conclusion it's not good to mix increasing and decreasing volume via ModifyPosition; one or the other yes, predictable, but not both in the same cBot if it's basing decisions on Position.Pips or Account.UnrealizedProfit, or on almost anything other than Equity.
Thanks.
Update re "laboriously keeping track": not that hard, but involves keeping ‘account state’ data outside the cTrader account, like in a local file or cloud, not self-contained in the positions - unless perhaps cTrader could add a large Account.Comment field that could store arbitrary data, or make the Positions.Comment modifyable & bigger?? :)
Later: Actually only one adjustment number per position might need remembering in order to emulate proportional netting when partially closing a position that has been increased earlier - the difference between ‘the proportional Pips or Entry expected before the partial close is done’ and ‘the actual new Pips or new Entry that appears in the Position afterwards’ - so the Bot can apply that offset to later Pips & profit (with opposite adjustment to Balance). Is there any way of storing a small amount of data per position on the server, for instance a modifyable Comment?
Hi there,
HOWEVER, I'm seeing the remaining portion of a position after a REDUCTION in volume ALSO has its Position.Pips altered. Why is that? Possibly the position was not combined really (in the live server or backtest memory) but rather kept as a collection of parts from each modification that increased volume, so that when it is later reduced some specific part is closed, in a LIFO or FIFO order or some other rule? Is this broker driven?
This is what I explained in my previous post. Positions are just collections of deals traded in a FIFO manner.
Is there any information in a Position that can tell a cBot the position's stats will not react in a predictable way if later PARTIALLY closed ('predictable' meaning Entry & Pips stay unchanged, profit prorata etc)?
There isn't. As you correctly pointed out, if you need this information, you need to track it your self.
I did not understand what you are doing and what exactly is happening. Can you record a video so that we can understand what you are looking at?
Best regards,
Panagiotis
Hi,
I undwerstood from this video that I can fix a risk reward (lets sasy 100 usd) and when I move My SL on a limit order the nb of lots is computed automatically to keep 100 usd of risk. And that if I change to market order the nb of lots will be computer when I click the buy/sell button based on the current price to respect 100 usd risk.
My be I understood wrong the feature for market order.., if i understood wrong can you any idea how I can do this as I want to always have the same risk
Thanks
Hi there,
It is impossible to set the risked amount exactly at a fixed stop loss price, since the trade eventually needs to be rounded at a volume that meets the minimum step set by the broker. Therefore you will get an approximation at best. The tool calculates the exact volume that needs to be traded for that amount to be risked but eventually you need to trade the closest valid volume.
Just use an external IDE for development. You can do this with a click of a button and get all the development functionalities you need. The built in editor is appropriate only for simple projects.
Best regards,
Panagiotis
Even with simple projects, one often needs to copy the error messages. Moreover, the new developers and advanced users who are learning to code are likely doing that in cAlgo and they are those who are most likely to encounter compilation errors they need to copy (to ask other developers about).
They can do that in an IDE. The product team will not divert resources from other important features to build something that already exists and can be used immediately.
Just use an external IDE for development. You can do this with a click of a button and get all the development functionalities you need. The built in editor is appropriate only for simple projects.
The entry price of the position is the average entry price of the deals composing the position. If the position has only one opening deal, then the opening price should not change. If more opening deals are involved e.g. you have increased the size of the position after entering it, the entry price might change as partial volume is closed and deals removed from the position.
this will crash until you replace OnBarClosed with OnBar, which I did to have it work also works with 1hr tf correctly, and it crashes with both fp markets and fusion markets accounts
Thank you. This issue will be fixed in an upcoming update.
Why don't you use an external IDE like Visual Studio instead? I don't think the team will invest time in reinventing the wheel.
Best regards,
Panagiotis
I do it, and although it improves things like IntelliSense, the management of duplicated code between bots doesn't get better since each bot is a solution, as I mentioned in the previous post. If there were a way to make each bot a project instead of a solution, then the development experience could be greatly improved. And if there is a way, I'm not aware of it.
No it is not possible, however you can reference shared projects across many solutions, if this is what you are looking for.
I'm trying to create a shared Library to use across my indicators and cBots, I can't stand replicating or copying code.
I decide to follow you recommendation of using a Shared Project. I have a couple questions:
1- Do you recommend having a single Git Repo for all Indicators and cBots, I mean creating the repo under <USER_HOME>\Documents\cAlgo\Sources or Should I setup 1 project per indicator?
2-If 3 indicator are all using the same shared Project, Do I need to create that sharedProject with the Solution of 1 Indicator or cBot and reuse in others?
I noticed that if the SharedProject isn't located within a specific location the AlgoHost.exe proecess crashes with error of not having access to the SharedProject folder. Which folder under under <USER_HOME>\Documents\cAlgo\Sources the SharedProject must be to prevent this?
Thanks.
Would be great i you could provide a sample of 2 indcators and 2 cBots using a shared project.
Hi there,
Unfortunately there is no correct answer to your questions as it all depends on your own requirements.
Best regards,
Panagiotis
Thank you for your very diplomatic reply, that doesn't really take us anywhere.
I think it's really deciving to point your users nowhere rather than helping with real problems.
If what cTrader recommend is to write duplicate code, then please be clear on that.
If you recommend shared project then please be clear and give a simple example of :
Indicator A, Indicator B, sharedProject C and robot D all using logic in SharedProject C.
If that's not possible then please say so.
I really don't see what our own requirements could make a difference in this very specific question.
Hi there,
It's not a diplomatic answer, it's just beyond the scope of my work. My role here is to explain how cTrader works, answer questions specific to cTrader and liaise for the resolution of problems. Giving trading advises, answering general software development questions and teaching people to code is above my role. Therefore I rarely engage in such discussions. The question on how to organize your projects is not a cTrader specific one but a general software development question. A cBot/Indicator/Plugin is just a .Net project so whatever applies to other .Net projects, applies here as well. Each developer organizes his projects as he sees fit.
What you describe should be possible, unfortunately I do not have time to prepare an example for you. If you thing there is a specific cTrader problem, let us know how to reproduce it and we will have a look at this.
Best regards,
Panagiotis
No, a cTrader bot/plugin/indicator is not a project but a solution. This is the reason for the topic.
I don't see the problem. In .Net, you can reference projects that are parts of solutions in other solutions. This is not a cTrader thing, is a .Net thing. So you can have an indicator as a standalone solution, as well as reference it in other solutions i.e cBots or plugins
Why don't you use an external IDE like Visual Studio instead? I don't think the team will invest time in reinventing the wheel.
Best regards,
Panagiotis
I do it, and although it improves things like IntelliSense, the management of duplicated code between bots doesn't get better since each bot is a solution, as I mentioned in the previous post. If there were a way to make each bot a project instead of a solution, then the development experience could be greatly improved. And if there is a way, I'm not aware of it.
No it is not possible, however you can reference shared projects across many solutions, if this is what you are looking for.
I'm trying to create a shared Library to use across my indicators and cBots, I can't stand replicating or copying code.
I decide to follow you recommendation of using a Shared Project. I have a couple questions:
1- Do you recommend having a single Git Repo for all Indicators and cBots, I mean creating the repo under <USER_HOME>\Documents\cAlgo\Sources or Should I setup 1 project per indicator?
2-If 3 indicator are all using the same shared Project, Do I need to create that sharedProject with the Solution of 1 Indicator or cBot and reuse in others?
I noticed that if the SharedProject isn't located within a specific location the AlgoHost.exe proecess crashes with error of not having access to the SharedProject folder. Which folder under under <USER_HOME>\Documents\cAlgo\Sources the SharedProject must be to prevent this?
Thanks.
Would be great i you could provide a sample of 2 indcators and 2 cBots using a shared project.
Hi there,
Unfortunately there is no correct answer to your questions as it all depends on your own requirements.
Best regards,
Panagiotis
Thank you for your very diplomatic reply, that doesn't really take us anywhere.
I think it's really deciving to point your users nowhere rather than helping with real problems.
If what cTrader recommend is to write duplicate code, then please be clear on that.
If you recommend shared project then please be clear and give a simple example of :
Indicator A, Indicator B, sharedProject C and robot D all using logic in SharedProject C.
If that's not possible then please say so.
I really don't see what our own requirements could make a difference in this very specific question.
Hi there,
It's not a diplomatic answer, it's just beyond the scope of my work. My role here is to explain how cTrader works, answer questions specific to cTrader and liaise for the resolution of problems. Giving trading advises, answering general software development questions and teaching people to code is above my role. Therefore I rarely engage in such discussions. The question on how to organize your projects is not a cTrader specific one but a general software development question. A cBot/Indicator/Plugin is just a .Net project so whatever applies to other .Net projects, applies here as well. Each developer organizes his projects as he sees fit.
What you describe should be possible, unfortunately I do not have time to prepare an example for you. If you thing there is a specific cTrader problem, let us know how to reproduce it and we will have a look at this.
so I’m not really fam with coding on this platform and currently the code does plot horizontal lines on the workspace. the ideal output is
-user defines (current) price at which the algo starts plotting horizontal lines
-user defines increment at which each horizontal line is plotted
for example ( Gold 2000, 3, 100)
algo plots a horizontal line each $3
currently my code gives me the prompts for each parameter but does not even plot a single line. ideally the code would plot automatically using a for loop. But worst case scenario I can manually enter the code for each line
Hi there,
Can you explain your issue in more detail? What do you expect your code to do and what does it do instead?
Best regards,
Panagiotis
Hi there,
I tried your indicator and it plots the lines fine.
So I do not see a problem.
Best regards,
Hey there,
Thanks for trying out the code. However the issue is that it's not supposed to just plot one line. It supposed to plot multiple lines as defined by the User. Could you share the code you used to get it to plot a line ? Cause I was not able able able to get my code to plot a single line.
Thank you in advance.
Hi there,
I used the code you shared. If you want to plot several lines, you need to write the relevant code i.e. a for loop where you will plot lines at different increments.
PanagiotisCharalampous
15 Nov 2024, 14:26
RE: RE: when adding to a losing/winning trade, it changes the take profit
walt50050 said:
Unfortunately I cannot help you if you do not provide the information I am asking for
@PanagiotisCharalampous