Topics

Forum Topics not found

Replies

amusleh
24 Mar 2022, 09:16 ( Updated at: 24 Mar 2022, 12:03 )

RE: RE: RE: RE: RE:

florent.herb said:

Hi amusleh,

I would like your view on this that has little to do with the topic above but still... 

What is more "important" considering a forex VPS in general: RAM or number of CPU?

Considering a dozen of instances opened at the same time on ctrader, between 4 or 6 GB of RAM and 4 or 6 CPU what combo of RAM / CPU would be best to choose? Thank you for all the help you can give me :)

Best Regards,

Florent

Hi,

It depends on your cBot and the way you want to use cTrader, for optimization the number of cores and base clock of each core is very important because optimization can use multiple cores and run in parallel multiple back tests on different CPU cores, it's not sequential like back test.

If you want to use VPS for optimization you you need at least 8 GB of ram and a 4 core CPU.

Increasing RAM size will not increase the optimization speed unless your cBot uses lots of RAM.


@amusleh

amusleh
24 Mar 2022, 09:11

Hi,

What do you mean by referencing them?

You have access to all chart objects and the events like object added/removed/updated.

If you want to draw trend line on chart you can do it with Char.DrawTrendLine method.

Here are some examples:

cAlgo API Reference - Chart Interface (ctrader.com)

cAlgo API Reference - ChartArea Interface (ctrader.com)

cAlgo API Reference - ChartTrendLine Interface (ctrader.com)

 


@amusleh

amusleh
23 Mar 2022, 07:50

Hi,

You can use historical tick data to get historical spread data.

Just get the historical tick data by using API ProtoOAGetTickDataReq message, and then calculate the spread by using each tick bid/ask prices, spread is the different between bid and ask price.


@amusleh

amusleh
22 Mar 2022, 11:30

RE:

csabz90 said:

Thanks for checking! I had a go at it using the console sample from your repo as you suggested, same error unfortunately.

I have a demo account with IC Markets, that's what I'm trying to use. What's weird is using FIX API to communicate with cTrader I am able to open a market order, but with Open API I can't, 'TRADE permission required'... Can you imagine the broker allowing demo trading through cTrader through FIX API but not through Open API? Anyway, I'll try with another broker just to check. Please don't hold back if you have any broker suggestions for this purpose!

 

Hi,

I tested on IC demo, and it worked fine.


@amusleh

amusleh
22 Mar 2022, 08:29

Hi,

I tested the Python console sample on your application, it worked fine, I was able to create new market orders on my demo trading accounts.

Can you tell me which broker you are using?

And please try on console sample, see if it works or not.


@amusleh

amusleh
21 Mar 2022, 12:55 ( Updated at: 19 Mar 2025, 08:57 )

Hi,

Did you checked all the checkbox(s) on your application form under Application Usages?

If you did that then please send an email to support@ctrader.com with your application name and your cID.


@amusleh

amusleh
21 Mar 2022, 08:49

Hi,

A Symbol schedule field gives you the symbol trading sessions, each session (ProtoOAInterval) has a start time which is inclusive and end time which is exclusive.

By inclusive it means that value is included, and by exclusive it mean that value it not included.

This data for each symbol is set by your broker, and if there is a gap between two sessions then it means you can't trade that symbol during that gap period.


@amusleh

amusleh
21 Mar 2022, 08:42

Hi,

Inside position closed event handler you are using LastResult, it's Position property is null:

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            var SPREAD = (double)((int)Math.Round(Symbol.Spread / Symbol.PipSize, 5));
            // check if the position has been closed due to stoploss or takeprofit or any other(stop out etc)

            if (LastResult.Position == null)
            {
                Print("LastResult.Position is null");
            }

            if (args.Reason == PositionCloseReason.StopLoss)
            {
                Print("PID: [ {0} ] Stoploss Hit {1}   ||   Gain/Loss {2}Pips / $ {3}   ||   Spread:{4}   ||   {5} {6}:{7}:{8} ", LastResult.Position.Id, SymbolName, LastResult.Position.Pips, LastResult.Position.NetProfit, SPREAD, Server.Time.DayOfWeek, Server.Time.Hour, Server.Time.Minute, Server.Time.Second);
            }
            else if (args.Reason == PositionCloseReason.TakeProfit)
            {
                Print("PID: [ {0} ] Take Profit Hit {1}   ||   Gain/Loss {2}Pips / $ {3}   ||   Spread:{4}   ||   {5} {6}:{7}:{8}", LastResult.Position.Id, SymbolName, LastResult.Position.Pips, LastResult.Position.NetProfit, SPREAD, Server.Time.DayOfWeek, Server.Time.Hour, Server.Time.Minute, Server.Time.Second);
            }
            else if (args.Reason == PositionCloseReason.Closed)
            {
                Print("PID: [ {0} ] Exit Trade {1}   ||   Gain/Loss {2}Pips / $ {3}   ||   Spread:{4}   ||   {5} {6}:{7}:{8}", LastResult.Position.Id, SymbolName, LastResult.Position.Pips, LastResult.Position.NetProfit, SPREAD, Server.Time.DayOfWeek, Server.Time.Hour, Server.Time.Minute, Server.Time.Second);
            }
            else if (args.Reason == PositionCloseReason.StopOut)
            {
                Print("PID: [ {0} ] StopOut {1}   ||   Gain/Loss {2}Pips / $ {3}   ||   Spread:{4}   ||   {5} {6}:{7}:{8}", LastResult.Position.Id, SymbolName, LastResult.Position.Pips, LastResult.Position.NetProfit, SPREAD, Server.Time.DayOfWeek, Server.Time.Hour, Server.Time.Minute, Server.Time.Second);
            }
        }

