How to correctly use HasCrossedBelow
            
                 24 Jul 2018, 12:46
            
                    
Dear Panagiotis.
I am using this code
"
  if (position.TradeType == TradeType.Buy && MarketSeries.Low.Last(1) < bb.Main.Last(1))// )
                    {
                        if (bb.Main.HasCrossedBelow(TMA.Result, 1) )
                        {
                            ClosePosition(position);
                        }
                    }
"
Replies
                     PanagiotisCharalampous
                     24 Jul 2018, 12:54
                                    
Hi Sasha,
I don't see an issue with the posted code. Could the problem be in another part? Maybe this part of the code is never reached to close the position.
Best Regards,
Panagiotis
@PanagiotisCharalampous
                     alexander.n.fedorov
                     24 Jul 2018, 13:01
                                            ( Updated at: 21 Dec 2023, 09:20 )
                                    
Never mind backslashes, they in a picture by mistake
But in the other case it woks just fine
                foreach (var position in positions)
                {
                    if (position.TradeType == TradeType.Buy && MarketSeries.Low.Last(1) < bb.Main.Last(1))
                    {
                        if (bb.Main.HasCrossedBelow(TMA.Result, 1) )
                        {
                            ClosePosition(position);
                        }
                    }
                    if (position.TradeType == TradeType.Sell && MarketSeries.High.Last(1) > bb.Main.Last(1))
                    {
                        if (bb.Main.HasCrossedAbove(TMA.Result, 1) )
                        {
                            ClosePosition(position);
                        }
                    }
                }
@alexander.n.fedorov

alexander.n.fedorov
24 Jul 2018, 12:48
But as you can see on the picture the blue line is crossing the TMA (triangular ma) and nothing happens.
Maybe the syntax is not right?
Regards,
Sasha
@alexander.n.fedorov