pause loop for 3 candles

Created at 12 Feb 2021, 15:47
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!
MA

marian.kosa

Joined 12.02.2021

pause loop for 3 candles
12 Feb 2021, 15:47


Hi.

I have IF loop in my code with market order in the end of it. 
After market order, i want this loop to be inactive for 3 candles for example, but rest of the code running normally. That way i will not get multiple entries in short time span.

Is there some kind of wait/sleep function? And where to write it?

if (*logic*)
                    {
                        ExecuteMarketOrder(TradeType.Buy, SymbolName, volume, "bot", SL, TP, "buy");
                        // Time.sleep(3)
                    }


@marian.kosa
Replies

JerryTrader
15 Feb 2021, 15:37

I don't know your level of programming skills, but a pretty basic way of doing it without knowing anything about the cBot API would be to:

  1. Create a field or property in your class
  2. When you execute the market order, store the bar index in the field/property
  3. Add a condition to check if the current bar index is greater than your field/property + 3

 

I think the best way to perform what you are looking for is to override the OnTimer method to set a flag like CanExecuteMarketOrder and stop the timer.
As soon as you execute a market order, you reset the flag and start the timer with Timer.Start() with the timespan you wanna wait before setting the CanExecuteMarketOrder flag.


@JerryTrader

marian.kosa
15 Feb 2021, 15:42

RE:

"pretty basic" is good estimate of my programming skills. :)

Thanks for respond. I was not sure where to look. I should be able figure it out now.



JerryTrader said:

I don't know your level of programming skills, but a pretty basic way of doing it without knowing anything about the cBot API would be to:

  1. Create a field or property in your class
  2. When you execute the market order, store the bar index in the field/property
  3. Add a condition to check if the current bar index is greater than your field/property + 3

 

I think the best way to perform what you are looking for is to override the OnTimer method to set a flag like CanExecuteMarketOrder and stop the timer.
As soon as you execute a market order, you reset the flag and start the timer with Timer.Start() with the timespan you wanna wait before setting the CanExecuteMarketOrder flag.

 


@marian.kosa