It is non crossed but it consider as crossed

Created at 08 Mar 2019, 20:35
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!
nh.zadeh's avatar

nh.zadeh

Joined 11.03.2018

It is non crossed but it consider as crossed
08 Mar 2019, 20:35


My code is as below:

if (longPosition.Count() == 1)
            {
                if (SMAShort.Result.HasCrossedBelow(SMAMedium.Result, 1))
                {
                    int newvol = System.Convert.ToInt32(Symbol.NormalizeVolumeInUnits(Symbol.QuantityToVolumeInUnits(lot * (1 - (TP1Percent + TP2Percent) / 100)), RoundingMode.Down));
                    ClosePosition(Positions.Find("Nasser Reverse" + Symbol.Code));
                    BuyTP1Flag = false;
                    if (shortPosition.Count() == 0 && SMAShort.Result.HasCrossedBelow(SMAMedium.Result, 1) || SMAShort.Result.HasCrossedBelow(SMALong.Result, 1))
                    {
                        //                    lot = VolumeCal(StopLoss);
                        if (!(SMAMedium.Result.Last(1) < SMALong.Result.Last(1)))
                            lotlot = Math.Round(0.5 * lot, 2);
                        ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.NormalizeVolumeInUnits(Symbol.QuantityToVolumeInUnits(lotlot), RoundingMode.Down), "Nasser Reverse" + Symbol.Code, StopLoss, null, 0.5);
                        Print(SMAShort.Result.Last(1), "    ", SMAMedium.Result.Last(1));
                    }
                    BuyTP1Flag = false;
                }
            }

 

Actually based on printed information SMAShort did not have any cross with SMAMedium, but it returns true as confimed cross. please advise

first value is SMAShort(1) and second value is belong to SMAMedium(1),as you see there is no cross, but cbot closed the position


@nh.zadeh
Replies

PanagiotisCharalampous
12 Mar 2019, 14:30

Hi Nasser, 

The information is not enough for somebody to help you. Please provide us with the following

1) The complete cBot code.

2) The parameters you use to run the code.

3) The parameters you use for the displayed indicators.

Best Regards,

Panagiotis


@PanagiotisCharalampous

nh.zadeh
12 Mar 2019, 17:32

RE:

Panagiotis Charalampous said:

Hi Nasser, 

The information is not enough for somebody to help you. Please provide us with the following

1) The complete cBot code.

2) The parameters you use to run the code.

3) The parameters you use for the displayed indicators.

Best Regards,

Panagiotis

Dear Panagiotis

 

Thanks for your reply, I solved the problem with using normal coding such as 2 previous SMA value to compare with previous vaule rather than using HasCrossedBelow. It seems that HasCrossedBelow has some bug, Please ask your technical department to check that is it return the right values or not.

 

Thanks for your support.

 

Best regards

Nasser


@nh.zadeh

PanagiotisCharalampous
12 Mar 2019, 17:38

Hi Nasser,

Can you please provide a small code example demonstrating that this function does not work properly? Maybe you are not using it correctly.

Best Regards,

Panagiotis


@PanagiotisCharalampous