Delay Timer Pause after opening a position before opening new position

Created at 29 Sep 2016, 17:38
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!
HA

harry

Joined 18.08.2016

Delay Timer Pause after opening a position before opening new position
29 Sep 2016, 17:38


/forum/cbot-support/399

I tried to use the code I found from above link to delay.pause timer, I want the bot to pause for 5mins after opening a position.

Here's the code I tried

             if (rsi.Result.LastValue < 25)
            {
                Close(TradeType.Sell);
                // Position was opened more than 300 seconds ago
                foreach (var position in Positions.FindAll("SampleRSI", Symbol, TradeType.Buy))
                {
                    if (position.EntryTime < DateTime.Now.AddSeconds(-300) || position == null)
                        Open(TradeType.Buy);
                }
            }

 

I try to pause the robot so not to open multiple positions at once, need to pause for 5 mins before opening if the rsi is still < 25 after 5 mins.

 

The above code have not opened any position even I added position == null, supposedlly at least 1 position is open

 

Thanks in Advance L!


@harry
Replies

... Deleted by UFO ...

harry
29 Sep 2016, 19:40

RE:

lucian said:

Use  Server.Time.AddSeconds(-300) or  Time.AddSeconds(-300)

DateTime.Now is the  Windows Time.

cBot works on  Robot(TimeZone = TimeZones.UTC)

 

Thanks L!

Am still confused why hasn't it opened any position despite I put OR position == null.

Well am running it again and see if it would open any position, am moving the position == null in front of the Time now.

   if (position == null || position.EntryTime < Time.AddSeconds(-300))

 


@harry

rmssf
29 Sep 2016, 20:01

RE: RE:

With no open positions your cbot never reaches that part of the code.

"foreach" really has the literal meaning "for each of open positions", so without open positions, the code inside is skipped.

 

harry said:

lucian said:

Use  Server.Time.AddSeconds(-300) or  Time.AddSeconds(-300)

DateTime.Now is the  Windows Time.

cBot works on  Robot(TimeZone = TimeZones.UTC)

 

Thanks L!

Am still confused why hasn't it opened any position despite I put OR position == null.

Well am running it again and see if it would open any position, am moving the position == null in front of the Time now.

   if (position == null || position.EntryTime < Time.AddSeconds(-300))

 

 


@rmssf

... Deleted by UFO ...

harry
30 Sep 2016, 03:00

RE: RE: RE:

Thanks rmssf, now i know why it never open any position

rmssf said:

With no open positions your cbot never reaches that part of the code.

"foreach" really has the literal meaning "for each of open positions", so without open positions, the code inside is skipped.

 

harry said:

lucian said:

Use  Server.Time.AddSeconds(-300) or  Time.AddSeconds(-300)

DateTime.Now is the  Windows Time.

cBot works on  Robot(TimeZone = TimeZones.UTC)

 

Thanks L!

Am still confused why hasn't it opened any position despite I put OR position == null.

Well am running it again and see if it would open any position, am moving the position == null in front of the Time now.

   if (position == null || position.EntryTime < Time.AddSeconds(-300))

 

 

 


@harry

harry
30 Sep 2016, 03:01

RE:

 

much appreciated L!

lucian said:

Try this:

 

 

   var pos = Positions.FindAll("SampleRSI", Symbol, TradeType.Buy);
            foreach (var position in pos)
            {
                if (position.EntryTime < DateTime.Now.AddSeconds(-300))
                {
                    Open(TradeType.Buy);
                }
            }
            if (pos.Length == 0)
                Open(TradeType.Buy);

 

 


@harry