How I could measured latency in MultiChart ? - MultiCharts | futures.io
futures.io futures trading
 

Go Back   futures.io

> Futures Trading, News, Charts and Platforms > Platforms and Indicators > MultiCharts


How I could measured latency in MultiChart ?
Started:October 25th, 2016 (01:28 PM) by pardo127 Views / Replies:237 / 5
Last Reply:November 1st, 2016 (10:39 AM) Attachments:0

Welcome to futures.io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike
     

Reply
 
Thread Tools Search this Thread

How I could measured latency in MultiChart ?

Old October 25th, 2016, 01:28 PM   #1 (permalink)
Trading Apprentice
madrid spain
 
Futures Experience: Beginner
Platform: tradestation
Favorite Futures: gold gc
 
Posts: 5 since Oct 2016
Thanks: 0 given, 0 received

How I could measured latency in MultiChart ?

I need to measured the latency of my strategy.

Could help me someone?

Reply With Quote
     

Old October 25th, 2016, 02:05 PM   #2 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MultiCharts, NinjaTrader, MetaTrader, R
Broker/Data: Interactive Brokers, IQFeed, Oanda
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 86 since Oct 2009
Thanks: 711 given, 72 received

Version?

.Net or EasyLanguage? What exactly are you trying to measure?

-Guy

Reply With Quote
     

Old October 25th, 2016, 02:20 PM   #3 (permalink)
Trading Apprentice
madrid spain
 
Futures Experience: Beginner
Platform: tradestation
Favorite Futures: gold gc
 
Posts: 5 since Oct 2016
Thanks: 0 given, 0 received



Fu510n View Post
.Net or EasyLanguage? What exactly are you trying to measure?

-Guy

I want to measure the time that takes my order to IB and the time that takes from the broker to exchange.

I have this Easylanguage code but dont compile in Multichart because It programmed with objects :


{
JJ Log Generator
---------------------------
Based on Code from Mathemagician
Added ideas from AndroidMarvin
Modded by Honza K.
---------------------------

Purpose: Logs order state infos with milisecond difference calculation between events



}

// DefineDLLFunc: "JJLogger.dll", int, "LogMessage", lpstr, lpstr;

Using tsdata.trading;
Using elsystem;

input:
EnableLogging(true),
LogFileName("C:\JJ_LogFromTS.txt");

var:
Intrabarpersist MessagesLogged(0),
Intrabarpersist Order ord(null),
Intrabarpersist tmpString(""),
StopWatch sw( Null ), // to get msec resolution
OrdersProvider op(null),
Intrabarpersist lastElapsed( 0.0 ); // record previous msec value to count diff

Method override void InitializeComponent()
begin
op = New OrdersProvider;
op.Realtime = true;
op.Updated+=opUpdated;
op.Load=true;
sw = New StopWatch; // AndroidMarvin idea - adding stopwatch to count latencies directly
sw.Start();
end;

Method void opUpdated (Objectsender, OrderUpdatedEventArgs args)
begin
if EnableLogging and args.Reason.ToString()<>"initialupdate" then begin
MessagesLogged+=1;
If args.Order<>null then begin
ord = args.Order;
tmpString =
Formatdate("yyyy/MM/dd", ComputerDateTime()) // date
+ "," + FormatTime("HH:mm:ss", ComputerDateTime()) // time
+ "," + numtostr( sw.ElapsedMilliseconds - lastElapsed, 0 ) // milisecond difference from previous event
+ "," + args.State.ToString()
{ + "," + args.Message
+ "," + args.Reason.ToString()
+ "," + ord.AccountID
+ "," + ord.Action.ToString()
+ "," + ord.AvgFilledPrice.ToString()
+ "," + ord.EnteredQuantity.ToString()
+ "," + ord.EnteredTime.ToString()
+ "," + ord.FilledQuantity.ToString()
+ "," + ord.FilledTime.ToString()
+ "," + ord.OrderID.ToString()
+ "," + ord.Originator.ToString()
+ "," + ord.Route.ToString()
+ "," + ord.State.ToString()
+ "," + ord.StateDetail.ToString()
+ "," + ord.StopPrice.ToString()
+ "," + ord.Symbol.ToString()
+ "," + ord.SymbolExtension.ToString()
+ "," + ord.Type.ToString()
} ;

end else begin
tmpString =
args.State.ToString()
+ "," + args.AccountID
+ "," + args.Message
+ "," + args.OrderID
+ "," + args.Reason.ToString()
+ "," + args.Symbol
;
end;

Fileappend(LogFileName, tmpString + newline);
lastElapsed = sw.ElapsedMilliseconds;

end;
end;

// Once (EnableLogging) begin Fileappend(LogFileName, newline + "Logging Active" + newline); end;
plot1(MessagesLogged, "Log Messages");

Reply With Quote
     

Old October 26th, 2016, 12:35 PM   #4 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MultiCharts, NinjaTrader, MetaTrader, R
Broker/Data: Interactive Brokers, IQFeed, Oanda
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 86 since Oct 2009
Thanks: 711 given, 72 received

Example EL benchmarking code

Answer
This post has been selected as an answer to the original posters question Answer

I ripped the code below from my own 10,000+ line EL strategy - no guarantees as to accuracy (though it does compile) or applicability but it will hopefully give you some ideas on benchmarking strategy code that doesn't require TradeStation-only "method" support (which would be a nice MC enhancement at some point).

 
Code
[IntrabarOrderGeneration = True]

vars:
  IntraBarPersist isStrategyAuto( False ),
  IntraBarPersist Tick( 0 ),
  IntraBarPersist _ContractsPerTrade( 1 ),
  IntraBarPersist EntryBar( -1 ),
  IntraBarPersist EntryTick( -1 ),
  IntraBarPersist EntryTime_s( 0.0 ),
  IntraBarPersist PendingTick( -1 ),
  IntraBarPersist PendingTime_s( 0.0 ),
  IntraBarPersist FilledTick( -1 ),
  IntraBarPersist FilledTime_s( 0.0 ),
  TradeTimeOK( True ),  // if not IsHoliday and NewsOK and Time >= TimeStart and Time < _TimeEnd and DayOfWeek( Date ) >= Monday and DayOfWeek( Date ) <= Friday
  ProfitLossOK( True ); // if TodayLoss <= -DailyLossMax


once begin
  Tick = 0;
end;

if BarStatus( 1 ) = -1 then begin // "between ticks" (MTF only?)
  #return;
end else
  Tick = Tick + 1;

{
| If trading live, don't bother processing historical data so orders aren't generated
}
isStrategyAuto = GetAppInfo( aiStrategyAuto ) = 1;
if isStrategyAuto and GetAppInfo( aiRealTimeCalc ) <> 1 then #return;

if EntryBar = -1 and MarketPosition = 0 and ProfitLossOK and TradeTimeOK and BarStatus(1) = 2 then begin

  value1 = 0; // some strategy that generates 1 for longs and -1 for shorts on bar close

  if value1 <> 0 then begin
  
    if value1 = 1 then
      Buy( "LE" {"LONG entry"} ) _ContractsPerTrade Contracts Next Bar at Market
    else
    if value1 = -1 then
      SellShort( "SE" {"SHORT entry"} ) _ContractsPerTrade Contracts Next Bar at Market;

    EntryBar = CurrentBar + MaxBarsBack;
    EntryTick = Tick;
    EntryTime_s = Time_s + MillisecondsFromDateTime( DateTime ) / 1000;
    PendingTick = -1;
    PendingTime_s = 0.0;
    FilledTick = -1;
    FilledTime_s = 0.0;

  end;
end;
  
if EntryBar <> -1 and CurrentContracts > 0 then begin

  if PendingTick = -1 then begin
    PendingTick = Tick;
    PendingTime_s = Time_s + MillisecondsFromDateTime( DateTime ) / 1000;
  end;

  if FilledTick = -1 and (MarketPosition_at_Broker <> 0 or not isStrategyAuto) then begin
    FilledTick = Tick;
    FilledTime_s = Time_s + MillisecondsFromDateTime( DateTime ) / 1000;

    MessageLog(
      "EntryTick=[", EntryTick:0:0, "] ",
      "EntryTime=[", EntryTime_s:0:3, "] ",
      "PendingTick=[", PendingTick:0:0, "] ",
      "PendingTime=[", PendingTime_s:0:3, "] ",
      "PendingElapsed=[", (TimeToSeconds( IntPortion( PendingTime_s )) + FracPortion( PendingTime_s )) - (TimeToSeconds( IntPortion( EntryTime_s )) + FracPortion( EntryTime_s )):0:3, "s] ",
      "FilledTime=[", FilledTime_s:0:3, "] ",
      "FilledTick=[", FilledTick:0:0, "] ",
      "FilledElapsed=[", (TimeToSeconds( IntPortion( FilledTime_s )) + FracPortion( FilledTime_s )) - (TimeToSeconds( IntPortion( PendingTime_s )) + FracPortion( PendingTime_s )):0:3, "s] ",                  
      "MarketPosition=[", MarketPosition:0:0, "] ",
      "MarketPosition_at_Broker=[", MarketPosition_at_Broker:0:0, "] ",
      "MarketPosition_at_Broker_for_The_Strategy=[", MarketPosition_at_Broker_for_The_Strategy:0:0, "] ",
      "CurrentContracts=[", CurrentContracts:0:0, "]"
    );
  end;
