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


How I could measured latency in MultiChart ?
Updated: Views / Replies:393 / 5
Created: by pardo127 Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • 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.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

How I could measured latency in MultiChart ?

  #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
 
  #2 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MC, NT, Python, R
Broker/Data: FXCM, IB, Oanda, IQFeed
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 94 since Oct 2009
Thanks: 724 given, 77 received

Version?

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

-Guy

Reply With Quote
 
  #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
 
  #4 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MC, NT, Python, R
Broker/Data: FXCM, IB, Oanda, IQFeed
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 94 since Oct 2009
Thanks: 724 given, 77 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:
 
  #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


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
 
  #6 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MC, NT, Python, R
Broker/Data: FXCM, IB, Oanda, IQFeed
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 94 since Oct 2009
Thanks: 724 given, 77 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 > > > > 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)

July Journal Challenge w/$1100 in prizes from TopstepTrader

July

John @ No BS Day Trading (TBA)

Elite only

An Afternoon with FIO member Softsoap (being rescheduled)

Elite only
     

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


All times are GMT -4. The time now is 11:37 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@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 2017-06-26 in 0.11 seconds with 32 queries on phoenix via your IP 54.224.86.148