[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Trading platform + AB



PureBytes Links

Trading Reference Links

Hello,

I sent this last night, but today it has still not arrived (that happens to my replies every once in a while), so I am sending it again:

Hi scourt2000,

I have used languages that are high level and extremely good a GUI implementations.  They have this construct that you point out.

However, they are not actually interrupt driven, but message hierarchy driven.  It amounts to a giant code loop like AFL in actual practice.

What Herman suggests amounts to the same thing assuming we get a new AFL command and behaviors.

With the current GetCursorMouseButtons(), we get the static state of all the mouse buttons.  This is useful for certain kinds of interactions with the chart.  But what we need to do certain operations reliably is a GetCursorMouseClicks() function.  It will only be true for each mouse button for one pass after the mouse is released, and the X,Y position will be latched for the point where the mouse was released for that one pass.

We can sort of do that with the current functions by using static variables and detecting that a change has occurred in the state of the mouse buttons since the last pass.  However, we can move the mouse very fast, and AFL is slow by comparison (to me anyway).  But perhaps the operating system noticed where the mouse was clicked and can supply AB with that location. ;-)

AFL can do nothing until it runs a pass of your AFL script for a particular chart.  You can't just jump into the middle of a script because a mouse click happened on that chart and there is an ON(mouseLeftClick){} buried in there some where.

Since a script has to run for a chart for a pass after the mouse click to be recognized, one of two approaches can be used:

The first is that the chart that the mouse click is on is the only AFL that will detect THAT mouse click.  No additional GetCursorChartID()  function is required for this to fix Herman's concerns.

The second way is Herman's which was to be able to ask for the ChartID of the mouse click.

In either case the AFL is just as simple as your example (though a little more wordy).

Somewhere in the AFL you have to "specify" which mouse click and specify what to do about it.

On(rightMouseClick) {...}

or (Mouse clicks valid only for the AFL of the chart)

If(GetCursorMouseClick()==rightMouse) {...}

or (Mouse clicks sent to all charts for one pass

If(GetCursorMouseClick()==rightMouse AND GetCursorChartID() == GetChartID()) {...}

I believe that Herman's way adds a bit more flexibility, because you can have a different "chart" supervising the mouse clicks and creating a "control panel" for another chart pane.

My 2 cents.

Best regards,
Dennis

On Jan 30, 2008, at 7:09 AM, Herman wrote:

Thank you Tomasz :-) this is great news!

Once we have the Window handle we can truly make AmiBroker "INTERACTIVE". Very sophisticated processes will become simple, single, mouse clicks. imo, wrt to scalping, Chart-Trading is really the thing of the future.  In Amibroker it is possible to create VERY visually revealing charts/display that can be interpreted by the trader a hundred times faster that scrolling tables with lots of numbers - as some other software providers offer. I have tried it and the efficiency of using dynamic displays, colors, sounds, bar charts, price labels, you name it, is simply stunning. It is all possible in AB, is (again imo) far more intuitive than looking at complex charts and tables.

so much to do, so little time ...

Best regards,
herman



For tips on developing Real-Time Auto-Trading systems visit:

Wednesday, January 30, 2008, 6:47:11 AM, you wrote:

>
Hello,

 

The point is that you don't understand execution model of AB.
If you click on ANY place chart pane, all panes belonging to given chart are
refreshed. This is so because the SELECTED date/time changed for all panes
and you want your custom Title, chart values,
and indicators recalculated. There are many formulas that use SelectedValue()
to display things that depend on the selected date.

 

AFL execution is ALREADY _event_ driven. It is NOT polled. It executes ONLY when there is an event
(mouse click, real-time refresh, zoom in/out, change of current symbol, user-defined timer (RequestTimedRefresh) etc).

 

The callback idea on the surface looks attractive, but once implemented you wil
see yourself repeating lots of code or calling the same global functions over and over
again and this would inefficient.

 

For example, let's say that your indicator that you use for trading takes 0.5 second
to execute.

 

With current design, when mouse click occurs your indicator is calculated ONCE
and you can use its values stored in a variable for anything (draw chart, handle mouse clicks,
auto-trade, display alarms, perform more calculations) - all with ONE calculation
of your time-consuming indicator.

 