end;

if EntryBar <> -1 and CurrentContracts > 0 and FilledTick <> -1 then begin
  // manage exit here
  EntryBar = -1; // on trade close..
end else begin
  if EntryBar <> -1 and EntryTick <> Tick then begin
    if CurrentBar + MaxBarsBack > EntryBar then begin
      // delayed entry past desired signal bar (market moving too fast?); either way, bail ASAP rather than take a chance
    end;
  end;
end;

Reply With Quote
     
The following user says Thank You to Fu510n for this post:
     

Old October 26th, 2016, 03:40 PM   #5 (permalink)
Trading Apprentice
Madrid, Spain
 
Futures Experience: Beginner
Platform: TradeStation
Favorite Futures: Emini Es
 
Posts: 7 since Feb 2016
Thanks: 7 given, 1 received

Futures Edge on FIO

Fu510n View Post
I ripped the code below from my own 10,000+ line EL strategy - no guarantees as to accuracy (though it does compile) or applicability but it will hopefully give you some ideas on benchmarking strategy code that doesn't require TradeStation-only "method" support (which would be a nice MC enhancement at some point).

 
Code
[IntrabarOrderGeneration = True]

vars:
  IntraBarPersist isStrategyAuto( False ),
  IntraBarPersist Tick( 0 ),
  IntraBarPersist _ContractsPerTrade( 1 ),
  IntraBarPersist EntryBar( -1 ),
  IntraBarPersist EntryTick( -1 ),
  IntraBarPersist EntryTime_s( 0.0 ),
  IntraBarPersist PendingTick( -1 ),
  IntraBarPersist PendingTime_s( 0.0 ),
  IntraBarPersist FilledTick( -1 ),
  IntraBarPersist FilledTime_s( 0.0 ),
  TradeTimeOK( True ),  // if not IsHoliday and NewsOK and Time >= TimeStart and Time < _TimeEnd and DayOfWeek( Date ) >= Monday and DayOfWeek( Date ) <= Friday
  ProfitLossOK( True ); // if TodayLoss <= -DailyLossMax


once begin
  Tick = 0;
end;

if BarStatus( 1 ) = -1 then begin // "between ticks" (MTF only?)
  #return;
end else
  Tick = Tick + 1;

{
| If trading live, don't bother processing historical data so orders aren't generated
}
isStrategyAuto = GetAppInfo( aiStrategyAuto ) = 1;
if isStrategyAuto and GetAppInfo( aiRealTimeCalc ) <> 1 then #return;

if EntryBar = -1 and MarketPosition = 0 and ProfitLossOK and TradeTimeOK and BarStatus(1) = 2 then begin

  value1 = 0; // some strategy that generates 1 for longs and -1 for shorts on bar close

  if value1 <> 0 then begin
  
    if value1 = 1 then
      Buy( "LE" {"LONG entry"} ) _ContractsPerTrade Contracts Next Bar at Market
    else
    if value1 = -1 then
      SellShort( "SE" {"SHORT entry"} ) _ContractsPerTrade Contracts Next Bar at Market;

    EntryBar = CurrentBar + MaxBarsBack;
    EntryTick = Tick;
    EntryTime_s = Time_s + MillisecondsFromDateTime( DateTime ) / 1000;
    PendingTick = -1;
    PendingTime_s = 0.0;
    FilledTick = -1;
    FilledTime_s = 0.0;

  end;
end;
  
