Intrabar Order Generation ain't working for moving average crossover - MultiCharts | futures io social day trading
futures io futures trading


Intrabar Order Generation ain't working for moving average crossover
Updated: Views / Replies:530 / 4
Created: by peachfuzz Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • 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.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Intrabar Order Generation ain't working for moving average crossover

  #1 (permalink)
Trading Apprentice
San Francisco CA USA
 
Futures Experience: Advanced
Platform: MultiCharts
Broker/Data: IB, CQG, OEC, TOS
Favorite Futures: ES
 
Posts: 4 since Sep 2015
Thanks: 1 given, 0 received

Intrabar Order Generation ain't working for moving average crossover

Just started using MC .Net and have since begun learning C#. I've managed to write a simple script based on moving average crossover utilizing the Intrabar order generation, with which I'm already having an issue. I would appreciate any advice.

1) IOG works perfectly for prices. For example, when price either crosses above or below another price (eg. high[0] > high[-1]) or an indicator (high > SMA(50)).

2) IOG does not work when it comes to two moving average crossover. Consider the following example.

Two conditions for BUY and SELL orders are coded to be triggered:
-When SMA(10) crosses above SMA(20), send a BUY order IOG
-When SMA(10) crosses below SMA(20), send a SELL order IOG

Suppose then the first condition is met and the BUY order was filled. However, before the end of the bar is reached, price reversed hard and SMA(10) turned down. Now SMA(10) is, again, below SMA(20). Therefore, a SELL order should be sent out. But it doesn't!!!

In the IOG Property box, I even elected to send as many as 100 entries and exits per bar. But to no avail.

Is this a bug, or am I just not getting it? Please enlighten this noob.



PS. Is it also possible to send the SELL order after a delay of, say, 10 ticks?


Last edited by peachfuzz; September 29th, 2015 at 06:22 AM.
Reply With Quote
 
  #2 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

peachfuzz,

as you noticed it won't work that way i.e. comparing this bar's indicator value to the previous bar to detect multiple intrabar crossings. This is not a but, but expected behavior.
For your goal you need to store the value the indicator has at the previous and the current tick and compare that to the indicator you want to check (In your example the SMA 20). If the current tick's value (of the SMA 10) is lower than the SMA 20 and the value from the previous tick is higher, you have a down cross and vice versa.

Adding a delay to your order entry can be done by setting a counter (a simple variable that you increment within your code) at the moment the entry condition is met. Than increment the counter on each subsequent code cycles, until it's above your threshold (10 in your example). At that moment you send the order.

Regards,
ABCTG

Reply With Quote
 
  #3 (permalink)
Trading Apprentice
San Francisco CA USA
 
Futures Experience: Advanced
Platform: MultiCharts
Broker/Data: IB, CQG, OEC, TOS
Favorite Futures: ES
 
Posts: 4 since Sep 2015
Thanks: 1 given, 0 received



ABCTG View Post
peachfuzz,
For your goal you need to store the value the indicator has at the previous and the current tick and compare that to the indicator you want to check (In your example the SMA 20). If the current tick's value (of the SMA 10) is lower than the SMA 20 and the value from the previous tick is higher, you have a down cross and vice versa.

Thanks for your reply. That makes perfect sense. But honestly, being a real noob, I don't even know where to start. Can you give me a pointer or two on how best to handle the issue? Here's what I have currently. As you can see the crossover is there. How would I store the actual price value at the point of the crossover? I look forward to your reply.

 
Code
 protected override void Create()
	{
            x_FastAverage = new XAverage(this);
	    x_SlowAverage = new XAverage(this);
	    x_FastAvg = new VariableSeries<Double>(this);
            x_SlowAvg = new VariableSeries<Double>(this);
	    x_MA2CrossSE = OrderCreator.MarketNextBar(new 
			SOrderParameters(Contracts.Default, "Short", EOrderAction.SellShort));
            x_MA2CrossLE = OrderCreator.MarketNextBar(new 
			SOrderParameters(Contracts.Default, "Long", EOrderAction.SellShort));
        }

		
        protected override void StartCalc()
	{
            price = Bars.Close;
	    x_FastAverage.Price = price;
	    x_FastAverage.Length = FastLength;
	    x_SlowAverage.Price = price;
	    x_SlowAverage.Length = SlowLength;
        }


        protected override void CalcBar()
	{
            x_FastAvg.Value = x_FastAverage[0];
	    x_SlowAvg.Value = x_SlowAverage[0];
	    if (Displace >= 0 || Bars.CurrentBar > Math.Abs(Displace))
		{
                if (Displace <= 0)
			{
            		if (this.CrossesOver(x_FastAvg, x_SlowAvg))
				{
		        	x_MA2CrossLE.Send();
        			}
                        else if (this.CrossesUnder(x_FastAvg, x_SlowAvg))
				{
		        	x_MA2CrossSE.Send();
        			}
			}
        	 }
          }
    }
}


ABCTG View Post
Adding a delay to your order entry can be done by setting a counter (a simple variable that you increment within your code) at the moment the entry condition is met. Than increment the counter on each subsequent code cycles, until it's above your threshold (10 in your example). At that moment you send the order.

Would something like this work?

 
Code
int numOfTicks = 10;

Reply With Quote
 
  #4 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

peachfuzz,

as you wrote you just started learning C#, you might want to lay a solid foundation here first and not dive into the actual programming of programming signals with intrabar order generation. It might appear to slow you down at first, but in the end you'll be so much faster with coming from a better understanding of the language.

You wouldn't need to store the price at the cross over in my opinion, but "the value the indicator has at the previous and the current tick and compare that to the indicator you want to check".

I am not sure what you intend with "int numOfTicks = 10;", but it would rather be something like (if numOfTicks is of type private int):
 
Code
if (your Long entry condition is triggered)
numOfTicks++;

if (numOfTicks >= 10)
{
 numOfTicks = 0;
 send the order here...
}
Regards,
ABCTG

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #5 (permalink)
Trading Apprentice
San Francisco CA USA
 
Futures Experience: Advanced
Platform: MultiCharts
Broker/Data: IB, CQG, OEC, TOS
Favorite Futures: ES
 
Posts: 4 since Sep 2015
Thanks: 1 given, 0 received

@ABCTG
Thanks for your input as well as your sage advice. I'm trying, I'm trying, but it ain't easy. Plus trying to tweak the trading strategy to make it more profitable is eating up all my time. I'll get there though.

Reply With Quote

Reply



futures io > > > > Intrabar Order Generation ain't working for moving average crossover

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Intra-Bar Order Generation ivanyu MultiCharts 4 July 24th, 2015 01:16 PM
Moving average crossover in market analyzer renkonovice NinjaTrader 0 September 28th, 2014 06:13 PM
Has anyone built a moving average crossover optimization in Excel 2010? buffalotrader100 Traders Hideout 2 February 12th, 2014 12:07 PM
question regarding order generation and onbarclose KhaosTrader EasyLanguage Programming 3 October 27th, 2012 06:18 AM
Predicting a crossover or moving average for next bar Trader.Jon NinjaTrader Programming 10 April 11th, 2010 11:11 PM


All times are GMT -4. The time now is 08:16 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@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 2017-12-17 in 0.10 seconds with 19 queries on phoenix via your IP 54.145.16.43