Topics
Replies
AnthonyY
26 Apr 2022, 10:36
RE: RE: RE:
amusleh said:
instylereality2 said:
amusleh said:
Hi,
Your cBot code is executed by a single thread on an event loop, so while it's blocked inside OnStart method it can't execute OnTick or any other method/event.
If you want to keep checking for something then use the Timer, blocking the cBot thread will prevent execution of all other cBot methods, events, properties update, etc...
Hey amusleh thank you for stepping in!
So to clarify the goal apart the code itself which was just an approach yeah, the idea is the single thread in OnStart() to handle all the limit orders, which are the only type I'll be using. So I came to the conclusion that OnTick() should be handling the price monitoring system and the two voids should be executing simultaneously somehow so the strategy could proceed to the next phases depending on how the market goes without taking certain amount of time because the bot would be on for full week for example. Now my question is,
Is that possible to be achieved with a single bot or should I just split it into different bots?If it can be in one it is a life saver if not I need to adapt everything else accordingly.
(edit: parallel invoke??)
Thank you!
Hi,
I have no idea what you are trying to do, and why you need a loop inside OnStart method that will be stopped by OnTick event execution.
Use OnStart to populate or configure your bot and OnTick / OnBar / OnTimer / Events for trading.
Avoid blocking the cBot/Indicator thread for very long time as it will stop execution of all other methods and events.
What do you mean by: "the idea is the single thread in OnStart() to handle all the limit orders"
Your cBot thread is responsible for executing your cBot methods, event handlers, and updated it's properties.
Yeah I was meant to say that the main body of the code would be in OnStart. The loop was just an approach to as to how to stay in OnStart waiting for an event yes, but the event Iam looking for in order to proceed to the next trading phases placing the next set of limit orders is just the the update of Price level or Prc (live Price update). When the feedback of ask and bid / 2 matches my preset levels a certain pre calculated set of limits are placed, for that I was thinking to create a system in a system by using the OnTick () which in a sense is a loop itself, but if it's not even possible technically there's no point to bang my head over it I will just bypass it and figure something else out. The strategy is kind of big and has pretty much everything from account management based on equity to placing orders and monitoring their progress at the same time. But all depends on the main approach and how all these small systems will interrelate and function all based on preset parameters.
Thank you
@AnthonyY
AnthonyY
26 Apr 2022, 10:03
( Updated at: 26 Apr 2022, 10:07 )
RE:
amusleh said:
Hi,
Your cBot code is executed by a single thread on an event loop, so while it's blocked inside OnStart method it can't execute OnTick or any other method/event.
If you want to keep checking for something then use the Timer, blocking the cBot thread will prevent execution of all other cBot methods, events, properties update, etc...
Hey amusleh thank you for stepping in!
So to clarify the goal apart the code itself which was just an approach yeah, the idea is the single thread in OnStart() to handle all the limit orders, which are the only type I'll be using. So I came to the conclusion that OnTick() should be handling the price monitoring system and the two voids should be executing simultaneously somehow so the strategy could proceed to the next phases depending on how the market goes without taking certain amount of time because the bot would be on for full week for example. Now my question is,
Is that possible to be achieved with a single bot or should I just split it into different bots?If it can be in one it is a life saver if not I need to adapt everything else accordingly.
(edit: parallel invoke??)
Thank you!
@AnthonyY
AnthonyY
25 Apr 2022, 14:00
RE: RE: RE:
firemyst said:
instylereality2 said:
firemyst said:
I'm not sure your idea will work, as I believe the "OnTick" events only occur after OnStart has completed.
Obviously Spotware can confirm, but if that's the case, you'll have to redo your logic.
Yeah, I was feeling that this would be the case. A confirmation is needed on this for sure.
Any idea about how this could be achieved? Or isn't possible at all to have a live price checking mechanism in OnTick() that would be combined with OnStart() to complete a continues checking cycle??
Thank you!
Why do you even need to wait in OnStart until something happens?
Just set a flag to false, and when it occurs in OnTick, set the flag to true.
Then check the flag in OnTick and when it's true, go through another branch of code.
Yeah that was kind of what I was trying to do there. Iam counting on OnStart because the OnTick will just produce infinite number of pending orders if that makes sense. Iam not a professional programmer, so I am still learning the tricks so to speak.
Thank you!
@AnthonyY
AnthonyY
25 Apr 2022, 09:23
RE:
firemyst said:
I'm not sure your idea will work, as I believe the "OnTick" events only occur after OnStart has completed.
Obviously Spotware can confirm, but if that's the case, you'll have to redo your logic.
Yeah, I was feeling that this would be the case. A confirmation is needed on this for sure.
Any idea about how this could be achieved? Or isn't possible at all to have a live price checking mechanism in OnTick() that would be combined with OnStart() to complete a continues checking cycle??
Thank you!
@AnthonyY
AnthonyY
21 Apr 2022, 11:28
RE:
amusleh said:
Hi,
There are several overloads available for ModifyPendingOrder method, if you don't want to change something then you can pass it's current value:
foreach (var order in PendingOrders) { if (order.Label == "SellD1TargetToBuyBackUpAirDist") { ModifyPendingOrder(order, order.VolumeInUnits, newStopLossInPips, order.TakeProfitPips); // You can also use the PendingOrder.ModifyXXX methods // order.ModifyStopLossPips(newStopLossInPips); } }
Hi!
You are the best, I don't know why but now it works and figured more in the process thank you so much!
I suppose the same goes similarly with ModifyPosition, yeah?
@AnthonyY
AnthonyY
31 Mar 2022, 17:09
RE:
amusleh said:
Hi,
To create multi option parameters you can use .NET enums, here is an example:
using cAlgo.API; namespace NewcBot { [Robot(AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter("Switch", DefaultValue = Switch.On)] public Switch SwitchParameter { get; set; } protected override void OnStart() { if (SwitchParameter == Switch.On) { Print("Switch in On"); } else { Print("Switch in Off"); } } } public enum Switch { On, Off } }
Thank you! That worked perfect, take care!
@AnthonyY
AnthonyY
25 Jan 2022, 10:58
RE:
amusleh said:
Hi,
Then you don't have to use cTrader Automate API at all, you can do everything with Open API.
You can get the bars/tick data with Open API, calculate your indicators, and feed the data to your ML model.
And you can execute the trading operations with Open API, you don't automate API in whole process at all.
You can do all in Python.
You can't reference OpenApiPy from a .NET environment unless you use something like IronPython which I don't have any experience with it at all.
We have a Jupyter sample in OpenApiPy Github repository that gets bars data and uses Python sklearn package to train a machine learning model, please check it: OpenApiPy/samples/jupyter at main · spotware/OpenApiPy (github.com)
Yes, already passing through all the material days now! Researching everything as all is new to me as well.
This is brilliant! So it is possible to parse data from all ctrader indicators I may have like Harmonics, Financial Markets pivots and all through OpenApiPy, which can hold data evaluation and order execution logic as well as the AI later on.
In the samples folder on github, I see a picture of the web page with the commands. As I haven't reached that stage myself yet, is ProtoOAAssetClassList or asset list referring to active ctrader indicators? Or assume that there is enother command for that?
A last one and thank you for the assistance, OAuth2.0, do I need that in my system as well? Please assume that at least for the start I exclusively base my code on your github for openapipy.
Thank you Amusleh
@AnthonyY
AnthonyY
25 Jan 2022, 10:04
RE:
amusleh said:
Hi,
Why you want to use Open API on your cBot? you have all the things you need in automate API.
As I said automate API is separate from Open API, you should use one not both at the same time.
But if you want to you can use Open API inside cTrader automate API environment, you don't have to use the Python package you can do it with .NET C#.
Hi!
Yes, I think sometimes I just make it more difficult for myself for no particular reason.
I am trying this approach because I find python better than C# as it is dynamic language, also OpenApiPy uses Twisted which I think I can work with based on your Github examples instead of protobuffers which I find complicate to understand how to use them from the documentation which is limited on other online places.
I just finished uni so I am not like the best programmer out there. I thought that my approach will be best because later on I am thinking to implement machine learning to my system which requires python as well as the data from indicators which are given from cAlgo. So I need the various indicator data from ctrader sent to a enother environment better situated for AI, evaluate the data given and whatever the outcome buy/sell order will be given back to ctrader. I guess the very first step would be ctrader automate anyway. Do you thing referencing from ctrader automate would work with OpenApiPy?
Thank you again!!
@AnthonyY
AnthonyY
24 Jan 2022, 14:07
( Updated at: 24 Jan 2022, 14:09 )
RE:
amusleh said:
Hi,
Let me first make some things clear for you, cTrader have three different types of APIs, each serve a different purpose:
- cTrader Automate API: It's part of cTrader desktop app, you can use it to create indicators and cBots for cTrader desktop app.
- FIX API: It's the standard FIX API implementation that is available for cTrader trading accounts, you can use it to trade and get price data of your cTrader trading account, but the FIX standard is very limited and old, you can get your trading account FIX API credentials from cTrader app settings section, we have some samples on our Github that you can use.
- Open API: This is another API cTrader provides, it's not dependent on cTrader desktop/web/mobile apps and it's fully separate from the two abovementioned APIs, this is the API that you can use to create fully featured trading platforms or trading algorithms that will operate on your or any other cTrader users trading accounts. if you want to create an app or a trading algorithm outside cTrader official provided apps that will be your go to option. we have plenty of rich samples for this API on our Github for different programming languages, we have developed SDKs for this and also some third party developers made lots of contribution to develop different packages/wrappers for this cTrader API, you can check our OpenAPI.NET or OpenApiPy Github repositories.
So regarding your question, I don't recommend you to use Open API inside cTrader automate API, if you want to build a trading strategy then use cTrader automate API.
In case you want to build something more complicated and feature rich use Open API.
And use FIX API only if you know what you are doing.
OpenApiPy is a Pyhton package that allows you to use the Open API easily inside a Python app or environment, it's developed and maintained by Spotware.
If you want to use OpenApiPy please check it's documentation.
And if you are interested in Open API take a look on it's documentation.
Hi Amusleh and thank you for your reply
Ctrader automate is based on C# and OpenApiPy on Python.
What I am thinking based on the documentations I read, is that I could write cBot with all its indicators and all and then connect it with the OpenApiPy with referencing I believe??
The goal is cBot indicator data, to be transferred to OpenApiPy which will be the one that will contain the logic behind order execution based on the data given.
I read on the documentations that for that I will need to make a .dll to reference these two. Am I correct on those points?
I think in all we talk about making ctrader automate and OpenApiPy to communicate with each other I suppose.
Than you!
@AnthonyY
AnthonyY
11 Apr 2024, 12:34
Very interested, i was searching for something like that.
@AnthonyY