Does Bars.ClosePrices give me the actual close price of a bar ?

Created at 20 Feb 2024, 10:37
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!
MI

mihlali700

Joined 22.12.2023

Does Bars.ClosePrices give me the actual close price of a bar ?
20 Feb 2024, 10:37


I am not understanding what sort of info I get from Bars.OpenPrices/Bars.ClosePrices. I have coded this logic so that it looks for a certain pattern and the logic isn't doing what I want it to do. 

 private bool IsBullishPullBack() {

        

        double AClose4 = Bars.ClosePrices.Last(4);

        

        double AClose3 = Bars.ClosePrices.Last(3);

        double ALow3 = Bars.LowPrices.Last(3);

        double AOpen3 = Bars.OpenPrices.Last(3);

        

        double AOpen2 = Bars.OpenPrices.Last(2);

        double AClose2 = Bars.ClosePrices.Last(2);

        

        double AOpen1 = Bars.OpenPrices.Last(1);

 

         if ( 

               (AClose3 <  AClose4)  &&  

               (AClose3 < AOpen2  && AOpen2 > ALow3 && AClose2 >= AOpen3 )  && 

               AOpen1 >= AOpen2 

         )

         

         {

           

           return false;

         

         }

         

         return true;

       

       }


Here is an example pic from the backtest : 

You can see here although in the code the close of bar 2 should be greater than or equal to the open of bar 3 but in this pic its tell yet the Bot still took the trade .

In case you wondering what the rest code is like : 
 // parent method to check rules and open bullish trade or send signal.
        private void TradeRulesBullish()
        {
            // flag to open a trade if all rules true.
            bool OpenBuyTrade = false;

            if (IsBullishSignal() && !IsBullishPullBack() )
            {
                OpenBuyTrade = true;
            }
 
            if (OpenBuyTrade)
            {
                if (!IsBullish)
                {
                    if (!IsTradeOpen(TradeType.Buy))
                    {
                    
                        double AClose3 = Bars.ClosePrices.Last(3);
                        double StopLoss1 = AClose3;
                        double takeprofits = TakeProfit;
                        
                        OpenTrade(TradeType.Buy,StopLoss1,takeprofits);
                    }
                }

                IsBullish = true;
            }
            else
            {
                IsBullish = false;
            }
        }

 


@mihlali700
Replies

firemyst
22 Feb 2024, 02:24 ( Updated at: 22 Feb 2024, 07:46 )

Duplicate. Original one is here:

https://ctrader.com/forum/cbot-support/42928

 


@firemyst