I have wrote the following code (just as a sample):
protectedoverridevoid OnBarUpdate()
{
if (FirstOperation)
{
EnterLong(100000, "Operation 1");
FirstEntryPrice = Close[0]; // Here I just want to register the price to which I have bought
Print ("First Entry Price: " + FirstEntryPrice.ToString());
FirstOperation = false;
SecondOperation = true;
}
NewTrigger = FirstEntryPrice - Distance;
if (SecondOperation && Close[0] < NewTrigger)
{
Print ("Close Long and Enter Short if current tick Price less than: " + NewTrigger.ToString());
ExitLong("Operation 1");
EnterShort(100000, "Operation 2");
SecondEntryPrice = Close[0];
Print ("Second Entry Price: " + SecondEntryPrice.ToString());
SecondOperation = false;
}
}
So, I need to know the exact price to which I bought/sold and place and order the sooner the price reach the NewTrigger level.
I need to to do backtesting with database when the strategy is finished, then, I think I have to dismiss Event Driven programming. Is it right?
I have been trying to execute this code on backtest mode (EURUSD tick-to-tick) and I find strange results:
- On the graph (Strategy Analyzer), it appears I buy Operation1 for 1.2774, but in my own output screen says: "First Entry Price: 1.2775" which is the previous tick.
- Similar results with se Short position.
Could you please tell me how can I avoid this delay error? Will the corrected code be different when I test the strategy with real-time feed-data?
Thank you very much for your comments.
Comment