Information

Username: stefan_schwarz1
Member since: 11 Dec 2022
Last login: 05 Nov 2023
Status: Active

Activity

Where Created Comments
Algorithms 0 1
Forum Topics 1 0
Jobs 0 0

Last Algorithm Comments

ST
stefan_schwarz1 · 1 year ago

The Tral_Start and Tral_Stop is not working if you dont modify a stoplossprice in OnPositionOpend()

...    

private void OnPositionOpened(PositionOpenedEventArgs args)
        {
            double? StopLossPrice = null;
            double? TakeProfitPrice = null;

            if (Positions.Count == 1)
            {
                position = args.Position;

                if (position.TradeType == TradeType.Buy)
                    {
                    TakeProfitPrice = position.EntryPrice + TakeProfit * Symbol.TickSize;
                    StopLossPrice = position.EntryPrice - Stop_Loss * Symbol.TickSize;
                    }
                if (position.TradeType == TradeType.Sell)
                    {
                    TakeProfitPrice = position.EntryPrice - TakeProfit * Symbol.TickSize;
                    StopLossPrice = position.EntryPrice + Stop_Loss * Symbol.TickSize;
                    }
            }
            else
                switch (GetPositionsSide())
                {
                    case 0:
                        TakeProfitPrice = GetAveragePrice(TradeType.Buy) + TakeProfit * Symbol.TickSize;
                        StopLossPrice = GetAveragePrice(TradeType.Buy) - Stop_Loss * Symbol.TickSize;
                        break;
                    case 1:
                        TakeProfitPrice = GetAveragePrice(TradeType.Sell) - TakeProfit * Symbol.TickSize;
                        StopLossPrice = GetAveragePrice(TradeType.Sell) + Stop_Loss * Symbol.TickSize;
                        break;
                }

            for (int i = 0; i < Positions.Count; i++)
            {
                position = Positions[i];
                if (StopLossPrice != null || TakeProfitPrice != null)
                    ModifyPosition(position, StopLossPrice, TakeProfitPrice);
            }
        }

...