Replace the above handler with yours, run your cBot, and you will that it prints "LastResult.Position is null" on logs.

To avoid such issues I strongly recommend you to learn C# basics before developing a cBot/Indicator.


@amusleh

amusleh
21 Mar 2022, 08:34

Hi,

Please post a job request or contact one of the consultant companies.


@amusleh

amusleh
18 Mar 2022, 09:44

RE: RE:

firemyst said:

Great. You have the code and screen capture above.

 

Broker is Pepperstone.

Renko chart is Re5.

Chart is NAS100. Date/time on the screen capture. But just in case, time in UTC + 8 is Mar 17th from 04:43 - 04:54

 

Thank you.

Hi,

We were able to reproduce the issue, it's a bug and we will fix it.

Thanks for reporting.


@amusleh

amusleh
18 Mar 2022, 08:30

Hi,

The bar index should work fine, if it's not then it's a bug.

Can you tell me which broker you are using? which Renko chart? I will try to reproduce it.


@amusleh

amusleh
17 Mar 2022, 10:16

Hi,

There is no such field available right now on cTrader FIX API, and we don't have any plane to add it.

I recommend you to open a thread under suggestions section, or use Open API.


@amusleh

amusleh
17 Mar 2022, 10:14

Hi,

You can use Chart events for than, please check: cAlgo API Reference - Chart Interface (ctrader.com)


@amusleh

amusleh
16 Mar 2022, 12:14

RE: RE: Cannot access FIX API Password to test the FIX API using the Python example

Groenewald.a.m said:

I found the issue. Two things - the cTrade website did accept my password change request - but the confirmation dialog was internittent and the dialog did not show that anything was set - My suggestion would be to make it explicit in the dialog, for example: "Password: Set / Not set for acc.

3463567

 

 

Secondly, The demo's work fine. however the first instruction to be sent should be:

Command (ex: Help): LogonRequest ResetSeqNum=Y

Sent:  8=FIX.4.4|9=126|35=A|49=demo.ctrader.3463567|56=CSERVER|57=QUOTE|50=QUOTE|34=1|52=20220316-09:31:34|98=0|108=30|141=Y|553=3463567|554=testing|10=148|

Received:  8=FIX.4.4|9=106|35=A|34=1|49=CSERVER|50=QUOTE|52=20220316-09:31:34.706|56=demo.ctrader.3463567|57=QUOTE|98=0|108=30|141=Y|10=054|

 

After that other commands worked.

 

Finally, the console app after a short while breaks with the following message :

 

Command (ex: Help): Unhandled Error
Traceback (most recent call last):
  File "/Users/Michael/IdeaProjects/cTraderFixPy-main/samples/ConsoleSample/main.py", line 125, in <module>
    reactor.run()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/twisted/internet/base.py", line 1318, in run
    self.mainLoop()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/twisted/internet/base.py", line 1328, in mainLoop
    reactorBaseSelf.runUntilCurrent()
--- <exception caught here> ---
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/twisted/internet/base.py", line 994, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "/Users/Michael/IdeaProjects/cTraderFixPy-main/samples/ConsoleSample/main.py", line 80, in executeUserCommand
    userInput = inputimeout("Command (ex: Help): ", timeout=30)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/inputimeout/inputimeout.py", line 32, in posix_inputimeout
    termios.tcflush(sys.stdin, termios.TCIFLUSH)
termios.error: (25, 'Inappropriate ioctl for device')

 

Hi,

The issue is with inputimeout package that is used by console sample, it allows using a single thread to get command and keep the FIX connection alive.

Maybe inputimeout is not compatible with Mac, it works fine on Windows and Ubuntu.

You can try the web sample or Jupyter sample.


@amusleh

amusleh
16 Mar 2022, 11:19

RE: RE: RE:

neilbarrett10 said:

neilbarrett10 said:

amusleh said:

Hi,

What do you mean by executing market order and buy £10 per point?

For profit/loss calculation you can use symbol Pip/Tick value.

A symbol tick/Pip value gives you one tick/Pip of symbol monetary value in account currency.

If you want to set a £50 stop loss and your account currency is GBP then you can divide 50 to symbol pip value and use the result as stop loss in Pips.

So what he actually wants is to do spread betting, which he currently does in interactive brokers and when he makes a trade he purchases £10 per point, and the interactive broker software allows him to do this. 

So it looks like spread betting is a type of account:- Hedged, Netted or spread_betting. So i believe i can open a spread_betting type of account, using the appropriate broker, but i am still not sure how to place a bet via cTrader Automate, which should be by specifying how much i would like to bet - £10 per point for example. 

Hi,

It doesn't matter what type of account you are using.

You just have to calculate how much volume you should buy/sell to earn 10 GBP for each Pip/Tick.

For that you can use Symbol Pip/Tick value properties.


@amusleh

amusleh
16 Mar 2022, 08:42 ( Updated at: 16 Mar 2022, 08:43 )

Hi,

If ETHUSD current price is 2537 and you want to open a buy position with a stop loss at 2500 you will do it like this:

stopLossInRelative = Round(2537 - 2500, symbol.Digits) * 100000

These methods might help you understand how different units works on Open API:

public static double GetTickSize(this ProtoOASymbol symbol) => 1 / Math.Pow(10, symbol.Digits);

public static double GetPipSize(this ProtoOASymbol symbol) => 1 / Math.Pow(10, symbol.PipPosition);

public static long GetRelativeFromPips(this ProtoOASymbol symbol, double pips)
{
    var pipsInPrice = pips * symbol.GetPipSize();
    return (long)Math.Round(pipsInPrice * 100000, symbol.Digits);
}

public static double GetPriceFromRelative(this ProtoOASymbol symbol, long relative) => Math.Round(relative / 100000.0, symbol.Digits);

public static double GetPipsFromRelative(this ProtoOASymbol symbol, long relative) => Math.Round((relative / 100000.0) / symbol.GetPipSize(), symbol.Digits - symbol.PipPosition);

public static double GetPipsFromPoints(this ProtoOASymbol symbol, long points) => symbol.GetPipsFromPrice(points * symbol.GetTickSize());

public static long GetPointsFromPips(this ProtoOASymbol symbol, double pips) => System.Convert.ToInt64(pips * Math.Pow(10, symbol.Digits - symbol.PipPosition));

public static double GetPipsFromPrice(this ProtoOASymbol symbol, double price) => Math.Round(price * Math.Pow(10, symbol.PipPosition), symbol.Digits - symbol.PipPosition);

Points are used for setting slippage on Market range and stop limit orders.

If you got the precision error then it means something is wrong with decimal places and rounding.


@amusleh

amusleh
15 Mar 2022, 10:50

Hi,

You can use Symbols.GetSymbol method and then you can use the returned Symbol instance PipSize, ex: cAlgo API Reference - Symbols Interface (ctrader.com)


@amusleh

amusleh
15 Mar 2022, 10:41 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

BJORNBERNAU said:

amusleh said:

Hi,

The code post button:

Regarding OnBar issue, it depends on your indicator code, OnBar is called whenever a new bar opens, and access LastValue of your indicator means that you are trying to get the indicator output for newly created bar, which most probably will be NAN.

Test your indicator on cTrader Visual back test mode, you will see that your indicator only works properly for historical bars, not for newly created bars.

 

Okay, so how can I access historical data with the onBar method in cBot? 

Hi,

You can use any value of your indicator outputs inside OnBar, if you want to use historical values just pass the index of value to output Last method or with [].

The issue is not the cBot or OnBar, the issue is your indicator, fix your indicator first and then use it on a cBot.


@amusleh

amusleh
15 Mar 2022, 09:46

Hi,

The code post button:

Regarding OnBar issue, it depends on your indicator code, OnBar is called whenever a new bar opens, and access LastValue of your indicator means that you are trying to get the indicator output for newly created bar, which most probably will be NAN.

Test your indicator on cTrader Visual back test mode, you will see that your indicator only works properly for historical bars, not for newly created bars.


@amusleh

amusleh
15 Mar 2022, 09:26

Hi,

First of all there is a button on editor for posting code, please use it next time!

Your indicator is not consistent with it's output, if you give the same data twice it will return different outputs each time.

You are using OnBar method of cBot, and you are using Last value of indicator outputs, which are not complete and it will always return NAN inside OnBar.

Here are some recommendation for you:

  • If you have time and interest to continue writing C# code, then stop developing cBots/Indicators and instead put some time to learn C# and .NET basics, there are a ton of materials available for free on internet that you can use
  • In case you don't have time or the interest, you can contact one of our consultant companies or post a job request
  • Start small, if you copy some piece of code from one place and another from another place and put it inside a cTrader indicator it will not work
  • When asking help or support, be specific, you can't post 100s of lines of code and ask us to find the issue for you

 


@amusleh