Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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?
Can you help answer these questions from other members on NexusFi?
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):
@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.