Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

Tradewinds

Object-Oriented Programming OOP

Recommended Posts

Great idea ... I'm a programmer by trade so I will be more than happy to help and answer questions ... bring them on!

 

MMS

 

When you first learned OOP basics, can you recall anything that didn't make sense to you? Did you learn it quickly? Are there things that quickly made sense to you? Was there anything about OOP that took a while for you to understand? Did you need to develop a different way of thinking? Is there anything about OOP that you confuse with procedural programing? Is there anything about OOP that you still make a mistake on? These are the kinds of things that I'd be interested in hearing about; from you or anyone else.

Share this post


Link to post
Share on other sites
When you first learned OOP basics, can you recall anything that didn't make sense to you?

 

This applies to programming in general but understanding and being able to program something using recursion. Once you understand this, OO becomes much easier as you are now able to think about objects\reuse\etc in an abstract way.

 

Did you learn it quickly? Are there things that quickly made sense to you?

 

Too me, basic OO is just a way to organize data\code into useful, self-contained things - called objects. So instead of having 10 variables and 50 procedures\functions in a file, instead you have 5 objects each with 2 variables with 10 functions\properties each. So coding and understanding this is easier as you are breaking the problem down into something smaller and more manageable.

 

Was there anything about OOP that took a while for you to understand? Did you need to develop a different way of thinking?

 

Now there are advanced features of OO that took some more practice, like Inheritance and Polymorphism. These features are there to help reuse code. Summary:

1. Objects - used to organize code\functionality

2. Inheritence\Polymorphism - ways to reuse code and reduce copy\paste

 

Is there anything about OOP that you confuse with procedural programing? Is there anything about OOP that you still make a mistake on? These are the kinds of things that I'd be interested in hearing about; from you or anyone else.

 

I would say a common mistake is for people to 'over-engineer' their object hierarchies and incorrectly implement Inheritance and Polymorphism. I've seen OO programs much more damn confusing than a procedural programs. It all depends on using the tools correctly. OO gives plenty of rope for people to hang themselves with.

 

But given the complexity of software today, some applications would be nearly impossible without OO.

 

thx

MMS

Share this post


Link to post
Share on other sites

When OO came on the popular computing scene ~25 yr ago (largely due to the availability of personal computer to the general public), it was all hype and hoopla, it was the best thing invented since sliced bread. It was the "future" of programming.

 

25 years later, I am surprised to see TS taking it on as a trading language.

 