If your call-back driven model was implemented after mouse click the following call back
functions would be called:

 

OnLButtondDown
OnChartRefresh
OnNewDateTimeSelected

 

And you would need to calculate your indicator THREE times in each function 
if you want its values. This is because the callback approach assumes that
there is NO "global" code executed always. And this would be three times slower.

 

Actually the whole distinction about this call-back thing is rather "philosophical"
because in practice in Windows the application has SINGLE application message loop (per thread)
and messages from ALL sources land in ONE queue that is handled
by one simple loop (see PeekMessage/GetMessage/DispatchMessage)
The message is pumped to active window.
All those call-backs and what you see in higher-level languages are
just functions called from big switch and/or message map (which is also switch / if-like construct)
that is inside WindowProc function that receives all messages.

 

 

This has NOTHING to do with interrupts.  Interrupts exist on PC platform on HARDWARE level
and are used by operating system only. Interrupts are asynchronous and one interrupt can
actually stop the execution of other code to handle the interrupt.
Message processing (what software applications do) is fully sequential and message processing is
NOT interrupted (i.e. one message must be fully processed before processing next one).
I am of course speaking what happens on single thread level (not couting that your app may be switched out by pre-emptive OS)

 

For this reason, you can implement your "callback" approach by yourself, just write a switch

 

Store code below in "myCallbackHandler.afl" file in the Include folder so you can use it whenever you want

 

function EventHandler() 
local b, x, y; 
b = GetCursorMouseButtons(); 
x = GetCursorXPosition(); 
y = GetCursorYPosition(); 

if( b & 1 ) OnLMouseButton( x, y ); 
if( b & 2 ) OnRMouseButton( x, y ); 
if( b & 4 ) OnMMouseButton( x, y ); 


EventHandler(); 

 

Then in your formula put #include <mycallbackhandler.afl> at the END of the formula:

 

function OnLMouseButton(x, y) 
   _TRACE("LButton x = " + DateTimeToStr( x ) + " y = " + y ); 

function OnRMouseButton(x, y) 
   _TRACE("RButton x = " + DateTimeToStr( x ) + " y = " + y ); 

function OnMMouseButton(x, y) 
   _TRACE("MButton x = " + DateTimeToStr( x ) + " y = " + y ); 

Graph0=C
#include <mycallbackhandler.afl>

And Herman is CORRECT in his response. The only thing needed to actually know to make it work
perfectly is window handle that received the mouse click (chartID is not enough as there can be
two panes shareing the same). The ability to know window handle that received mouse click will be added.

 

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "scourt2000" <stevehite@xxxxxxxxxxx>
Sent: Wednesday, January 30, 2008 2:51 AM
Subject: [amibroker] Re: Trading platform + AB

> "This can be done now using GetCursorMouseButtons(), 
> GetCursorXPosition() and GetCursorYPosition() . HOWEVER there is no 
> function that returns the ChartID for the chartpane over which the 
> mouse is clicked"
> Hi Herman,
> All of that chartID stuff would not be necessary if you tied the 
> mouse button clicks to well-known event routines (like that ones I 
> mentioned as an example) which get called specifically from the AFL 
> code behind a chart pane.
> You want this type of facility event-driven, not polled.  Polling 
> puts more work on the user's side and brings up other unpleasant side-
> effects like what you just described.  
> Which would you rather do?  
> 1) Code a rats nest of polling inline with your other AFL code
> -or-
> 2) Have a well-known function called on a mouse click with all of the 
> information you need provided as the function parameters directed to 
> the script already bound to a particular chart pane?
> Anyone who chooses #1 last seriously programmed a computer more than 
> 20 years ago.
> "That's available now - check the list of functions, duude."
> No it's not...duude [sic]
> Please note that this group is for discussion between users only.
> To get support from AmiBroker please send an e-mail directly to 
> SUPPORT {at} amibroker.com
> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> For other support material please check also:
> Yahoo! Groups Links
> <*> To visit your group on the web, go to:
> <*> Your email settings:
>    Individual Email | Traditional
> <*> To change settings online go to:
>    (Yahoo! ID required)
> <*> To change settings via email:
> <*> To unsubscribe from this group, send an email to:
> <*> Your use of Yahoo! Groups is subject to:
>  

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___