if EntryBar <> -1 and CurrentContracts > 0 then begin

  if PendingTick = -1 then begin
    PendingTick = Tick;
    PendingTime_s = Time_s + MillisecondsFromDateTime( DateTime ) / 1000;
  end;

  if FilledTick = -1 and (MarketPosition_at_Broker <> 0 or not isStrategyAuto) then begin
    FilledTick = Tick;
    FilledTime_s = Time_s + MillisecondsFromDateTime( DateTime ) / 1000;

    MessageLog(
      "EntryTick=[", EntryTick:0:0, "] ",
      "EntryTime=[", EntryTime_s:0:3, "] ",
      "PendingTick=[", PendingTick:0:0, "] ",
      "PendingTime=[", PendingTime_s:0:3, "] ",
      "PendingElapsed=[", (TimeToSeconds( IntPortion( PendingTime_s )) + FracPortion( PendingTime_s )) - (TimeToSeconds( IntPortion( EntryTime_s )) + FracPortion( EntryTime_s )):0:3, "s] ",
      "FilledTime=[", FilledTime_s:0:3, "] ",
      "FilledTick=[", FilledTick:0:0, "] ",
      "FilledElapsed=[", (TimeToSeconds( IntPortion( FilledTime_s )) + FracPortion( FilledTime_s )) - (TimeToSeconds( IntPortion( PendingTime_s )) + FracPortion( PendingTime_s )):0:3, "s] ",                  
      "MarketPosition=[", MarketPosition:0:0, "] ",
      "MarketPosition_at_Broker=[", MarketPosition_at_Broker:0:0, "] ",
      "MarketPosition_at_Broker_for_The_Strategy=[", MarketPosition_at_Broker_for_The_Strategy:0:0, "] ",
      "CurrentContracts=[", CurrentContracts:0:0, "]"
    );
  end;
end;

if EntryBar <> -1 and CurrentContracts > 0 and FilledTick <> -1 then begin
  // manage exit here
  EntryBar = -1; // on trade close..
end else begin
  if EntryBar <> -1 and EntryTick <> Tick then begin
    if CurrentBar + MaxBarsBack > EntryBar then begin
      // delayed entry past desired signal bar (market moving too fast?); either way, bail ASAP rather than take a chance
    end;
  end;
end;

Thanks for the post FU510n.

I am trying to understand the code I am stuck with the expression "EntryTick:0:0". What does this instruction do?

Thanks in advance.

Reply With Quote
     

Old November 1st, 2016, 10:39 AM   #6 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MultiCharts, NinjaTrader, MetaTrader, R
Broker/Data: Interactive Brokers, IQFeed, Oanda
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 86 since Oct 2009
Thanks: 711 given, 72 received

MultiCharts numerical expression formatting

Lifting from Print or even on BMT in various places MultiCharts Easylanguage Price Decimal Points ... it's just output formatting (that in the case of "EntryTick:0:0" just prints it as a basic integer without ANY decimal places).

Quoting 
A numerical expression can be formatted to specify the minimum number of characters, including the decimal point, and the number of decimal places to be used for the output:
Expression:c:d
Where:
c - minimum number of characters,
d - number of decimal places.
The default output format for a numerical expression is two decimal places and a minimum of seven characters.

If the number of decimal places in the numerical expression is more than the specified number, the value will be will be rounded off to the specified number of decimal places.

If the number of characters in the output is less than the specified minimum, leading spaces will be added to bring the output to the specified minimum value.


Reply With Quote
     
The following user says Thank You to Fu510n for this post:
     

Reply



futures.io > Futures Trading, News, Charts and Platforms > Platforms and Indicators > MultiCharts > How I could measured latency in MultiChart ?

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Al Brooks: Stop Losing when a Good Trade goes Bad, Correcting Mistakes

Elite only
 

Trading Technologies: Algo Design Lab hands-on

Dec 13

Normal webinar schedule resumes after the holidays

January
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do you know your latency? endian675 NinjaTrader 12 October 25th, 2016 03:41 PM
Measured Move steve2222 Terms (Glossary) 0 April 11th, 2016 06:34 AM
Latency EthanC Tech Support 4 July 6th, 2014 11:13 PM
Daily profit measured by volatility Big Mike Psychology and Money Management 63 March 11th, 2013 08:26 PM
Indicator that measured distance in ticks between movable lines PeterOhlson NinjaTrader 1 June 12th, 2011 03:00 PM


All times are GMT -4. The time now is 06:00 PM.

Copyright © 2016 by futures.io. All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
 
no new posts
Page generated 2016-12-08 in 0.11 seconds with 31 queries on phoenix via your IP 54.159.129.152