NexusFi: Find Your Edge


Home Menu

 





Max trades per Day


Discussion in NinjaTrader

Updated
    1. trending_up 2,090 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Max trades per Day

  #1 (permalink)
steinhandel
Spain/Spain
 
Posts: 6 since Feb 2016
Thanks Given: 1
Thanks Received: 0

Hello,

I need to implement max limit per day in NT8
I have the next code in NT8 that trade well in backtesting, but not in Real time
can someone help me?
thanks

private int trades_till_today = 0;
private int _MaxEntriesDay = 2;


protected override void OnBarUpdate()
{

if ( Bars.IsFirstBarOfSession )
{
trades_till_today = SystemPerformance.AllTrades.Count;
}

int trades_today = SystemPerformance.AllTrades.Count - trades_till_today + (Position.MarketPosition != MarketPosition.Flat ? 1 : 0);

if (trades_today < _MaxEntriesDay)
{
If (Close[0] > EMA1[0])

{
EnterLong();
}
}

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
About a successful futures trader who didnt know anythin …
Psychology and Money Management
What broker to use for trading palladium futures
Commodities
 
  #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: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

I would recommend you add some debug output in your code
with the statement Print, you then can follow the logic of your
code through the day.

Something i'm think of, what instrument are you trading ?
Is there on or more session per day ?

Also if you stop/start your strategy, your count will be zeroed
(mind : closing manually a position will stop your strategy

All of this will become cleared when outputting more information


steinhandel View Post
Hello,

I need to implement max limit per day in NT8
I have the next code in NT8 that trade well in backtesting, but not in Real time
can someone help me?
thanks

private int trades_till_today = 0;
private int _MaxEntriesDay = 2;


protected override void OnBarUpdate()
{

if ( Bars.IsFirstBarOfSession )
{
trades_till_today = SystemPerformance.AllTrades.Count;
}

int trades_today = SystemPerformance.AllTrades.Count - trades_till_today + (Position.MarketPosition != MarketPosition.Flat ? 1 : 0);

if (trades_today < _MaxEntriesDay)
{
If (Close[0] > EMA1[0])

{
EnterLong();
}
}


Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
steinhandel
Spain/Spain
 
Posts: 6 since Feb 2016
Thanks Given: 1
Thanks Received: 0


Thanks for your reply rleplae,

I attached below complete code
it work well in backtesting with any intrument (i try ZN)
I trade one sesión per day

but, in realtime or market replay, the limit of trades per day, donīt work.



#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion

namespace NinjaTrader.NinjaScript.Strategies
{
public class TPD : Strategy
{

private int profitTargetTicks = 15;
private int stopLossTicks = 10;
private int trades_till_today = 0;
private SMA SMA1;


protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"trade per day Limit (one session per day)";
Name = "TPD";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
IsInstantiatedOnEachOptimizationIteration = true;

_cntrcts = 1;
_MaxEntriesDay = 2;

}

else if (State == State.Configure)
{
SetStopLoss(CalculationMode.Ticks, stopLossTicks);
SetProfitTarget(CalculationMode.Ticks, profitTargetTicks);

}

else if (State == State.DataLoaded)
{
SMA1 = SMA(10);
}

}

protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade) return;

if (CurrentBars[0] < 1)
return;
if ( Bars.IsFirstBarOfSession )
{
trades_till_today = SystemPerformance.AllTrades.Count;
}

int trades_today = SystemPerformance.AllTrades.Count - trades_till_today + (Position.MarketPosition != MarketPosition.Flat ? 1 : 0);
if (trades_today < _MaxEntriesDay)

{

// Set 1
if (Close[0] > (SMA1[0] ))

{
EnterLong(Convert.ToInt32(_cntrcts), "");
}

// Set 2
if (Close[0] < (SMA1[0]))

{
EnterShort(Convert.ToInt32(_cntrcts), "");
}

}

}

#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(ResourceType = typeof(Custom.Resource), Name="_cntrcts", Description="cntrcts", Order=1, GroupName="NinjaScriptStrategyParameters")]
public int _cntrcts
{ get; set; }

[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(ResourceType = typeof(Custom.Resource), Name="_MaxEntriesDay", Description="_MaxEntriesDay ", Order=2, GroupName="NinjaScriptStrategyParameters")]
public int _MaxEntriesDay
{ get; set; }


[Range(0, int.MaxValue)]
[NinjaScriptProperty]
[Display(Name="Profit Target Ticks", Description="Number of ticks away from entry price for the Profit Target order", Order=3, GroupName="Parameters")]
public int ProfitTargetTicks
{
get { return profitTargetTicks; }
set { profitTargetTicks = value; }
}

[Range(0, int.MaxValue)]
[NinjaScriptProperty]
[Display(Name="Stop Loss Ticks", Description="Numbers of ticks away from entry price for the Stop Loss order", Order=4, GroupName="Parameters")]
public int StopLossTicks
{
get { return stopLossTicks; }
set { stopLossTicks = value; }
}


#endregion

}
}

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: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

I suggest you output some of those values with a Print statement, when you run it in real-time
and then you will see what values are returned and where the logic flows...

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
steinhandel
Spain/Spain
 
Posts: 6 since Feb 2016
Thanks Given: 1
Thanks Received: 0

Thanls rleplae,

I donīt understand well what it means "print statement", Can you put an example?

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: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


steinhandel View Post
Thanls rleplae,

I donīt understand well what it means "print statement", Can you put an example?

sure :

 
Code
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade) return;

if (CurrentBars[0] < 1)
return;
if ( Bars.IsFirstBarOfSession )
{
trades_till_today = SystemPerformance.AllTrades.Count;
Print("trades_till_today:"+trades_till_today);
}

int trades_today = SystemPerformance.AllTrades.Count - trades_till_today + (Position.MarketPosition != MarketPosition.Flat ? 1 : 0);	

Print("trades_today:"+trades_today);
Print("_MaxEntriesDay"+_MaxEntriesDay);

if (trades_today < _MaxEntriesDay)

{	

// Set 1	
if (Close[0] > (SMA1[0] ))

{
EnterLong(Convert.ToInt32(_cntrcts), "");
}

// Set 2
if (Close[0] < (SMA1[0])) 

{
EnterShort(Convert.ToInt32(_cntrcts), "");
}

}

}

You need to open the output window in NT
then you will see the values each time that piece of code is executed

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
steinhandel
Spain/Spain
 
Posts: 6 since Feb 2016
Thanks Given: 1
Thanks Received: 0

Sorry for my inexperience rleplae,
I conect Ninjascript output at same time that run market replay and.... any mesages any errors
(only definition of parameters ..." ennabling Ninjascript strategy TPD: On starting a real time strategy.......

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: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

Then you can add other Print statements to make sure you are editing the right file.
If you have your output window open, you should at least see something

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on September 18, 2017


© 2024 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 - Privacy Policy - Downloads - Top
no new posts