How to control the number of order when use ExecuteMarketOrder funtion

Created at 17 Dec 2018, 16:05
MI

MinMin

Joined 23.07.2018

How to control the number of order when use ExecuteMarketOrder funtion
17 Dec 2018, 16:05


Hi team,

I coded like that:

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;


namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleTrendcBot : Robot
    {

[Parameter("Quantity (Lots)", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

 [Parameter("targetprice", DefaultValue = 40)]
        public double targetprice { get; set; }

protected override void OnTick()
        {
            
if ( Symbol.Ask == targetprice + 0.02 && Positions.Find(label, Symbol, TradeType.Buy == null)
            {

                ExecuteOrder(Quantity, TradeType.Sell);

                return;
            }
......

I don't meet any problem when I backtest. It's always create orders like i want. But when I run with real data, there are problem happened: sometimes the orders are created double, although i had setup condition" Positions.Find(label, Symbol, TradeType.Buy == null" but there are two orders had created in the same time. here is log show:

17/12/2018 20:28:19.117 | test2 (2), USDJPY, h1 | Executing Market Order to Buy 2000 USDJPY
17/12/2018 20:28:19.117 | test2 (2), USDJPY, h1 | Executing Market Order to Buy 2000 USDJPY
17/12/2018 20:28:19.648 | test2 (2), USDJPY, h1 | → Executing Market Order to Buy 2000 USDJPY SUCCEEDED, Position PID52429489
17/12/2018 20:28:19.898 | test2 (2), USDJPY, h1 | → Executing Market Order to Buy 2000 USDJPY SUCCEEDED, Position PID52429490

Could you help me with this problem? It's really big prolem.

Thanks and best regards,

 


@MinMin
Replies

PanagiotisCharalampous
17 Dec 2018, 16:18

Hi vancong140293,

Try changing your condition to the following

if (Symbol.Ask == targetprice + 0.02 && Positions.Find(label, Symbol, TradeType.Sell) == null)

Best Regards,

Panagiotis


@PanagiotisCharalampous

MinMin
17 Dec 2018, 16:25

RE:

Panagiotis Charalampous said:

Hi vancong140293,

Try changing your condition to the following

if (Symbol.Ask == targetprice + 0.02 && Positions.Find(label, Symbol, TradeType.Sell) == null)

Best Regards,

Panagiotis

Sorry I was missing ")"  when i copy . But I used the same code like you and the problem happend!


@MinMin

PanagiotisCharalampous
17 Dec 2018, 16:59

Hi vancong140293,

Can you post the full cBot code to check it?

Best Regards,

Panagiotis


@PanagiotisCharalampous