NexusFi: Find Your Edge


Home Menu

 





Code for hour minutes and seconds


Discussion in NinjaTrader

Updated
    1. trending_up 2,595 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 8 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
 
victorin's Avatar
 victorin 
Espaņa
 
Experience: Intermediate
Platform: ninjatrader
Trading: ES, 6E, GC, CL
Posts: 73 since Jun 2016
Thanks Given: 49
Thanks Received: 24

Hi I have a strategy that I want you to make me a purchase at a specific minute and second hour.

Could you tell me what the correct code to insert into NinjaScript? If you are now 13:25:45 sec and you make me want to purchase at 13:38:14 sec, what would be the correct code?

Thanks and regards.


Started this thread Reply With Quote

 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #2 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860

You can do it several ways

1. the most correct is with a on time event, that triggers exactly at that time

2. you can check on every incoming tick, if the time has arrived, the disadvantage
is in iliquid market, the order will be trigger after that time, after the first trade

regards,
Ron


Attached Files
Elite Membership required to download: ATimerWithCustomEventTest.zip
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
 
victorin's Avatar
 victorin 
Espaņa
 
Experience: Intermediate
Platform: ninjatrader
Trading: ES, 6E, GC, CL
Posts: 73 since Jun 2016
Thanks Given: 49
Thanks Received: 24



rleplae View Post
You can do it several ways

1. the most correct is with a on time event, that triggers exactly at that time

2. you can check on every incoming tick, if the time has arrived, the disadvantage
is in iliquid market, the order will be trigger after that time, after the first trade

regards,
Ron

Thanks Ron, for your help.
The truth is that the strategy makes you just need to run the second, for example at 12:21:17 sec

With the template you sent me I get no place think of it, could you tell me how it should be placed correctly with the data I have in my strategy? This is what I have.

protected override void Initialize()
{
MyTimeSpan = new TimeSpan(8, 0, 0);
CalculateOnBarClose = true;
SetStopLoss("", CalculationMode.Ticks, Stop, false);
SetProfitTarget("", CalculationMode.Ticks, Target);
//SetTrailStop("", CalculationMode.Ticks, Trail, false);
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(Time[0].TimeOfDay == MyTimeSpan)
{
EnterLongStop(Close[0] + 5 * TickSize);
}


Started this thread Reply With Quote
  #4 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860


victorin View Post
Thanks Ron, for your help.
The truth is that the strategy makes you just need to run the second, for example at 12:21:17 sec

With the template you sent me I get no place think of it, could you tell me how it should be placed correctly with the data I have in my strategy? This is what I have.

protected override void Initialize()
{
MyTimeSpan = new TimeSpan(8, 0, 0);
CalculateOnBarClose = true;
SetStopLoss("", CalculationMode.Ticks, Stop, false);
SetProfitTarget("", CalculationMode.Ticks, Target);
//SetTrailStop("", CalculationMode.Ticks, Trail, false);
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(Time[0].TimeOfDay == MyTimeSpan)
{
EnterLongStop(Close[0] + 5 * TickSize);
}

The problem with your code is that it will only check when a new bar is formed.
you are subscribing the even 'onBarUpdate'

You could alternatively also subscribe the onMarketUpdate, that means your
code would then be check for every change in the bid/ask or any trade, at that
moment, you simple check the current time and if necessary fired an order


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 
victorin's Avatar
 victorin 
Espaņa
 
Experience: Intermediate
Platform: ninjatrader
Trading: ES, 6E, GC, CL
Posts: 73 since Jun 2016
Thanks Given: 49
Thanks Received: 24


rleplae View Post
The problem with your code is that it will only check when a new bar is formed.
you are subscribing the even 'onBarUpdate'

You could alternatively also subscribe the onMarketUpdate, that means your
code would then be check for every change in the bid/ask or any trade, at that
moment, you simple check the current time and if necessary fired an order



// [Description("trailing stop")]
// [GridCategory("Parameters")]
// public int Trail
// {
// get { return trail; }
// set { trail = Math.Max(1, value); }
// }
#endregion
}
}


Started this thread Reply With Quote
  #6 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860

I think what you want to do is something like this :
(i didn't debug the code, sorry if typos)

 
Code
		protected override void OnMarketData (MarketDataEventArgs e)
		{

                        if (e.MarketDataType == MarketDataType.Last)
                       {
                          if (String.Compare(e.Time.ToString("HHmm"),"0800") >0)
                                EnterLongStop(e.Price + 5 * TickSize);
                        }
                 }


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
victorin's Avatar
 victorin 
Espaņa
 
Experience: Intermediate
Platform: ninjatrader
Trading: ES, 6E, GC, CL
Posts: 73 since Jun 2016
Thanks Given: 49
Thanks Received: 24


rleplae View Post
I think what you want to do is something like this :
(i didn't debug the code, sorry if typos)

 
Code
		protected override void OnMarketData (MarketDataEventArgs e)
		{

                        if (e.MarketDataType == MarketDataType.Last)
                       {
                          if (String.Compare(e.Time.ToString("HHmm"),"0800") >0)
                                EnterLongStop(e.Price + 5 * TickSize);
                        }
                 }

Ok thanks Ron,
but then My TimeSpan is the time I will introduce, where I have to tell the program if MyTimeSpan time = current time to do my operation?

Greetings.


----------------------------------------------------------------------------

protected override void Initialize()
{
MyTimeSpan = new TimeSpan(8, 0, 0);
CalculateOnBarClose = false;
SetStopLoss("", CalculationMode.Ticks, Stop, false);
SetProfitTarget("", CalculationMode.Ticks, Target);
//SetTrailStop("", CalculationMode.Ticks, Trail, false);
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(Time[0].TimeOfDay == MyTimeSpan)
{
EnterLongStop(Close[0] + 5 * TickSize);
}


Started this thread Reply With Quote
  #8 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860

It is possible to check for a time (like 15 min before and after oil report on Wednesday)
Or you can check for duration since entry of the trade (too slow trade kill it

Both logic you can see in a BOT that i have published in the past for educational purposes:


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #9 (permalink)
 
victorin's Avatar
 victorin 
Espaņa
 
Experience: Intermediate
Platform: ninjatrader
Trading: ES, 6E, GC, CL
Posts: 73 since Jun 2016
Thanks Given: 49
Thanks Received: 24


rleplae View Post
It is possible to check for a time (like 15 min before and after oil report on Wednesday)
Or you can check for duration since entry of the trade (too slow trade kill it

Both logic you can see in a BOT that i have published in the past for educational purposes:



Sorry I do not understand what you mean,
thank you.


Started this thread Reply With Quote




Last Updated on July 28, 2016


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts