Comparison of Open and Close Price
Comparison of Open and Close Price
23 Jan 2013, 17:38
I am trying to create a condition that will compare the open price with the close price as displayed on candles, but it doesnt open any positions when infact that simple condition is met many times. Here is the sample code. Im not sure if i am using MarketSeries correctly.
double firstclose = MarketSeries.Close[MarketSeries.Close.Count-1]; double firstopen = MarketSeries.Open[MarketSeries.Close.Count-1];
if (firstopen > firstclose)
{
//Sell
}
Replies
supafly
23 Jan 2013, 19:42
Admin,
Thanks for taking the time to write the above algo. I have just compared it to my algo and they are very similar in logic and syntax. I am still unable to locate the problem so i compiled your algo to see the outcome and it is giving me the same results which are 0 trades executed, so im not sure what else to do.
If it helps, the only differences are:
private Position position;
protected override void OnBar()
Thanks
@supafly
admin
24 Jan 2013, 10:59
Have you tried backtesting it? If you are using OnBar that means that the code will execute on each new trendbar which will depend on the timeframe that you are using. If you are using the default hourly timeframe you would have to wait up to an hour before the code executes. Try a small timeframe like a minute, as well as backtesting.
@admin
supafly
24 Jan 2013, 13:38
Hi Admin,
I have backtested and dropped down to the 1 minute but again no result. If its possible, can you run the above algo and tell me if it works on your system. Im not sure if there is an issue when doing a comparison and both conditions have the same MarketSeries count.
Thanks
@supafly
supafly
24 Jan 2013, 18:46
Also, I have another live working algorithm that uses count -1 for a MarketSeries command and moving averages with count -1 and count -2. If my above statement is true, when I tried to modify the algorithm to say -2 instead of -1, the bactesting results were poor compared to the previous backtest results. Again this algorithm uses OnBar().
Thanks
@supafly
admin
25 Jan 2013, 09:48
You can use print statements to confirm the values like so:
protected override void OnBar() { int index = MarketSeries.Close.Count - 1; Print("Open Time {0}", MarketSeries.OpenTime[index]); Print("Open {0}", MarketSeries.Open[index]); Print("Close {0}", MarketSeries.Close[index]); Print("High {0}", MarketSeries.High[index]); Print("Low {0}", MarketSeries.Low[index]); Print("Open Time {0}", MarketSeries.OpenTime.LastValue); Print("Open {0}", MarketSeries.Open.LastValue); Print("Close {0}", MarketSeries.Close.LastValue); Print("High {0}", MarketSeries.High.LastValue); Print("Low {0}", MarketSeries.Low.LastValue); Print("Open Time {0}", MarketSeries.OpenTime[index - 1]); Print("Open {0}", MarketSeries.Open[index - 1]); Print("Close {0}", MarketSeries.Close[index - 1]); Print("High {0}", MarketSeries.High[index - 1]); Print("Low {0}", MarketSeries.Low[index - 1]); }
@admin
admin
23 Jan 2013, 17:55
Yes, it is correct. A simple print statement will prove that this condition is met within the code. It is probably something else that is not correct.
You can test this code and let us know:
@admin