Possible bug in ExecuteMarketOrder with StopTriggerMethod

Created at 04 Sep 2020, 11:52
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!
AN

andi21

Joined 14.12.2016

Possible bug in ExecuteMarketOrder with StopTriggerMethod
04 Sep 2020, 11:52


Hello Spotware-Team,

in my opinion this is a bug - please see following points to reproduce:

- select Asset "XAUUSD" (large spread, so perfect to test)

- execute the bot below with parameter 2.0 -> sl is set about spread * 2 away from BID -> correct

- execute the bot below with parameter 0.5 -> sl SHOULD be set about spread * 0.5 away from BID -> but that is not the case. The position is executed, but without the sl, so NO sl set. Probably that is the case, because the ExecuteMarketOrder checks sl-price is <= ASK in sell-position and denys the sl. But with a StopTriggerMethod Opposite it should not check against <= ASK, but <= BID.

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Entry_Demo_Bot : Robot
    {    
        [Parameter(DefaultValue = 0.5d)]
        public double Spread_Factor { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
            double spread = (Symbol.Spread * Spread_Factor);            
            double pips_From_Entry_Price = spread != 0.0d ? spread / Symbol.PipSize : spread; 
            
            ExecuteMarketOrder(
                TradeType.Sell, 
                SymbolName, 
                Symbol.VolumeInUnitsMin, 
                null, 
                Math.Floor(pips_From_Entry_Price), 
                null,
                null,
                false, 
                StopTriggerMethod.Opposite);
            
            Stop();
        }
        
        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Thank you in advance for your help.

And if you agree with me that this is a bug, please give me a notice when it can be expected to be fixed and released, so that i can change my source code accordingly, so that it can allow these currently "bug"-situations.

Best Regards,

andi21


@andi21
Replies

PanagiotisCharalampous
04 Sep 2020, 12:27

Hi andi21,

This is not a bug, it works by design. SL is set on the requested distance from the position's entry price. StopTriggerMethod affects only the trigger method, not the SL price level.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

andi21
04 Sep 2020, 12:49

RE:

PanagiotisCharalampous said:

Hi andi21,

This is not a bug, it works by design. SL is set on the requested distance from the position's entry price. StopTriggerMethod affects only the trigger method, not the SL price level.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis,

yes, i am aware of that.

But the key point is (in the example above with the sell position and triggermethod opposite), that the sl is discarded by the ExecuteMarketOrder-Method, although it should accept it, because the requested sl is though BELOW Ask, but ABOVE Bid and triggering is done by Bid with triggermethod opposite in sell positions.

Best Regards,

andi21 


@andi21