Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
How I could measured latency in MultiChart ?
Updated November 1, 2016
trending_up
1,793 views
thumb_up
2 thanks given
group
4 followers
forum
5 posts
attach_file
0 attachments
How I could measured latency in MultiChart ?
October 25th, 2016, 12:28 PM
madrid spain
Posts: 5 since Oct 2016
Thanks Given: 0
Thanks Received: 0
I need to measured the latency of my strategy.
Could help me someone?
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
October 25th, 2016, 01:05 PM
Suffield, CT
Experience: Advanced
Platform: MC, TS, Python, Rust
Broker: IB, IQFeed, TS, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
Frequency: Several times daily
Duration: Seconds
Posts: 144 since Oct 2009
Thanks Given: 902
Thanks Received: 143
.Net or EasyLanguage ? What exactly are you trying to measure?
-Guy
October 25th, 2016, 01:20 PM
madrid spain
Posts: 5 since Oct 2016
Thanks Given: 0
Thanks Received: 0
Fu510n
.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");
October 26th, 2016, 11:35 AM
Suffield, CT
Experience: Advanced
Platform: MC, TS, Python, Rust
Broker: IB, IQFeed, TS, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
Frequency: Several times daily
Duration: Seconds
Posts: 144 since Oct 2009
Thanks Given: 902
Thanks Received: 143
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;
October 26th, 2016, 02:40 PM
Madrid, Spain
Posts: 7 since Feb 2016
Thanks Given: 7
Thanks Received: 1
Fu510n
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.
November 1st, 2016, 09:39 AM
Suffield, CT
Experience: Advanced
Platform: MC, TS, Python, Rust
Broker: IB, IQFeed, TS, Kraken
Trading: ES, NQ, RTY, YM, CL, RB, 6E
Frequency: Several times daily
Duration: Seconds
Posts: 144 since Oct 2009
Thanks Given: 902
Thanks Received: 143
Lifting from Print or even on BMT in various places MultiCharts [AUTOLINK]Easylanguage[/AUTOLINK] 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.
Last Updated on November 1, 2016