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



How I could measured latency in MultiChart ?


Discussion in MultiCharts

Updated
    1. trending_up 1,044 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 5 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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

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

 
Search this Thread
 

How I could measured latency in MultiChart ?

(login for full post details)
  #1 (permalink)
madrid spain
 
 
Posts: 5 since Oct 2016
Thanks: 0 given, 0 received

I need to measured the latency of my strategy.

Could help me someone?

Reply With Quote

Journal Challenge February 2021 results:
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(173 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(120 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(35 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #2 (permalink)
Suffield, CT
 
Experience: Advanced
Platform: MultiCharts, Python
Broker: IB, IQFeed, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
 
Fu510n's Avatar
 
Posts: 116 since Oct 2009
Thanks: 815 given, 116 received

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

-Guy

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #3 (permalink)
madrid spain
 
 
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
 
(login for full post details)
  #4 (permalink)
Suffield, CT
 
Experience: Advanced
Platform: MultiCharts, Python
Broker: IB, IQFeed, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
 
Fu510n's Avatar
 
Posts: 116 since Oct 2009
Thanks: 815 given, 116 received

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;

Follow me on Twitter Reply With Quote
The following user says Thank You to Fu510n for this post:
 
(login for full post details)
  #5 (permalink)
Madrid, Spain
 
 
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
 
(login for full post details)
  #6 (permalink)
Suffield, CT
 
Experience: Advanced
Platform: MultiCharts, Python
Broker: IB, IQFeed, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
 
Fu510n's Avatar
 
Posts: 116 since Oct 2009
Thanks: 815 given, 116 received

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.


Follow me on Twitter Reply With Quote
The following user says Thank You to Fu510n for this post:


futures io Trading Community Platforms and Indicators MultiCharts > How I could measured latency in MultiChart ?


Last Updated on November 1, 2016


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Call Option Buying: The New Pain Trade? w/Carley Garner

Elite only
     



Copyright © 2021 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