Got a problem with my current strategy setup.
I have an indicator that effectively needs to calculate at the end of bar close. Therefore the strategy is set to calculate @ close.
However I have set up a method of when the indicator triggers, an entry order is placed 1 tick - the current bar's close (buy.) A cancel order is set to trigger if the price moves 3 ticks + the current order.
However because the strategy is set to calculate @ close, there has been repeated times where an order has been placed, then the price moving 4 -5 ticks with being filled. (ie the bar has not closed.)
How is it possible to for the order to be calculated tick for tick?
I heard of using OnMarketData but have no idea how to code it?
Any help would be great. Thanks
My only suggestion is to use CalculateOnBarClose = False, which will fix your cancel code and then use "FirstTickOfBar" in your entry code. When doing that, set your signal back one bar. So, instead of:
if (CrossAbove(EMA(20), EMA(50), 0)), use:
if (FirstTickOfBar && CrossAbove(EMA(20), EMA(50), 1))
This allows your signal to reach bar close before entering. There may be a better way out there but I THINK this will do what you want.
The following user says Thank You to dsraider for this post:
I hear you as I like to let the bar close before entering as well but this can be used as a fix. When you add FirstTickOfBar to your entry code and set your signal back a bar, it basically tells you strat to wait until your entry bar closes (like you want) and then enter at the first tick of the next bar. I then set my entry order to Open. So, for the example I gave you, at the open of the current bar, the strat would check to see if the 20 crossed above the 50 on the close of the last bar. If it did, it would enter. Using this combo prevents the strat from taking trades mid-bar.
Unless I'm missing something (or too hungover to fully understand you), I think this will do it.
Hmm....every indicator in your code SHOULD require you to decide which bar to choose ( being current,  being one bar back). Basically, if you see a , try changing it to . If your signal isn't secret, I'd be happy to have a look. Otherwise, let's start with that.
hmm well its a custom indicator off a vendor. I have tried to use  but doesnt seem to work. When I set to calc at close to false, it becomes way too CPU intensive.
Is it possible to have 2 strategies running?
ie - One for the indicator, and the other being for order placement and trade management?
I don't think that's possible but there are many people much more experienced with programming than I am. Maybe they know better. Is your indicator a free one? If so, I'll download and try and figure out the code. If not, maybe you can post or PM me the part that only includes the numbers? Sometimes, you don't get  but can have "(xxx, 0)" instead.