Can this code be fixed?

Created at 22 Feb 2017, 07:38
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!
DE

derekszyszka

Joined 15.10.2016

Can this code be fixed?
22 Feb 2017, 07:38


This is a absolute static TP and SL bot I use inconjuction with my SMA breakout bot. 

Randomly, this bot will add two zeros (00) to each my TP and SL levels for no reason. Example: for a 10sl and 8tp it would randomly change it to 1000 sl and 800 tp.


// -------------------------------------------------------------------------------
//
//    This is a Sample used as a guideline to build your own Robot. 
//    Please use the forum to provide us with your suggestions about cAlgo’s API.
//
// -------------------------------------------------------------------------------

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot()]
    public class ModifyAccountPositions : Robot
    {
        protected override void OnTick()
        {
            foreach (var position in Positions)
            {
                if (position.StopLoss == null)
                {
                    Print("Modifying {0}", position.Id);
                    ModifyPosition(position, GetAbsoluteStopLoss(position, 10), GetAbsoluteTakeProfit(position, 8));
                }
            }
        }

        private double GetAbsoluteStopLoss(Position position, int stopLossInPips)
        {
            return position.TradeType == TradeType.Buy ? position.EntryPrice - Symbol.PipSize * stopLossInPips : position.EntryPrice + Symbol.PipSize * stopLossInPips;
        }

        private double GetAbsoluteTakeProfit(Position position, int takeProfitInPips)
        {
            return position.TradeType == TradeType.Buy ? position.EntryPrice + Symbol.PipSize * takeProfitInPips : position.EntryPrice - Symbol.PipSize * takeProfitInPips;
        }
    }
}

 


@derekszyszka
Replies

cTKit
22 Feb 2017, 10:05

Not sure we have enough information to help you.

What currency pairs is this happening on, different ones, the same ones?

The code is pretty straight forward and I use something similar a lot without this problem.


@cTKit

derekszyszka
22 Feb 2017, 16:32

RE:

testpossessed said:

Not sure we have enough information to help you.

What currency pairs is this happening on, different ones, the same ones?

The code is pretty straight forward and I use something similar a lot without this problem.

All currency pairs, could be the gbpusd, usdjpy, audusd, it is comepletely random. Are you willing to share your SL/TP bot you use so I can compare the script?


@derekszyszka

Jiri
23 Feb 2017, 01:19

Hi, the Positions collection is global (across all symbols) while Symbol.PipSize is local (of the symbol you have attached cbot to). Aren't you modifying positions on different symbols than you have attached cbot to?


@Jiri