Cbot problem on JPY symbol

Created at 27 Jun 2018, 16:44
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!
12

1222Ht

Joined 11.11.2017

Cbot problem on JPY symbol
27 Jun 2018, 16:44


Hi ,  Thank you for reading my question .

I have made a cbot that changes my pending order's target price , stop loss and take profit. 

It is :

     PendingOrders.Created += OnPendingOrdersCreated;

     void OnPendingOrdersCreated(PendingOrderCreatedEventArgs obj)
        {

                 ModifyPendingOrder(obj.PendingOrder,Pending_Order_Entry_Price, Stop_Loss / Symbol.PipSize, Take_Profit/ Symbol.PipSize, Server.Time.AddMinutes(50), Trade_Size);

}

it works fine with EURUSD GBP AUD etc. however, when i use it on any JPY symbol . it doesnt work and cbot stops ...

I have noticed that JPY is slightly different in price. can i change anything to make this work .

Many Thanks ,

Henry

 

 

 

 


@1222Ht
Replies

PanagiotisCharalampous
27 Jun 2018, 16:50

Hi 1222Ht,

We would be able to help you if you posted the complete source code of the cBot, so that we can reproduce the issue. Also, can you check the log to see if you receive a message. Maybe this will clarify the reason that the cBot stops.

Best Regards,

Panagiotis


@PanagiotisCharalampous

1222Ht
27 Jun 2018, 16:56

Hi Panagiotis, Thank you for your reply .

it is just very simple code that changes target price to marketseries.high.maximum(2) , ie for buy pending order and it only has problem with JPY. 

27/06/2018 13:52:55.966 | cBot "Stop Loss Take Profit " was started successfully for USDJPY, m3.
27/06/2018 13:52:58.919 | Modifying pending order OID72458495 (Volume: 1000, Price: 110.392, SL: 4.40000000000111, TP: 9.94360319840695, ExpireTime: 27/06/2018 14:42:58)
27/06/2018 13:52:59.310 | → Modifying pending order OID72458495 (Volume: 1000, Price: 110.392, SL: 4.40000000000111, TP: 9.94360319840695, ExpireTime: 27/06/2018 14:42:58) FAILED with error "TechnicalError", PendingOrder OID72458495
27/06/2018 13:52:59.310 | Crashed in PendingOrders.Created with InvalidOperationException: Nullable object must have a value.
27/06/2018 13:52:59.325 | cBot "Stop Loss Take Profit " was stopped for USDJPY, m3.

Thank you very much 

 


@1222Ht

PanagiotisCharalampous
27 Jun 2018, 17:07

Ηι 1222Ht,

Without the source code I can only make assumptions. Based on the log, I would suggest to round SL and TP to the decimals allowed by the symbol.

Best Regards,

Panagiotis


@PanagiotisCharalampous

1222Ht
27 Jun 2018, 19:03

Hi Panagiotis, Thank you for your reply .

I tried Math.Round() it to 0 and 1 , it didnt crash but still not perform what i wanted on USDJPY, if I math.round() to 2 or above it stops again ..

Please see the source code , thank you for your time 

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 ProblemWithJPY : Robot
    {

        private double BarSize;

        private double Average(DataSeries Data)
        {
            double Sum = 0;

            for (int i = 0; i < Data.Count; i++)
                Sum += Data[i];

            return Sum / Data.Count;
        }

        private double Buy_Pending_Order_Entry_Price;
        private double Sell_Pending_Order_Entry_Price;

        protected override void OnStart()
        {
            BarSize = Average(MarketSeries.High) - Average(MarketSeries.Low);
            Buy_Pending_Order_Entry_Price = MarketSeries.High.Maximum(2) + Symbol.TickSize;
            Sell_Pending_Order_Entry_Price = MarketSeries.Low.Minimum(2) - Symbol.TickSize;

            PendingOrders.Created += OnPendingOrdersCreated;
        }

        protected override void OnTick()
        {
            Buy_Pending_Order_Entry_Price = MarketSeries.High.Maximum(2) + Symbol.TickSize;
            Sell_Pending_Order_Entry_Price = MarketSeries.Low.Minimum(2) - Symbol.TickSize;
        }

        void OnPendingOrdersCreated(PendingOrderCreatedEventArgs obj)
        {
            if (obj.PendingOrder.TradeType == TradeType.Buy && obj.PendingOrder.OrderType == PendingOrderType.Stop && obj.PendingOrder.SymbolCode == Symbol.Code)
                ModifyPendingOrder(obj.PendingOrder, Buy_Pending_Order_Entry_Price, Math.Abs(Buy_Pending_Order_Entry_Price - Sell_Pending_Order_Entry_Price) / Symbol.PipSize, BarSize * 3.5 / Symbol.PipSize, Server.Time.AddMinutes(50), Symbol.NormalizeVolumeInUnits(Account.Balance * 0.025 / Math.Abs(Buy_Pending_Order_Entry_Price - Sell_Pending_Order_Entry_Price)));

            if (obj.PendingOrder.TradeType == TradeType.Sell && obj.PendingOrder.OrderType == PendingOrderType.Stop && obj.PendingOrder.SymbolCode == Symbol.Code)
                ModifyPendingOrder(obj.PendingOrder, Sell_Pending_Order_Entry_Price, Math.Abs(Buy_Pending_Order_Entry_Price - Sell_Pending_Order_Entry_Price) / Symbol.PipSize, BarSize * 3.5 / Symbol.PipSize, Server.Time.AddMinutes(50), Symbol.NormalizeVolumeInUnits(Account.Balance * 0.025 / Math.Abs(Buy_Pending_Order_Entry_Price - Sell_Pending_Order_Entry_Price)));
        }
    }
}

 

Many Thanks,


@1222Ht

PanagiotisCharalampous
28 Jun 2018, 09:23

Hi 1222Ht,

Can you please clarify what you mean with "still not perform what i wanted"? What do you want the cBot to do and what does it do? Why do you need a SL and TP with 2 decimal places?

Best Regards,

Panagiotis


@PanagiotisCharalampous

1222Ht
28 Jun 2018, 12:30

Hi Panagiotis, Thank you for your reply .

i want the target price ie for buy pending order to move to a tick above current or last bars high .  

In JPY symbol when I round it to 2 or above , it crashes , when i round it to 0 / 1 it either is very far away or it goes to middle of current bar and fills .

This doesnt happen with other currency pairs .. Thank you for your time

Many Thanks


@1222Ht

1222Ht
02 Jul 2018, 05:54

Sorry i was confused and round target price too , now there is no problem thank you very much !


@1222Ht