Trouble with code

Created at 25 Apr 2014, 22:15
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
TE

Tempestshade

Joined 29.03.2014

Trouble with code
25 Apr 2014, 22:15


Hello,

 

I currently have a cBot I am working on and for whatever reason it will not open up Buy trades. My code is:

 

 

            if (ncv >= 0 && ocv <= 0)
            {
                if (MarketSeries.Close[0] > MarketSeries.Open[0])
                {
                    var buy = Symbol.Bid + 0.002;
                    PlaceStopOrder(TradeType.Buy, Symbol, Volume, buy, label, StopLoss, TakeProfit);
                }
                if (MarketSeries.Close[0] < MarketSeries.Open[0])
                {
                    var sell = Symbol.Ask - 0.002;
                    PlaceStopOrder(TradeType.Sell, Symbol, Volume, sell, label, StopLoss, TakeProfit);
                }
            }

It opens up sell trades no problem, however, for whatever reason buy trades will not work. Would love help.

 

Cheers,

David


@Tempestshade
Replies

Researcher
27 Apr 2014, 12:11

MarketSeries.Open[0] is the first value on a chart, if you want last one use MarketSeries.Open.Last(0) instead


@Researcher

Jimmy
18 May 2014, 15:13

trouble with code

What do you MEAN??

The first value on the chart ?? the first candle on the most left side of the chart?? the oldest bar??

The first/ last value on the right side of the chart?? the newest bar whilst the newer that did not close is still being made??

Please be specific.

I have written many indicators and many robots on a different platform and i am now trying to begin using Calgo but i find it to be EXTREMELY HARD because nothing seems to work in the last two days i have written at least 8 robots and none of them work the way i want them to work i can not get the MarketSeries. to pull correct values it either opens up one trade and stays there or it starts flipping orders at each tick i am really getting a headache and becoming depressed about this the documentation on these methods is so POOR extremely POOR for all i know bar-1 is the oldest bar and bar [1] is the last newest closed bar and bar [0] is the bar currently being made but i can find no reference or guide what so ever of what these array indexes are in Calgo.

It always says build succeeded but it never actually works the way i wrote it.

Somebody ought to write a decent manual on this thing or it will be a complete fail you can't expect coders to spend day's on just a few simple methods that somehow refuse to function the way they are supposed to or at least the way they are experienced with.

I used to be so fast producing working code and now all of a sudden i am stuck at one point barely moving forward because i just have no reference or manual that comes with the code.

I see many people are having many problems like these
 


@Jimmy

bp2012
19 May 2014, 02:26

mt4 uses index 0 to be the current bar, but ctrader uses a more traditional approach where index 0 is the first (oldest) bar in the series. Personally I prefer the ctrader perspective. 

There is a bit of a learning curve for cTrader, but once you have a few indicators and robots under your belt I think that most people will find it superior to other platforms. 

 

The information you are looking for can be found below. I've pasted in the relevant section and a link to the source. I'd recommend writing indicators before doing heavy lifting on a robot. (Just my 2 cents.)

Good Luck!

 

/api/guides/indicators

Calculate

The calculate method is the main method of the indicator. It is called for each historic bar starting from the beginning of the series up to the current bar and then on each incoming tick. In the case of multi-symbol / multi-timeframe implementation, it will be called on each tick of each symbol that is used in the indicator.

It is typically used for the calculation of an indicator based on a formula. In this case, it is the difference of the High and the Low prices of each bar. The index parameter, represents each bar, ranging from 0 up to the current (last) bar. So, at each bar the Calculate method will be called and the Result will be assigned with the difference between the High and the Low of that bar.


@bp2012

Jimmy
19 May 2014, 08:40

RE:

Thank You.

With the information you provided i actually got it to work properly.

Do you maybe also know the solution as to how we can implement a shift in the sma method?

I have been trying to work around it but i hope there is a more easy method

 

bp2012 said:

mt4 uses index 0 to be the current bar, but ctrader uses a more traditional approach where index 0 is the first (oldest) bar in the series. Personally I prefer the ctrader perspective. 

There is a bit of a learning curve for cTrader, but once you have a few indicators and robots under your belt I think that most people will find it superior to other platforms. 

 

The information you are looking for can be found below. I've pasted in the relevant section and a link to the source. I'd recommend writing indicators before doing heavy lifting on a robot. (Just my 2 cents.)

Good Luck!

 

/api/guides/indicators

Calculate

The calculate method is the main method of the indicator. It is called for each historic bar starting from the beginning of the series up to the current bar and then on each incoming tick. In the case of multi-symbol / multi-timeframe implementation, it will be called on each tick of each symbol that is used in the indicator.

It is typically used for the calculation of an indicator based on a formula. In this case, it is the difference of the High and the Low prices of each bar. The index parameter, represents each bar, ranging from 0 up to the current (last) bar. So, at each bar the Calculate method will be called and the Result will be assigned with the difference between the High and the Low of that bar.

 


@Jimmy