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 > 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 05:22 AM.
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.
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.
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):
The following user says Thank You to ABCTG for this post:
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.