Topics
07 Jun 2014, 12:27
 3515
 4
Replies

Antonma
19 Jul 2014, 01:08

Hi,

there is no tick price. You can use Symbol.Bid and Symbol.Ask on the tick event. Some people use (Bid+Ask)/2 in order to get the current price...

Regards,

Anton

 


@Antonma

Antonma
15 Jul 2014, 00:22

Hi,

at this indicator I fix the issue by moving the setting of the index value from MarketDepth.Updated function in to the calculation function of the indicator.

Unfortunately this fix didn't solve the issue with my another nested indicator where I try to put the result from my custom indicator into the OOTB Moving Averages indicator.

Here is it what I'm trying:

private WPOrderBook4MA WP;
        private MovingAverage WPMA;       
        private int lastIndex;

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            object[] parameterAll = new[] 
            {
                (object)L2Depth
            };

            try
            {                
                WP = Indicators.GetIndicator<WPOrderBook4MA>(parameterAll);
                WPMA = Indicators.MovingAverage(WP.Result, BarPeriod, MovingAverageType.Simple);
            }
            catch (Exception ex)
            {
                Print(ex.Message);   
            }

            lastIndex = -1;
            
        }
  public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
              if (!IsLastBar)
            {
                return;
            }

            
            if (lastIndex == 0)
            {
                lastIndex = index;
                return;
            }

            if (lastIndex != index)
            {

                try
                {

                    Result[index] = WPMA.Result[index];
                    Print("WPMA[{0}]={1} ", index, WPMA.Result[index]);
                    Print("WP[{0}]={1}", index, WP.Result[index]);
                    Print("WP.TimeFrame={0}", WP.TimeFrame);
                    Print("WP.Symbol={0}", WP.Symbol);
                    Print("WP.Time={0}", WP.Time);
                    Print("WP.DOMDepth={0}", WP.DOMDepth);
                    Print("WP.Result.LastValue{0}", WP.Result.LastValue);
                }
                catch (Exception ex)
                {

                    Print(ex.Message);
                }

                lastIndex = index;
            }
            
        }

For both

Print("WPMA[{0}]={1} ", index, WPMA.Result[index]);
Print("WP[{0}]={1}", index, WP.Result[index]);

I get always "NaN"

14/07/2014 21:17:13.319 | WPMA[7182]=NaN 
14/07/2014 21:17:13.319 | WP[7182]=NaN
14/07/2014 21:17:13.319 | WP.TimeFrame=Minute
14/07/2014 21:17:13.319 | WP.Symbol=EURJPY (Ask: 138.310, Bid: 138.295)
14/07/2014 21:17:13.319 | WP.Time=14.07.2014 21:17:13
14/07/2014 21:17:13.319 | WP.DOMDepth=3
14/07/2014 21:17:13.319 | WP.Result.LastValueNaN

Some suggestions?

Thank you and bets regards,

Anton


@Antonma

Antonma
06 Jul 2014, 21:30

RE:

akent813 said:

hello, I was wondering, do you guys know if there is a means to extract raw data from ctrader, so that one can identify the details specific to bid/ask/last pricing... im seeking something along these lines... please observer the below sample...

 

20130501000000,1.55358,1.55371
20130501000000,1.55357,1.55369
20130501000000,1.55353,1.55367
20130501000000,1.55349,1.55367
20130501000000,1.55349,1.55367
20130501000001,1.55348,1.55367
20130501000001,1.55348,1.55366
20130501000001,1.55347,1.55362
20130501000001,1.55344,1.55363
20130501000002,1.55348,1.55364
20130501000002,1.55348,1.55364
20130501000004,1.55348,1.55363
20130501000006,1.55348,1.55363
20130501000007,1.55344,1.55362
20130501000008,1.55344,1.55362
20130501000010,1.55344,1.55364
20130501000012,1.55344,1.55364
20130501000013,1.55344,1.55363
20130501000025,1.55344,1.5536

 

I have found the following link relative to one persons attempt to extract this type of content via marketdepth.update

 

/forum/cbot-support/2971

 

not sure if this is a reasonable approach.. it sounds to me more of a work around, I was hoping to access a direct feed and store in a file / db etc?

 

Thanks in advance.

 

 

Hi,

if you just want to have the tick data without the bid and ask volume (not tick count) you can use  MarketSeries and Symbol.

In OnTick event you can access the tickdata with symbol ask and bid and then add to the db or csv file. I do it like this:

protected override void OnTick()
 {
    // Put your core logic here
    //Custom List<> with custom class TickData
    MyTickDataList.Add(new TickData());

    MyTickDataList.Last().Close = MarketSeries.Close.LastValue;
    MyTickDataList.Last().High = MarketSeries.High.LastValue;
    MyTickDataList.Last().Low = MarketSeries.Low.LastValue;            
    MyTickDataList.Last().Open = MarketSeries.Open.LastValue;
    MyTickDataList.Last().OpenTime = MarketSeries.OpenTime.LastValue;                    
    MyTickDataList.Last().TimeStamp = Server.Time.ToFileTimeUtc();

    MyTickDataList.Last().Ask = Symbol.Ask;
    MyTickDataList.Last().Bid = Symbol.Bid;
    ...
   //save data
}

 

Regards,

Anton

 


@Antonma

Antonma
11 Jun 2014, 23:26

Ok, that is what I'm doing now:

1. Gather DOM Data before the next tick occurs

protected override void OnStart()
{
   md = MarketData.GetMarketDepth(Symbol);
   md.Updated += md_Updated;
}  
void md_Updated()
        {
            //Print("md updated: " + Server.Time.ToLongTimeString());

            foreach (var ask in md.AskEntries)
            {
                AskVolumeByPriceByBar.Add(new VolumeByPrice(ask.Price, ask.Volume));
            }

            foreach (var bid in md.BidEntries)
            {
                BidVolumeByPriceByBar.Add(new VolumeByPrice(bid.Price, bid.Volume));
            }
        }

2. When next tick occurs find the current ask and bid prices in gathered list of DOM data:

 protected override void OnTick()
 {
     ...
     List<VolumeByPrice> bidsf = BidVolumeByPriceByBar.FindAll(x => x.Price == Symbol.Bid);
     List<VolumeByPrice> asksf = AskVolumeByPriceByBar.FindAll(x => x.Price == Symbol.Ask);
     ...
     
 }

So assumed that the DOM data was updated 5 times before a new tick occurs which set (<List> index) of values form the DOM data can I take I order to represent the time and sales (T&S) of the current tick? 

Currently I take all DOM data that was changed between current and last tick for current ask and bid price in order to represent the T&S. But I don’t know if it is right.

 foreach (var bid in bidsf)
 {
        tempBidVolume += bid.Volume;
 }

 foreach (var ask in asksf)
 {
        tempAskVolume += ask.Volume;
  }

Any suggestions?

Thank you,

Anton 


@Antonma

Antonma
11 Jun 2014, 23:04

Hi,

use 

index = MarketSeries.Close.Count - 2;

for last closed bar. Count -1 is the current bar...

 

 

 


@Antonma

Antonma
02 Jun 2014, 11:49

RE:

Spotware said:

TickVolume shows only Bid changes. It is not possible to retrieve Ask changes.

Ok, thank you for the clarification. What about the volume? How can I get the volume (not tick count) associated to the bid change?

Regards,

Anton


@Antonma