My personal take (only personal 2 cents' worth) -- it is a waste of otherwise useful and productive time for the non-programmers (especially traders) trying to learn and implement any serious and extensive OO programming project.

 

OO programming is a craft, not a skill.

It requires dedication and discipline to learn.

It requires total immersion to learn it well. (object thinking is a paradigm shift)

It requires practice practice and practice

(ie. getting paid to do it professionally on the boss' dime).

 

If you have not touched a piece of EasyLanguage code for 3 months,

you can pick it up and understand the operation immediately.

 

If you have not touched a piece of OO code for 3 months,

it might take you a day(s) to understand the heads and tails of things

(unless it is a very short code).

 

OO is great for big and complicated projects. (eg. a comprehensive autotrade)

EasyLanguage is good for small to medium sized indicators and simple autotrades.

 

For the full time trader and amateur programmer,

my advice is to stick to EasyLanguage and spend your precious time trading and making money, and if you have extra time, go and have fun doing things with the money you earned.

 

Again, don't mean to discourage anybody taking it on... this is only my 2 cents' worth of gut feelings. YMMV.

Edited by Tams

Share this post


Link to post
Share on other sites

Too me, basic OO is just a way to organize data\code into useful, self-contained things - called objects. So instead of having 10 variables and 50 procedures\functions in a file, instead you have 5 objects each with 2 variables with 10 functions\properties each. So coding and understanding this is easier as you are breaking the problem down into something smaller and more manageable.

thx

MMS

 

This sound interesting, and thank you for the feedback. What I'd be interested in seeing is two sets of very simple code, one procedural, one OO. For example, the price breaks the last high. Don't show all the code for how to determine the last high, just assume that we already have that. What would be the object? How would you program the condition of the current close going over the last high? I don't know if you could do it in pseudo code?

 

var: LastHigh(0), NewHigh(False);

NewHigh = Close > LastHigh;  // NewHigh is assigned a value of 'True' when condition met

 

How would OO code be different?

Share this post


Link to post
Share on other sites
What would be the object? How would you program the condition of the current close going over the last high? I don't know if you could do it in pseudo code?

 

var: LastHigh(0), NewHigh(False);

NewHigh = Close > LastHigh;  // NewHigh is assigned a value of 'True' when condition met

 

How would OO code be different?

 

I could see a vendor building the code this way - where the instrument (stock, etc) is the object and things like volume, price, etc. are its properties. e.g.

 

class Stock()
{
 // variables to hold data
 int LastHigh;
 int Close;
 int Price;
 int Volume:

 // properties to return calculated data values
 bool NewHigh {
   return Close > LastHigh;
 }
}

 

Then someone would use this object like so:

 

Stock s = new Stock("AAPL");
if (s.NewHigh == true) BUY!!

 

So it all depends on the framework provided by the vendor. I know NinjaTrader is built with C# so if you program against it, essentially you are using OO. But like Tams said earlier, if the main goal is Trading, it doesn't matter whether it is OO or not, the tool doesn't matter. You just want it to work.

 

thx

MMS

Share this post


Link to post
Share on other sites

25 years later, I am surprised to see TS taking it on as a trading language.

 

My personal take (only personal 2 cents' worth) -- it is a waste of otherwise useful and productive time for the non-programmers (especially traders) trying to learn and implement any serious and extensive OO programming project.

 

I wouldn't care about OO, but I have this code that was created as an example by TradeStation, and it's the only code that I know of that will do what I want. I don't know of any other options. It has to do with running the code, and therefore a clock, independent from having the code calculate dependent upon data ticks.

 

Plus I'm not sure if there is functionality, options available in OO in EasyLanguage not available otherwise. So, in a sense, I feel that I'm being forced to learn two programing languages, and I may need to use both of them in the same indicator.

Share this post


Link to post
Share on other sites
So, in a sense, I feel that I'm being forced to learn two programing languages, and I may need to use both of them in the same indicator.

 

OO is not a new programming language - it more like a new technique of how to use a programming language. C# is a OO language but you can write a program that is 100% procedural in nature. So if it was written in EasyLanguage, you just have to get your head around how they organized the code, and if they used any OO features of the language. You don't have to learn another language. I hope that makes sense ...

 

MMS

Share this post


Link to post
Share on other sites
OO is not a new programming language -

 

Well, yes, you are right OO is not a new programming language. But the reality is, I need to go through a whole new learning process that is just as much work as learning a new language. Actually it's more work, because I already know procedural programing logic, so I could go to another language, and just need to learn the syntax and nomenclature.

Share this post


Link to post
Share on other sites
I wouldn't care about OO, but I have this code that was created as an example by TradeStation, and it's the only code that I know of that will do what I want. I don't know of any other options. It has to do with running the code, and therefore a clock, independent from having the code calculate dependent upon data ticks.

 

Plus I'm not sure if there is functionality, options available in OO in EasyLanguage not available otherwise. So, in a sense, I feel that I'm being forced to learn two programing languages, and I may need to use both of them in the same indicator.

 

can't help you if you have to use a piece of code written by TS in OO.

 

for tasks beyond what EL offers, I would rather go to PowerBasic, or FreeBasic, etc., not OO.

Share this post


Link to post
Share on other sites

Okay, I'd like to go through an entire indicator in OOP, and figure out everything step by step. Let's use the indicator to send an order to the market.

 

Input: string iAccount1( "Enter Your Equities Account Number" ), int iQuantity1(100), PlaceOrderNow(FALSE);

vars: tsdata.trading.Order MyOrder(NULL);

{Called whenever the order status is updated}
Method void OrderStatusUpdate(elsystem.Object sender, tsdata.trading.OrderUpdatedEventArgs args)
begin
UpdatePlots();
end;

{Plots the order status}
method void UpdatePlots()
begin
Plot1(MyOrder.State.ToString()); 
end;

{Send the order when TRUE and sets the method used to handle Order Status Updated events} 
If PlaceOrderNow then begin
{Order sent only once per load in this example}
once MyOrder = OrderTicket1.Send();
MyOrder.Updated += OrderStatusUpdate;
UpdatePlots();
end;

 

First are user INPUTS:

 

Input: string iAccount1( "Enter Your Equities Account Number" ), int iQuantity1(100), PlaceOrderNow(FALSE);

 

This doesn't look any different than with procedural programing.

 

Next are VARIABLES:

 

vars: tsdata.trading.Order MyOrder(NULL);

 

'vars:' is the same, but the variable 'MyOrder' is preceded with some stuff. What is this stuff?

 

tsdata.trading is a Namespace, whatever that means. I guess that 'Order' is the Class, whatever that means. "tsdata.trading.Order" has Properties, Methods and Events, but I don't see anything about creating a variable. Okay, I found something else.

 

tsdata.trading

 

Contains classes that are used to manage trades, positions, and account information.

 

Okay, I can understand about managing trades, managing positions and managing account information. So if I want to manage a trade, I need to somehow use this 'tsdata.trading' Namespace. That makes some sense to me, but I still don't know why they have to call it a 'Namespace' or what a Namespace is. It seems kind of stupid. It's like a generic term that has it's place in some kind of structure, but it doesn't intuitively mean anything to me. So I just need to know that there are these things called 'Namespaces', and they are at the foundation of the hierarchy. I need to deal with them first, or I can't get to the the other stuff. If I don't use the Namespace tsdata.trading, then I can't get to the point where the code actually issues a buy command. Would you say that is correct?

 

So, to declare a variable, it seems like I need to list the Namespace first and attach the 'Order' class to it. But I still have absolutely no idea why I need to list the Namespace and Class before the variable name. And I don't see anything in the help to tell me what the syntax is for declaring a variable. I guess it's just something you need to magically know.

 

Okay, maybe what it does, is set up a relationship with the variable MyOrder to the 'tsdata.trading.Order' thingy so I don't need to type that every time. So I can just type 'MyOrder' instead of 'tsdata.trading.Order'?

 

Anyway, That's enough for now. If anyone can magically make this more understandable, please feel free to comment.

Share this post


Link to post
Share on other sites

Let's move on to the next section:

 

{Called whenever the order status is updated}
Method void OrderStatusUpdate(elsystem.Object sender, tsdata.trading.OrderUpdatedEventArgs args)
begin
UpdatePlots();
end;

 

The above section of code is a subroutine. Don't confuse the Method reserved word with Object Oriented Methods. These are two different things. The above subroutine is named 'OrderStatusUpdate'. The 'OrderStatusUpdate' subroutine runs whenever it is called with the 'OrderStatusUpdate' name. Subroutines created with the Method reserved word can receive arguments passed to it. In this indicator, the call to the subroutine comes later down in the code than the subroutine. Method Subroutines can be called from a line either below or above the subroutine. A sequential programing flow is not required. It looks like the 'OrderStatusUpdate' subroutine is set up to receive a couple input arguments.

 

The first argument is: elsystem.Object sender

 

elsystem.Object is as follows:

 

A base class from which all other classes are derived. Every method in the Object class is available in all objects in the system, although derived classes can and do override some of the base methods. TradeStation HELP

 

'sender' and 'args' are the names given to the input parameters. elsystem.Object is the data type of the input 'sender'. The data type must be put in front of each input parameter name. Okay, 'sender' and 'args' are just named parameters. Sort of like naming variables, but here, the inputs are named.

 

So the Method subroutine will receive data of data types, elsystem.Object and tsdata.trading.OrderUpdatedEventArgs, and those data type names are 'sender' and 'args'.

So this subroutine named 'OrderStatusUpdate' will receive inputs, and then this subroutine calls another subroutine named 'UpdatePlots'.

 

I don't know what the point is of the subroutine 'OrderStatusUpdate' receiving inputs. I don't see that those inputs are used in any way, unless they are then passed on again to the 'UpdatePlots' subroutine. But I don't know if that's what happens or not.

Share this post


Link to post
Share on other sites

Next are VARIABLES:

 

vars: tsdata.trading.Order MyOrder(NULL);

 

'vars:' is the same, but the variable 'MyOrder' is preceded with some stuff. What is this stuff?

 

tsdata.trading is a Namespace, whatever that means.

 

A namespace is used to organize Classes. In large systems, there may be many classes what would have the 'name' Order, so to differentiate between them, you put them into its own 'namespace', which is 'tsdata.trading'

 

Remember my first post about OO being a way to organize code. This is a real-life example of that.

 

I need to deal with them first, or I can't get to the the other stuff. If I don't use the Namespace tsdata.trading, then I can't get to the point where the code actually issues a buy command. Would you say that is correct?

 

To use the correct Order class, you have to declare the correct one by using its 'fullname' - which would be tsdata.trading.Order. So yes to your question.

 

Okay, maybe what it does, is set up a relationship with the variable MyOrder to the 'tsdata.trading.Order' thingy so I don't need to type that every time. So I can just type 'MyOrder' instead of 'tsdata.trading.Order'?

 

No, 'MyOrder' is simply the variable name. A variable must be declared to be of a type, most commonly an integer or a string. But here, it is of type 'tsdata.trading.Order'. So 'MyOrder' is a 'tsdata.trading.Order'

 

I hope my explanations are clear ... some references:

Introduction to Object Oriented Programming Concepts (OOP) and More - CodeProject

 

thx

MMS

Share this post


Link to post
Share on other sites

I don't know what the point is of the subroutine 'OrderStatusUpdate' receiving inputs. I don't see that those inputs are used in any way, unless they are then passed on again to the 'UpdatePlots' subroutine. But I don't know if that's what happens or not.

 

This method is called an 'event handler' (I can tell by the type of the parameters - tsdata.trading.OrderUpdatedEventArgs).

 

An 'event handler' is the method that runs code when the 'OrderStatusUpdate' event happens in your program. These parameters are common to event handlers, as it tells the receiver who triggered the event (elsystem.Object sender) and if there are any arguments for the event (tsdata.trading.OrderUpdatedEventArgs args - this would be data, etc).

 

In this particular example, the parameters are not used but more often than not, these parameters would be used.

 

MMS

Share this post


Link to post
Share on other sites
This method is called an 'event handler' (I can tell by the type of the parameters - tsdata.trading.OrderUpdatedEventArgs).

 

An 'event handler' is the method that runs code when the 'OrderStatusUpdate' event happens in your program. These parameters are common to event handlers, as it tells the receiver who triggered the event (elsystem.Object sender) and if there are any arguments for the event (tsdata.trading.OrderUpdatedEventArgs args - this would be data, etc).

 

In this particular example, the parameters are not used but more often than not, these parameters would be used.

 

MMS

 

Okay, so when the status of an order changes, the platform updates and maintains the info about the order change in a database. Information on the order status can be retrieved and sent to the 'Event Handler' when something detects the 'OrderStatusUpdate' event?

 

Are there some basic rules about the 'sender' and 'receiver'? I'm assuming that the 'sender' was whatever called the event handler? And the receiver is the event handler?

Share this post


Link to post
Share on other sites

Let's look that the last part of the code:

 

{Send the order when TRUE and sets the method used to handle Order Status Updated events} 
If PlaceOrderNow then begin
{Order sent only once per load in this example}
once MyOrder = OrderTicket1.Send();
MyOrder.Updated += OrderStatusUpdate;
UpdatePlots();
end;

 

'MyOrder' is a variable. I'm familiar enough with EasyLanguage to know that certain commands return an output value, and it's required to set a variable equal to the command in order to receive the output value. So the variable, 'MyOrder' is set equal to the OrderTicket1.Send() Method. This places the order.

 

Then on the next line, the variable 'MyOrder' has something appended to it.

 

MyOrder.Updated

 

I use the autocomplete, and went through the list of things available to 'MyOrder', and 'Updated' has a lightening bolt icon in front of it. I don't know what that icon stands for. There are different icons that mean different things. Okay, I just found it, the lightening bolt means that it's an Event. The Help states that 'Updated' is an Event Handler that is called whenever the object is updated. The Event Handler is called, but what does that do? I really don't know what the end result of 'MyOrder.Updated' is?

 

Now, I don't know what the plus and equal signs do in the line:

 

MyOrder.Updated += OrderStatusUpdate;

 

The OrderStatusUpdate is the subroutine name. So that makes the subroutine run. I don't know why the plus and equals signs are there?

Share this post


Link to post
Share on other sites

I guess that Events allow objects to send and receive information. A property is easy to understand. The button is blue. The Order Qty is 1. Methods cause some action. Send the Order.

 

Properties

Methods

Events

 

Events don't cause an action, but you use an Event if you want to get information, or send information about an object?

Share this post


Link to post
Share on other sites

 

Next are VARIABLES:

 

vars: tsdata.trading.Order MyOrder(NULL);

 

'vars:' is the same, but the variable 'MyOrder' is preceded with some stuff. What is this stuff?

 

Okay, maybe what it does, is set up a relationship with the variable MyOrder to the 'tsdata.trading.Order' thingy so I don't need to type that every time. So I can just type 'MyOrder' instead of 'tsdata.trading.Order'?

 

No, 'MyOrder' is simply the variable name. A variable must be declared to be of a type, most commonly an integer or a string. But here, it is of type 'tsdata.trading.Order'. So 'MyOrder' is a 'tsdata.trading.Order'

 

I do know that once the variable has been defined in that way, with 'tsdata.trading.Order' as the type of data, that the variable 'MyOrder' has options available to it.

 

I can not use:

 

tsdata.trading.Order.Cancel

 

But I CAN do this:

 

MyOrder.Cancel

 

I don't know why those two are not interchangeable.

Share this post


Link to post
Share on other sites
Okay, so when the status of an order changes, the platform updates and maintains the info about the order change in a database. Information on the order status can be retrieved and sent to the 'Event Handler' when something detects the 'OrderStatusUpdate' event?

 

Yes it usually works like that

 

Are there some basic rules about the 'sender' and 'receiver'? I'm assuming that the 'sender' was whatever called the event handler? And the receiver is the event handler?

 

The sender can be any object that initiates the event. And a receiver can be any object that chooses to listen for the event. Remember, in OO, all functions\methods are attached to an object. So 'event handler' is just a specific function on an object that contains the code that responds to the event.

 

MMS

Share this post


Link to post
Share on other sites
So the variable, 'MyOrder' is set equal to the OrderTicket1.Send() Method. This places the order.

 

More accurately, the MyOrder variable is set to the output of the OrderTicket1.Send() method. What is happening here is the OrderTicket1.Send() method returns a Order object and you are setting MyOrder to point to that object.

 

'Updated' has a lightening bolt icon in front of it.

 

These are 'events' that are initiated by the object

 

MyOrder.Updated += OrderStatusUpdate;

 

What this is doing is registering the OrderStatusUpdate 'event handler' (that we talked about in the previous post) to the event MyOrder.Updated.

 

So whenever the Updated event (on the MyOrder object) happens, it will call the event handler OrderStatusUpdate.

 

thx,

MMS

Share this post


Link to post
Share on other sites
I guess that Events allow objects to send and receive information. Events don't cause an action, but you use an Event if you want to get information, or send information about an object?

 

Events allow objects to notify other objects about its state. You use events when you want to be notified when another objects' state changed (e.g. OrderStatusUpdated). At that point, the receiving object can get all information it needs from the event arguments or from the sender of the event.

 

MMS

Share this post


Link to post
Share on other sites

I can not use:

 

tsdata.trading.Order.Cancel

 

But I CAN do this:

 

MyOrder.Cancel

 

I don't know why those two are not interchangeable.

 

Type defines the properties\functions\events\etc of an object - like a blueprint.

But an object is an instance of the Type - like a house.

 

Maybe another analogy will help here ...

 

tsdata.trading.Order == 'Human'

MyOrder == 'Mark'

 

So MyOrder is an instance of Type tsdata.trading.Order

just as 'Mark' is an instance of Type 'Human'

 

So therefore you can call 'MyOrder.Cancel'

just like you can call 'Mark.Walk'

 

But 'Human.Walk' doesn't make sense because 'Human' is just a definition. 'Mark' is the instance of that definition. Thats why you can't call 'tsdata.trading.Order.Cancel'

 

MMS

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Topics

  • Posts

    • I'm still a dove regarding crypto trading. Not because of the instruments traded, but because of the lack of market centralization. It reminds me of the early days of forex trading where no broker-dealers offered trade clearing via the interbank market. This is basically betting against "the house" which is its own captive market-maker, has its own one-off price feed, and has its own one-off trade execution policies. As a side note, I always opt out of broker-dealers' arbitration clauses within 30 days of account opening pursuant to the U.S. Federal Arbitration Act. Unscrupulous broker-dealers and platform sellers don't even provide opt-out terms in their trading/subscription agreements, but it still exists pursuant to federal statutes and federal court precedent. Sierra Chart also collects unspent platform subscription deposits from traders in their website's online "wallet." This subjects them not only to FINRA liability but CFPB liability as well. I figuratively atom bombed Sierra Chart with this info and they refunded all platform fees and data fees that I ever paid to them before I closed my Sierra Chart account. On a more general note, virtually all broker-dealers are either partnered with, or straight up are, Wall Street investment banks and hedge funds. These are the folks that refer to retail traders as "cannon fodder" and "fish food." To me, any broker-dealer is nothing more than a counterparty to a series of my transactions. If I find any reason not to trust a broker-dealer, I'm out. Crypto trading, as it presently exists, fits the bill. Crypto owning/investment might be a different story, but I'm strictly a trader.
    • Consider this... While a human trader has emotions, a bot does not. All a human trader needs to do to code a statistically profitable strategy on a good emotional day. And it can be coded for any timeframe, intraday or overnights.
    • Well said. Broker-dealers that aren't connected to centralized exchanges or the prime interbank exchanges are, in fact, casinos--where nothing extends beyond "the house."
    • My latest trick... After successfully live trading forex for years, switch to trading futures in the U.S. Chicago Mercantile Exchanges. Futures spreads are generally 1 or 2 ticks with no swaps, and data fees and commission fees are fixed. As a caveat, leverage changes throughout every day based on international sessions, so this is not for small accounts. 
    • @analyst75, I am just dying for you to write a sequel... Why Some Young People Prefer to Live Alone.😂
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.