Topics
Replies
lec0456
04 Apr 2013, 16:53
I am shifting back one bar if the SMA is based on the close, high or low because of what I have been asking. Since these values are not final( or valid )at index you shouldn't use them to calculate the SMA. Above you recomended to only use the values index-1, which is shifting the values back one bar as well.
What was happening to me was that if I made a calculation based on the SMA value at index and index-1 when the next bar comes(i.e. index advances one) the SMA at index should be equal to index-1, but sometimes it would not be equal because the SMA was not using the final value of the closing. Its a little hard to explain. When the on bar is triggered it calculates the SMA and continues to update the same index value until the next on bar it triggered. So you get different values at the begiining verses the end of the on bar. thats what my issue is or what I am trying to solve...
If you are using the SMA for manual trading and eyeballing trades, its not going to matter one bit but if you are using the SMA for calculations you will get erratic results.
If you use the SMA the way it is, then you have to use index-1, which is shifting back one bar. Which is fine except for when you want the SMA based on the Open because then you are shifting back when you don't have to. At index the open is final.
I guess the other way to do it is use index -1 when calcualting off of the close, high or low; but use index when calculating off of the open but that creates programing complexity.
@lec0456
lec0456
04 Apr 2013, 01:46
ok, yes you could do that but if you use the market open then you are using the previous open when the current open is stable. So here is what I did:
public override void Calculate(int index) { int t0=index; if(t0<paramPeriods)return;//** prevent crash caused by posibly using a negetive index value if(double.IsNaN(Source[t0]))return; double sum=0; if(Source==MarketSeries.Open) { for (int x = t0 - paramPeriods + 1; x <= t0; x++) // this will include calculations using index where High, Low, & Close values are not final. {sum+=Source[x];} // if you use the open, calculations will be the same as the SMA included with cAlgo } else { for (int x = t0 - paramPeriods; x < t0; x++) // this will include the last 10 values not including index because values are not final except for the open. {sum+=Source[x];} // these results wll be different from the SMA included with cAlgo } Result[index]=sum/paramPeriods; //DateTime opentime= MarketSeries.OpenTime[index]; //Print("{0,20}{1,20}{2,20}{3,20}{4,20}",opentime,index,Result[index],Result[index-1],"Indicator"); }
@lec0456
lec0456
02 Apr 2013, 23:24
Well, I was only addressing the index problem. it seemed simple enough. But it looks like there are other problems with the indicator
this line doesn't look like it will work because its trying to change the previous index value set. I don't think you can do that...
DomCyc[index - 1] = mDomCyc[index];
You probably have to wait for support to respond to that question. Sorry.
@lec0456
lec0456
02 Apr 2013, 21:57
looks like you are using previous index values to calculate something. like index-1 and index-2
So, you probably just need a statement in the begining of your Calculate procedure that says:
if(index<2)return;
otherwise the first value calculated will cause a crash.
@lec0456
lec0456
02 Apr 2013, 17:57
Hi Support,
I am back to investigating this issue because of accuracy concerns. To recap, my concern is that if you use an SMA on a Market Closing price and include the index value, you will get unstable results. because At the index value the close is not final. We had some discussion above but i never got a final answer... If I use a 1 period SMA the result for values less than index(ie. index-1) are equal to the close but the value for index is shifting. Which means that if a robot uses the current SMA value it will be off when on bar event is called.
@lec0456
lec0456
16 Mar 2013, 21:42
TraderM thanks for checking on the issue. There are a couple of methids that only work in real time like the notifications for email and sound. But I was trying to verify if the same was true with the chart Objects. I would like to see if support will verify this and decide if it is by design or a bug. I would really like to see this available with backtesting.
I will tell you that you can get indicators to mark the chart with trade entries and exits but that is obviously a lot more work and not going to cover all the possible uses as within a robot.
@lec0456
lec0456
15 Mar 2013, 22:30
Ok, I changed the color and played with the position but nothing. The code is below, Could you see if it works by backtesting?
using System; using System.Collections.Generic; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.Indicators; using cAlgo.API.Requests; namespace cAlgo.Robots { [Robot] public class TestChartObject : Robot { private Position openedTrade; protected override void OnBar() { if (Trade.IsExecuting) return; if (openedTrade==null) { var Order = new MarketOrderRequest(TradeType.Buy, 100000) {Label="Trade",SlippagePips=1,StopLossPips=10,TakeProfitPips=10}; Trade.Send(Order); } } protected override void OnPositionOpened(Position openedPosition) { openedTrade=openedPosition; ChartObjects.DrawText("Trade"+(MarketSeries.Close.Count-1), "T", MarketSeries.Close.Count-1, openedPosition.EntryPrice+(5*Symbol.PipSize), VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Red); Print("************************{0} {1}*****************************",MarketSeries.Close.Count-1,openedPosition.EntryPrice+(5*Symbol.PipSize)); } protected override void OnPositionClosed(Position closedPosition){openedTrade=null;} } }
@lec0456
lec0456
13 Mar 2013, 23:31
I have this line:
ChartObjects.DrawText("Trade"+(MarketSeries.Close.Count-1), "T", MarketSeries.Close.Count-1, openedPosition.EntryPrice+3*Symbol.PipSize, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);
in the OnPositionOpened event, but it doesn't work. I was expecting it would place a "T" for trade over the bar a position was opened but nothing, no error , nothing...any clues?
@lec0456
lec0456
13 Mar 2013, 20:25
I ran the same tests against FXPro data and the indicator and the Robot SMA's match. I notice the versions of cAlgo are different. the version of FXpro cAlgo is 1.0.26115 and ICMarkets cAlgo is 1.0.26114. Don't know if that is the difference but you can clearly see that IC Markets is giving different values for SMA between the indicators and Robots. please investigate!
@lec0456
lec0456
13 Mar 2013, 19:26
I will tell you what I think the issue could be...Using a double to hold all indicator values will introduce randomness in calculations because the use of decimals and division are not precise with doubles. With C# You need to use decimal data type. Thats just a hunch...
@lec0456
lec0456
05 Apr 2013, 22:20
Ok
@lec0456