NexusFi: Find Your Edge


Home Menu

 





Enter on CalOnBarClose=True, but Exit Immediately on X Ticks


Discussion in Traders Hideout

Updated
      Top Posters
    1. looks_one spinnybobo with 8 posts (1 thanks)
    2. looks_two xplorer with 5 posts (0 thanks)
    3. looks_3 albertjay with 5 posts (1 thanks)
    4. looks_4 maryfromcolorado with 2 posts (0 thanks)
    1. trending_up 9,666 views
    2. thumb_up 3 thanks given
    3. group 4 followers
    1. forum 22 posts
    2. attach_file 0 attachments




 
Search this Thread

Enter on CalOnBarClose=True, but Exit Immediately on X Ticks

  #11 (permalink)
 
xplorer's Avatar
 xplorer 
London UK
Site Moderator
 
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 5,945 since Sep 2015
Thanks Given: 15,447
Thanks Received: 15,291


kburks View Post
What platform do you use??

Sent from my SM-G920V using NexusFi mobile app

CQG QTrader.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
Better Renko Gaps
The Elite Circle
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
  #12 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


xplorer View Post
CQG QTrader.

interesting. do you like it better than Ninja?
does it allow you do write code? what language?

Follow me on Twitter Reply With Quote
  #13 (permalink)
 albertjay 
Los Angeles CA
 
Experience: Advanced
Platform: NT
Trading: ES
Posts: 12 since Aug 2015
Thanks Given: 3
Thanks Received: 5


This is pretty much the only thing that I've tried thus far that works. NT should make this a bit easier to do. Hopefully in a future update. All the best, and thanks!


spinnybobo View Post
try this code out
it does not work historically. Historically code would need Add(PeriodType.Tick, 1) added to Initialize()

 
Code
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    
    [Description("used for testing things")]
    public class sdPlayground : Strategy
    {
        
	 private IOrder entryOrder = null;
	 private IOrder exitOrder = null;
	 private int currentBarOrderFilled = 0;
     
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			Unmanaged = true;
        }

     
        protected override void OnBarUpdate()
        {
		if (!Historical)
		{
			if (entryOrder == null && Flat)
			{
				entryOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, 1, 0, 0, "", "Entry");
				Print("hitting this");
			}
			if (entryOrder != null)
				Print(entryOrder.ToString());
			if (Long)
				Print("we are long: Positin.Quantity: " + Position.Quantity + "  AvgPrice  " + Position.AvgPrice);
		}
			
        }
		
	protected override void OnMarketData(MarketDataEventArgs e)
	{
		if (e.MarketDataType == MarketDataType.Last)
		{
				
			double multiplier = 1;
			OrderAction orderAction = OrderAction.Sell;
				
			if (Short)
			{
				multiplier = -1;
				orderAction = OrderAction.BuyToCover;
			}
			double threshold = Instrument.MasterInstrument.Round2TickSize(multiplier*(e.Price - Position.AvgPrice))/TickSize;

			Print("threshold: " + threshold + "  Position.AvgPrice: " + Position.AvgPrice + " e.Price: " + e.Price);
				
			if (Long || Short)
				Print("filled on bar : " + currentBarOrderFilled + " CurrentBar: " + CurrentBar);
				
			if ((Long || Short)&& currentBarOrderFilled == CurrentBar)
			{
				if (threshold >= 2)
					exitOrder = SubmitOrder(0, orderAction, OrderType.Market, 1, 0, 0, "", "Exit 12 Ticks");
			}
				
		 }
		}
		protected override void OnOrderUpdate(IOrder order)
		{
			if (entryOrder != null && entryOrder == order)
			{
				Print(entryOrder.ToString());
				if (order.OrderState == OrderState.Filled)
				{
					currentBarOrderFilled = CurrentBar;
					Print("Filled on bar number: " + currentBarOrderFilled);
					entryOrder = null;
				}
				if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
					entryOrder = null;
			}
			if (exitOrder != null && exitOrder == order)
			{
				if (order.OrderState == OrderState.Filled)
					exitOrder = null;
				if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
					exitOrder = null;
			}
		}
		private bool Long { get { return (Position.MarketPosition == MarketPosition.Long);}}
		private bool Short { get { return (Position.MarketPosition == MarketPosition.Short);}}
		private bool Flat { get { return (Position.MarketPosition == MarketPosition.Flat);}}

        #region Properties
 
        #endregion
    }
}
what I put in OnBarUpdate() was just to get an order
you would want to deal with OnMarketData and if you use IOrders, then OnOrderUpdate to set the CurrentBar to the bar you got filled on. I also included "helper" methods for Long, Short as well as Flat


Started this thread Reply With Quote
  #14 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


albertjay View Post
This is pretty much the only thing that I've tried thus far that works. NT should make this a bit easier to do. Hopefully in a future update. All the best, and thanks!

cool glad I could help. let me know how it goes

Follow me on Twitter Reply With Quote
  #15 (permalink)
 
xplorer's Avatar
 xplorer 
London UK
Site Moderator
 
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 5,945 since Sep 2015
Thanks Given: 15,447
Thanks Received: 15,291


spinnybobo View Post
interesting. do you like it better than Ninja?
does it allow you do write code? what language?

Yes, my experience is that CQG has a better responsiveness than NT. You can code indicators and the like, although I don't think we can talk about CQG having a programming language per se.


Check the 2 posts from this link out - my own one and Okina's (R.I.P.)

Reply With Quote
  #16 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


xplorer View Post
Yes, my experience is that CQG has a better responsiveness than NT. You can code indicators and the like, although I don't think we can talk about CQG having a programming language per se.


Check the 2 posts from this link out - my own one and Okina's (R.I.P.)

where are the links? wow just read about Okina. so sad. I didn't know him but so young. :-( many prayers for him and his wife and family.

Follow me on Twitter Reply With Quote
Thanked by:
  #17 (permalink)
 
xplorer's Avatar
 xplorer 
London UK
Site Moderator
 
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 5,945 since Sep 2015
Thanks Given: 15,447
Thanks Received: 15,291


spinnybobo View Post
where are the links? wow just read about Okina. so sad. I didn't know him but so young. :-( many prayers for him and his wife and family.

Sorry here's the URL


Reply With Quote
  #18 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


xplorer View Post
Sorry here's the URL


oh ok. yeah CQG looks great. but you can't develop in it?

Follow me on Twitter Reply With Quote
  #19 (permalink)
 
xplorer's Avatar
 xplorer 
London UK
Site Moderator
 
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 5,945 since Sep 2015
Thanks Given: 15,447
Thanks Received: 15,291


spinnybobo View Post
oh ok. yeah CQG looks great. but you can't develop in it?

You can use APIs if you have specific needs CQG APIs | [AUTOLINK]CQG[/AUTOLINK], Inc.

CQG has a built-in facility to create indicators. I like its relative simplicity of language to do that.

However documentation is quite poor.

Reply With Quote
  #20 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61



xplorer View Post
You can use APIs if you have specific needs CQG APIs | [AUTOLINK]CQG[/AUTOLINK], Inc.

CQG has a built-in facility to create indicators. I like its relative simplicity of language to do that.

However documentation is quite poor.

cool I will have to look into it sometime

Follow me on Twitter Reply With Quote




Last Updated on October 18, 2016


© 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