skipping to next bar

Created at 09 Apr 2015, 03:53
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!
lec0456's avatar

lec0456

Joined 14.11.2012

skipping to next bar
09 Apr 2015, 03:53


if I am using the Ontick event.    is there any way I can skip the ticks until the next bar event occurs on a certain criteria?


@lec0456
Replies

GunArm
15 Apr 2015, 22:11

RE:

I also want to know this, something like

protected override void OnTick()
{
   if( ! FIRST_TICK_OF_NEW_BAR) return;

   // do the stuff you only want to do once on previous candle close here
}

    

 

I also opened a related thread /forum/cbot-support/4932


@GunArm

GunArm
15 Apr 2015, 22:38

RE:

I found there is an OnBar() method you can override, rather than using OnTick().

Since technically your question started with "if I am using OnTick", if OnTick is a requirement, you could probably set some kind of flag in the OnBar method, and then skip a section of your OnTick method until that flag is set.  Otherwise easier to just use OnBar in it's place.


@GunArm

lec0456
16 Apr 2015, 00:07

Yes, that is what I eventually did.

 

I set a global bool flag called nextbarto true  in the OnBar event.

 

In the OnTick event I check the flag and then set it to false.

 

This was probably a special case for me because I have an indicator to trade at specific times that is dependent on the time frame being used.

So if I set my algorithm to start trading at 8am if I completed a trade within one bar, the algo would start trading again.  The required behavior was for it to stop. Now it looks at the nextbar flag  if its in the middle of a candle and does not start trading.unless no successful trade is made, then it continues trading. 

 

 


@lec0456

yourne
05 Jul 2015, 18:33

hi there. recently i have been bothered by the same problem too. i want to dynamically modify the positions (trailing SL, asynchronously closing, etc) so basically the OnTick() method is my only option.  however i will open a position in the starting tick of current bar and if the price hits SL before the current bar is closed, i want the cbot not to open the same position again (cause the signal is still there anyway). what is your solution? very grateful for your help :) 


@yourne

yourne
05 Jul 2015, 18:47

Or can i use both OnBar() and OnTick? cause i have tried this way but the cbot went crashed. is this just not allowed in cAlgo or there was something wrong in my code which i did not realized then?if i can use the two method in one cbot, there is no need to waste a time. 


@yourne

Spotware
06 Jul 2015, 14:53

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware