StateMachine Design Tools?

Created at 18 Jun 2016, 14:57
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Mikro's avatar

Mikro

Joined 20.06.2015

StateMachine Design Tools?
18 Jun 2016, 14:57


Hi all,

to implement trading strategies a state machine would come in handy at times.

As of now I found no other option to code one than to use a switch statement and an enumeration to be able to switch to different logic blocks depending on the actice Triggers...

      private enum ds
        {
            Timer,
            Idle,
            OpenLong,
            OpenShort,
         }

  switch (DirectorState)
                {
                    case ds.Timer:      // DS: TIMER
                        if (DsTimer()==true) CycleComplete = true;
                        break;

                    case ds.Idle:       // DS: IDLE
                        if (DsIdle() == true) CycleComplete = true;
                        break;

                    case ds.OpenLong:   // SM: OPEN LONG
                        if (DsOpenlong() == true) CycleComplete = true;
                        break;
                  }

 

For Visual Studio there are Add-ins like 'Stateless' Designer but I could not get them to work for cBot design so far.

Has anybody found a tool, perhaps even a graphical, to create StateMachines in a cBot so far?

THX


@Mikro
Replies

zelenij.krokodil
19 Jun 2016, 08:09

RE:

Mikro said:

Hi all,

to implement trading strategies a state machine would come in handy at times.

As of now I found no other option to code one than to use a switch statement and an enumeration to be able to switch to different logic blocks depending on the actice Triggers...

      private enum ds
        {
            Timer,
            Idle,
            OpenLong,
            OpenShort,
         }

  switch (DirectorState)
                {
                    case ds.Timer:      // DS: TIMER
                        if (DsTimer()==true) CycleComplete = true;
                        break;

                    case ds.Idle:       // DS: IDLE
                        if (DsIdle() == true) CycleComplete = true;
                        break;

                    case ds.OpenLong:   // SM: OPEN LONG
                        if (DsOpenlong() == true) CycleComplete = true;
                        break;
                  }

 

For Visual Studio there are Add-ins like 'Stateless' Designer but I could not get them to work for cBot design so far.

Has anybody found a tool, perhaps even a graphical, to create StateMachines in a cBot so far?

THX

Can't you create a separate library project, design the state machine there and then just link the library to your main cBot robot project?


@zelenij.krokodil

Mikro
19 Jun 2016, 10:14

Hi,

sounds like an idea. Havn't created a separate library project for a cBot yet.

How would you do that an how would you transfer the stateinfomation, buy and sell signals and so on?

Do you know an open source tool for graphical statemachine design? I took a look at the MATLAB Stateflow Demo but could not manage to compile c# code...

THX


@Mikro

zelenij.krokodil
20 Jun 2016, 16:24

RE:

Mikro said:

Hi,

sounds like an idea. Havn't created a separate library project for a cBot yet.

How would you do that an how would you transfer the stateinfomation, buy and sell signals and so on?

Do you know an open source tool for graphical statemachine design? I took a look at the MATLAB Stateflow Demo but could not manage to compile c# code...

THX

Depends on what you need to do, you can:

1. In the library create a state machine object, that accepts Robot as one of the construction parameters

2. Use the state machine object to make all the trading decisions, calling to the relevant Robot methods

3. In the actual algo create an instance of the state machine object and pass it this

4. Don't forget to reference cAlgo dll in the library project

I personally haven't used any state machine generation code, so can't help you here.  But there must be at least some libraries that will make your life easier - maybe search for workflow or rules engines


@zelenij.krokodil

Mikro
07 Jul 2016, 21:38 ( Updated at: 21 Dec 2023, 09:20 )

RE: RE:

Hi Zelenij,

took me a while to find some time for programming again.

Sorry to have to ask a few noob questions here.

In Visual Studio I switched from Net Framework 4.0 to 4.5. Then in Workflow Foundation I have the state machine toolbox availabe. In my solution I created a state machine workflow. Now I'm stuck with the construction parameters, how do I set these in the state machine?

How do I call Methods from the cBot from within the state machine workflow object?

And finally were do I need to reference the dll in the cAlgo project?

THX!

zelenij.krokodil said:

Depends on what you need to do, you can:

1. In the library create a state machine object, that accepts Robot as one of the construction parameters

2. Use the state machine object to make all the trading decisions, calling to the relevant Robot methods

3. In the actual algo create an instance of the state machine object and pass it this

4. Don't forget to reference cAlgo dll in the library project

I personally haven't used any state machine generation code, so can't help you here.  But there must be at least some libraries that will make your life easier - maybe search for workflow or rules engines

 


@Mikro

zelenij.krokodil
10 Jul 2016, 18:18

First, I don't know if you can actually use .NET framework 4.5 with cAlgo - I think our good friends from Spotware are lagging a few years behind the rest of the world in that regard.

 

You can add a reference to cAlgo dll - you should be able to find it in your Documents/cAlgo somewhere.

 

Then you need to have a reference to a Robot object - pass it to your state machine as a construction time parameter or have it as a property which you will set first thing.


@zelenij.krokodil