PDA

View Full Version : How to start a strategy from now


stevebong
02-16-2010, 11:53 PM
Hi,

Could someone please tell me how to start a strategy starting from current bar?

I've been trying to do this using below code but I am thinking there is a better way to do this. The problem with below is that if the strategy lasts more than a day then the strategy stops running unless the startTime is 100 (1min after midnight).

if (ToDay(Time[0]) >= tradingDate && ToTime(Time[0]) >= startTime)
{
do something
}

Any help is appreciated.

Thanks,

NinjaTrader_Tim
02-17-2010, 06:18 AM
Hi stevebong,

Thank you for your post.

If you write

if (Historical)
{
return;
}

as the first line after OnBarUpdate(), the strategy will not execute on historical bars.

vegasfoster
02-18-2010, 09:21 PM
Hi, I am trying to do the same thing but I am getting multiple errors, not sure what I am doing wrong. Thanks.

NinjaTrader_Bertrand
02-19-2010, 04:39 AM
vegasfoster, you need to include this in the OnBarUpdate() and pay attention to correct bracing -


protected override void OnBarUpdate()
{

if (Historical) return;

}

vegasfoster
02-20-2010, 05:01 PM
Thanks for replying. The problem was that I added it exactly as you described, as follows:


"protected override void OnBarUpdate()

{

if (Historical) return;

}

{
// Condition set 1
if (High[1] > MovingHL(100, 24).MovingHigh[2]
&& Close[0] == Low[1])
{....}"

Having two sets of the outer squiggly brackets was fouling it up. When I changed it to the following it worked:

"protected override void OnBarUpdate()

{

if (Historical) return;

// Condition set 1
if (High[1] > MovingHL(100, 24).MovingHigh[2]
&& Close[0] == Low[1])
{....}"

It's just taking me a while to learn these things, e.g. 20 <> 20.0, PointValue <> pointvalue, etc. I will get there.