Topics

Forum Topics not found

Replies

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

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 connect@spotware.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

amusleh
15 Mar 2022, 08:54

Hi,

Installing a new broker cTrader will not delete or replace your current indicators/cBots/templates.

All installed cTrader instances will use the same automate folder data.


@amusleh

amusleh
15 Mar 2022, 08:52

Hi,

This can be caused by symbol spread or something might be wrong with your code, can you post a sample cBot code that can reproduce this issue on visual back test?


@amusleh

amusleh
14 Mar 2022, 18:10

RE: RE:

undseth said:

amusleh said:

Hi,

The data series itself has a minimum method, so you can use is like this:

// This gives you the lowest price in last 20 bars lows
var lowestLow = Bars.LowPrices.Minimum(20)

 

 

Hi again,

This will get the lowest low from start index 1, but I need it to get the lowest low from eks start index 10, so it shuld

start at index 10 and get the lowest low in a periode of 20 bars. Hope this make sense??

 

Thanks for all the help!

Halvard

Then use the method I posted on my first post, you can set the start/end index and it will give you the low, ex:

// This will return the lowest low between bar index 90 and 100
var low = Minimum(Bars.LowPrices, 90, 100);

 


@amusleh