Enter on CalOnBarClose=True, but Exit Immediately on X Ticks (Page 2) - Traders Hideout | futures.io
futures.io futures trading
 

Go Back   futures.io

> Futures Trading, News, Charts and Platforms > Traders Hideout


Enter on CalOnBarClose=True, but Exit Immediately on X Ticks
Started:September 13th, 2016 (05:30 PM) by albertjay Views / Replies:733 / 22
Last Reply:October 18th, 2016 (09:16 PM) Attachments:0

Welcome to futures.io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike
     

Reply
 
Thread Tools Search this Thread

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

Old September 14th, 2016, 05:04 PM   #11 (permalink)
Market Wizard
London UK
 
Futures Experience: Beginner
Platform: CQG
Favorite Futures: Futures
 
xplorer's Avatar
 
Posts: 1,547 since Sep 2015
Thanks: 2,642 given, 1,927 received
Forum Reputation: Legendary


kburks View Post
What platform do you use??

Sent from my SM-G920V using futures.io mobile app

CQG QTrader.

Reply With Quote
     

Old September 14th, 2016, 07:06 PM   #12 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 47 received


xplorer View Post
CQG QTrader.

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

Reply With Quote
     

Old September 14th, 2016, 08:42 PM   #13 (permalink)
Elite Member
Los Angeles CA
 
Futures Experience: Advanced
Platform: NT
Favorite Futures: Stocks
 
Posts: 8 since Aug 2015
Thanks: 0 given, 2 received


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


Reply With Quote
     

Old September 15th, 2016, 02:15 AM   #14 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 47 received


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

Reply With Quote
     

Old September 15th, 2016, 05:52 AM   #15 (permalink)
Market Wizard
London UK
 
Futures Experience: Beginner
Platform: CQG
Favorite Futures: Futures
 
xplorer's Avatar
 
Posts: 1,547 since Sep 2015
Thanks: 2,642 given, 1,927 received
Forum Reputation: Legendary

Futures Edge on FIO

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
     

Old September 15th, 2016, 11:16 AM   #16 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 47 received


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.

Reply With Quote
     
The following user says Thank You to spinnybobo for this post:
     

Old September 15th, 2016, 11:43 AM   #17 (permalink)
Market Wizard
London UK
 
Futures Experience: Beginner
Platform: CQG
Favorite Futures: Futures
 
xplorer's Avatar
 
Posts: 1,547 since Sep 2015
Thanks: 2,642 given, 1,927 received
Forum Reputation: Legendary


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

https://futures.io/elite-trading-journals/38439-scalper-s-journey-1088.html#post583691

Reply With Quote
     

Old September 15th, 2016, 09:42 PM   #18 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 47 received



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

Reply With Quote
     

Old September 16th, 2016, 06:58 AM   #19 (permalink)
Market Wizard
London UK
 
Futures Experience: Beginner
Platform: CQG
Favorite Futures: Futures
 
xplorer's Avatar
 
Posts: 1,547 since Sep 2015
Thanks: 2,642 given, 1,927 received
Forum Reputation: Legendary


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 | CQG, 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
     

Old September 16th, 2016, 11:53 AM   #20 (permalink)
Elite Member
Crete, IL/USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
 
spinnybobo's Avatar
 
Posts: 171 since Aug 2009
Thanks: 99 given, 47 received



xplorer View Post
You can use APIs if you have specific needs CQG APIs | CQG, 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

Reply With Quote
     

Reply



futures.io > Futures Trading, News, Charts and Platforms > Traders Hideout > Enter on CalOnBarClose=True, but Exit Immediately on X Ticks

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Trading Technologies: ADL hands-on

Dec 13

Normal webinar schedule resumes after the holidays

January

Ernie Chan: Risk Management

Elite only

Dedicated Trading Servers: Advantages/Disadvantages w/sam028

Elite only

An Afternoon with FIO member Massive I

Elite only

Leo Murphy: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter and Exit market using different chart resolution vhanded MultiCharts 0 May 1st, 2015 06:37 AM
Enter and exit positions within the same bar mandelmus EasyLanguage Programming 2 March 12th, 2015 10:41 AM
How to enter long buy on a bar immediately before it closes. bmtfken EasyLanguage Programming 19 July 27th, 2014 08:01 PM
Best Price Enter/Exit? NJAMC Elite Automated NinjaTrader Trading 3 July 8th, 2011 06:00 PM
Viper has a "order entry strategy" that you can use to enter and exit. rcr3908 NinjaTrader 2 April 30th, 2011 06:20 PM


All times are GMT -4. The time now is 09:47 AM.

Copyright © 2016 by futures.io. 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.
 
no new posts
Page generated 2016-12-11 in 0.16 seconds with 39 queries on phoenix via your IP 54.159.129.152