help

Created at 31 Aug 2020, 17:03
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!
LU

luca.tocchi

Joined 25.03.2020

help
31 Aug 2020, 17:03


hi this is my bot

when the 3 moving averages and the stochastic are all upwards it must go buy

when the 3 moving averages and the stochastic are all down it must go sell

the problem is that the while loop is not even seen. why?

the program goes buy if the 50 period moving average (Mv50) is up and sell if it is down

thanks

 

if (Mv50.Result.Last(1) > Mv50.Result.LastValue)
                            {
                                while (Mv10.Result.Last(1) < Mv10.Result.LastValue && Mv1.Result.Last(1) < Mv1.Result.LastValue && St.PercentD.LastValue < St.PercentK.LastValue)
                                {
                                    Print("Waiting for trigger");
                                    System.Threading.Thread.Sleep(10000);
                                }
                                ExecuteOrder(position.Quantity * 2, TradeType.Sell);
                            }
                            else
                            {
                                while (Mv10.Result.Last(1) > Mv10.Result.LastValue &&  Mv1.Result.Last(1) > Mv1.Result.LastValue && St.PercentD.LastValue > St.PercentK.LastValue)
                                {
                                    Print("Waiting for trigger");
                                    System.Threading.Thread.Sleep(10000);
                                }
                                ExecuteOrder(position.Quantity * 2, TradeType.Buy);
                            }


@luca.tocchi
Replies

PanagiotisCharalampous
31 Aug 2020, 17:08

Hi Luca,

This will never trigger because you have programmed an infinite while loop. There is no way for the condition to become true.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

luca.tocchi
31 Aug 2020, 18:06

RE:

PanagiotisCharalampous said:

Hi Luca,

This will never trigger because you have programmed an infinite while loop. There is no way for the condition to become true.

Best Regards,

Panagiotis 

Join us on Telegram

 

what should i correct?

I thought that if the condition is true he waits, if it is false he exits the cycle


@luca.tocchi

PanagiotisCharalampous
01 Sep 2020, 07:58

Hi Luca,

You need to rewrite the code from scratch. This one does not make any sense. How will the condition be updated if it the code does not exit the loop?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous