From 4eb2e255f1e5ceab13a28577f69969d4ba72ac3b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Feb 2019 17:47:35 +0100 Subject: [PATCH 001/157] Initial commit --- .gitattributes | 2 + .gitignore | 11 + LICENSE | 661 +++++++++++++++++++++++++++ Plotters-Trading-Simulation.sln | 25 + Project.njsproj | 68 +++ README.md | 1 + TradingSimulation.js | 778 ++++++++++++++++++++++++++++++++ TradingSimulationPanel.js | 273 +++++++++++ this.plotter.config.json | 20 + 9 files changed, 1839 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Plotters-Trading-Simulation.sln create mode 100644 Project.njsproj create mode 100644 README.md create mode 100644 TradingSimulation.js create mode 100644 TradingSimulationPanel.js create mode 100644 this.plotter.config.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..dfe077042 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..82c487bdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ + +.vs/* +obj/* + +bin/* + +*.config +*.log +*.cache +node_modules/* + diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..dbbe35581 --- /dev/null +++ b/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/Plotters-Trading-Simulation.sln b/Plotters-Trading-Simulation.sln new file mode 100644 index 000000000..661fcc076 --- /dev/null +++ b/Plotters-Trading-Simulation.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2027 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "Project", "Project.njsproj", "{096B35AD-F86F-47B9-A99F-04CA93397DA8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {096B35AD-F86F-47B9-A99F-04CA93397DA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {096B35AD-F86F-47B9-A99F-04CA93397DA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {096B35AD-F86F-47B9-A99F-04CA93397DA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {096B35AD-F86F-47B9-A99F-04CA93397DA8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E75EDC9D-66A7-4C54-8EA1-5ADC148CACA8} + EndGlobalSection +EndGlobal diff --git a/Project.njsproj b/Project.njsproj new file mode 100644 index 000000000..2e95d5370 --- /dev/null +++ b/Project.njsproj @@ -0,0 +1,68 @@ + + + + Debug + 2.0 + {096b35ad-f86f-47b9-a99f-04ca93397da8} + + ShowAllFiles + TradingSimulation.js + . + . + {3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD} + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + Project + + + + + + + + + + + + + + + + + + + False + True + 0 + / + http://localhost:48022/ + False + True + http://localhost:1337 + False + + + + + + + CurrentPage + True + False + False + False + + + + + + + + + False + False + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000..d47bdb098 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Plotter Bollinger Bands diff --git a/TradingSimulation.js b/TradingSimulation.js new file mode 100644 index 000000000..96d781c85 --- /dev/null +++ b/TradingSimulation.js @@ -0,0 +1,778 @@ +function newAAMastersPlottersTradingSimulationTradingSimulation () +{ + + const MODULE_NAME = "Simulation Plotter"; + const INFO_LOG = false; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; + + let thisObject = { + + // Main functions and properties. + + initialize: initialize, + container: undefined, + getContainer: getContainer, + setTimePeriod: setTimePeriod, + setDatetime: setDatetime, + draw: draw, + recalculateScale: recalculateScale, + + /* Events declared outside the plotter. */ + + onDailyFileLoaded: onDailyFileLoaded, + + // Secondary functions and properties. + + currentRecord: undefined + }; + + /* this is part of the module template */ + + let container = newContainer(); // Do not touch this 3 lines, they are just needed. + container.initialize(); + thisObject.container = container; + + let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + + let timePeriod; // This will hold the current Time Period the user is at. + let datetime; // This will hold the current Datetime the user is at. + + let marketFile; // This is the current Market File being plotted. + let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. + + let marketFiles; // This object will provide the different Market Files at different Time Periods. + let dailyFiles; // This object will provide the different File Cursors at different Time Periods. + + /* these are module specific variables: */ + + let records = []; // Here we keep the records to be ploted every time the Draw() function is called by the AAWebPlatform. + + return thisObject; + + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + + /* Store the information received. */ + + marketFiles = pStorage.marketFiles[0]; + dailyFiles = pStorage.dailyFiles[0]; + + datetime = pDatetime; + timePeriod = pTimePeriod; + + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ + + marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. + + recalculateScale(); + + /* Now we set the right files according to current Period. */ + + marketFile = marketFiles.getFile(pTimePeriod); + fileCursor = dailyFiles.getFileCursor(pTimePeriod); + + /* Listen to the necesary events. */ + + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + + /* Get ready for plotting. */ + + recalculate(); + + callBackFunction(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); } + } + } + + function getContainer(point) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } + + let container; + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err.message = " + err.message); } + } + } + + function onFilesUpdated() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } + + let newMarketFile = marketFiles.getFile(timePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err.message = " + err.message); } + } + } + + function setTimePeriod(pTimePeriod) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } + + if (timePeriod !== pTimePeriod) { + + timePeriod = pTimePeriod; + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + let newMarketFile = marketFiles.getFile(pTimePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } else { + + let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + + if (newFileCursor !== undefined) { + + fileCursor = newFileCursor; + recalculate(); + } + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err.message = " + err.message); } + } + } + + function setDatetime(pDatetime) { + + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } + + datetime = pDatetime; + + } + + function onDailyFileLoaded(event) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onDailyFileLoaded -> Entering function."); } + + if (event.currentValue === event.totalValue) { + + /* This happens only when all of the files in the cursor have been loaded. */ + + recalculate(); + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err.message = " + err.message); } + } + } + + function draw() { + + try { + + if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); } + + this.container.frame.draw(); + + plotChart(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); } + } + } + + function recalculate() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + recalculateUsingMarketFiles(); + + } else { + + recalculateUsingDailyFiles(); + + } + + thisObject.container.eventHandler.raiseEvent("Records Changed", records); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); } + } + } + + function recalculateUsingDailyFiles() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } + + if (fileCursor === undefined) { return; } // We need to wait + + if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor + + let daysOnSides = getSideDays(timePeriod); + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + + let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + + let currentDate = new Date(farLeftDate.valueOf()); + + records = []; + + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { + + let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); + + let dailyFile = fileCursor.files.get(stringDate); + + if (dailyFile !== undefined) { + + for (let i = 0; i < dailyFile.length; i++) { + + let record = { + begin: undefined, + end: undefined, + type: undefined, + rate: undefined, + amount: undefined, + balanceA: undefined, + balanceB: undefined + }; + + record.begin = marketFile[i][0]; + record.end = marketFile[i][1]; + record.type = marketFile[i][2]; + record.rate = marketFile[i][3]; + record.amount = marketFile[i][4]; + record.balanceA = marketFile[i][5]; + record.balanceB = marketFile[i][6]; + + if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + + records.push(record); + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", thisObject.currentRecord); + + } + } + } + } + + currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS); + } + + /* Lests check if all the visible screen is going to be covered by records. */ + + let lowerEnd = leftDate.valueOf(); + let upperEnd = rightDate.valueOf(); + + if (records.length > 0) { + + if (records[0].begin > lowerEnd || records[records.length - 1].end < upperEnd) { + + setTimeout(recalculate, 2000); + + //console.log("File missing while calculating records, scheduling a recalculation in 2 seconds."); + + } + } + + //console.log("Olivia > recalculateUsingDailyFiles > total records generated : " + records.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err.message = " + err.message); } + } + } + + function recalculateUsingMarketFiles() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingMarketFiles -> Entering function."); } + + if (marketFile === undefined) { return; } // Initialization not complete yet. + + let daysOnSides = getSideDays(timePeriod); + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + + leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + + records = []; + + for (let i = 0; i < marketFile.length; i++) { + + let record = { + begin: undefined, + end: undefined, + type: undefined, + rate: undefined, + amount: undefined, + balanceA: undefined, + balanceB: undefined, + profit: undefined, + lastProfit: undefined, + stopLoss: undefined, + roundtrips: undefined, + hits: undefined, + fails: undefined, + hitRatio: undefined, + ROI: undefined, + periods: undefined, + days: undefined, + anualizedRateOfReturn: undefined, + sellRate: undefined, + lastProfitPercent: undefined + }; + + record.begin = marketFile[i][0]; + record.end = marketFile[i][1]; + record.type = marketFile[i][2]; + record.rate = marketFile[i][3]; + record.amount = marketFile[i][4]; + record.balanceA = marketFile[i][5]; + record.balanceB = marketFile[i][6]; + record.profit = marketFile[i][7]; + record.lastProfit = marketFile[i][8]; + record.stopLoss = marketFile[i][9]; + record.roundtrips = marketFile[i][10]; + record.hits = marketFile[i][11]; + record.fails = marketFile[i][12]; + record.hitRatio = marketFile[i][13]; + record.ROI = marketFile[i][14]; + record.periods = marketFile[i][15]; + record.days = marketFile[i][16]; + record.anualizedRateOfReturn = marketFile[i][17]; + record.sellRate = marketFile[i][18]; + record.lastProfitPercent = marketFile[i][19]; + + if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { + + records.push(record); + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", thisObject.currentRecord); + + } + } + } + + //console.log("Olivia > recalculateUsingMarketFiles > total records generated : " + records.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); } + } + } + + function recalculateScale() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); } + + if (marketFile === undefined) { return; } // We need the market file to be loaded to make the calculation. + + if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + + let minValue = { + x: EARLIEST_DATE.valueOf(), + y: 0 + }; + + let maxValue = { + x: MAX_PLOTABLE_DATE.valueOf(), + y: nextPorwerOf10(getMaxRate()) / 4 // TODO: This 4 is temporary + }; + + + timeLineCoordinateSystem.initialize( + minValue, + maxValue, + thisObject.container.frame.width, + thisObject.container.frame.height + ); + + function getMaxRate() { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> getMaxRate -> Entering function."); } + + let maxValue = 0; + + for (let i = 0; i < marketFile.length; i++) { + + let currentMax = 25000; // TODO Fix this, since when there are not records above 10k the scales is dissincronized with the scale of the candles. marketFile[i][3]; // 3 = rate. + + if (maxValue < currentMax) { + maxValue = currentMax; + } + } + + return maxValue; + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err.message = " + err.message); } + } + } + + function plotChart() { + + try { + + if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } + + let record; + + if (records.length > 0) { + + /* Now we calculate and plot the records */ + + for (let i = 0; i < records.length; i++) { + + record = records[i]; + + let direction = 0; + + if (record.type === 'Buy') { direction = -1; } + if (record.type === 'Sell-1') { direction = +1; } + if (record.type === 'Sell-2') { direction = +1; } + if (record.type === 'Pre-Sell') { direction = +1; } + + let recordPoint1 = { + x: record.begin + (record.end - record.begin) / 2, + y: record.rate + }; + + let recordPoint2 = { + x: record.begin + (record.end - record.begin) / 2, + y: record.rate + record.rate * 0.05 * direction + }; + + let recordPoint3 = { + x: record.begin + (record.end - record.begin) / 2, + y: record.rate + record.rate * 0.05 * direction + }; + + let recordPoint4 = { + x: record.begin, + y: record.stopLoss + }; + + let recordPoint5 = { + x: record.end, + y: record.stopLoss + }; + + if (record.stopLoss === 0) { // Put these points out of range if stopLoss is zero. + + recordPoint4.x = 0; + recordPoint5.x = 0; + + } + + let recordPoint6 = { + x: record.begin, + y: record.sellRate + }; + + let recordPoint7 = { + x: record.end, + y: record.sellRate + }; + + if (record.sellRate === 0) { // Put these points out of range if sellRate is zero. + + recordPoint6.x = 0; + recordPoint7.x = 0; + + } + + recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); + recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); + recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); + recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); + recordPoint5 = timeLineCoordinateSystem.transformThisPoint(recordPoint5); + recordPoint6 = timeLineCoordinateSystem.transformThisPoint(recordPoint6); + recordPoint7 = timeLineCoordinateSystem.transformThisPoint(recordPoint7); + + recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); + recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); + recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); + recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); + recordPoint5 = transformThisPoint(recordPoint5, thisObject.container); + recordPoint6 = transformThisPoint(recordPoint6, thisObject.container); + recordPoint7 = transformThisPoint(recordPoint7, thisObject.container); + + if (recordPoint1.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { + continue; + } + + recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); + recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); + recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); + recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); + recordPoint5 = viewPort.fitIntoVisibleArea(recordPoint5); + recordPoint6 = viewPort.fitIntoVisibleArea(recordPoint6); + recordPoint7 = viewPort.fitIntoVisibleArea(recordPoint7); + + /* Next we are drawing the stopLoss floor / ceilling */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y); + browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } + } + + browserCanvasContext.lineWidth = 1 + browserCanvasContext.stroke() + + /* Next we are drawing the sellRate */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint6.x, recordPoint6.y); + browserCanvasContext.lineTo(recordPoint7.x, recordPoint7.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', 1)'; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } + } + + browserCanvasContext.lineWidth = 1 + browserCanvasContext.stroke() + + /* Continue with the pins */ + + if (record.type !== '') { + + /* Next we are drawing the stick */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); + browserCanvasContext.lineTo(recordPoint2.x, recordPoint2.y); + + browserCanvasContext.closePath(); + + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + + let currentRecord = { + innerRecord: record + }; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; + } + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; + } + + browserCanvasContext.setLineDash([4, 2]) + browserCanvasContext.lineWidth = 0.2 + browserCanvasContext.stroke() + browserCanvasContext.setLineDash([0, 0]) + + /* We will draw a circle */ + + let radius = 5; + let color = UI_COLOR.DARK; + + if (record.type === 'Buy') { color = UI_COLOR.GREEN; } + if (record.type === 'Sell-1') { color = UI_COLOR.RUSTED_RED; } + if (record.type === 'Sell-2') { color = UI_COLOR.MANGANESE_PURPLE; } + if (record.type === 'Pre-Sell') { color = UI_COLOR.GOLDEN_ORANGE; } + + browserCanvasContext.beginPath(); + + // browserCanvasContext.moveTo(recordPoint3.x, recordPoint3.y); + browserCanvasContext.arc(recordPoint3.x, recordPoint3.y, radius, 0, Math.PI * 2, true); + + browserCanvasContext.closePath(); + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + /* highlight the current record */ + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } else { + browserCanvasContext.fillStyle = 'rgba(' + color + ', 1)'; + } + } else { + browserCanvasContext.fillStyle = 'rgba(' + color + ', 1)'; + } + + if ( + recordPoint1.x < viewPort.visibleArea.topLeft.x + 50 + || + recordPoint1.x > viewPort.visibleArea.bottomRight.x - 50 + ) { + // we leave this candles without fill. + } else { + browserCanvasContext.fill(); + } + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; + } + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; + } + + browserCanvasContext.lineWidth = 0.2; + browserCanvasContext.stroke(); + + } + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } + } + } + + + function onZoomChanged(event) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err.message = " + err.message); } + } + } + + function onOffsetChanged() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + + if (Math.random() * 100 > 95) { + + recalculate() + }; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err.message = " + err.message); } + } + } + + function onDragFinished() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onDragFinished -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err.message = " + err.message); } + } + } +} + diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js new file mode 100644 index 000000000..e700483e5 --- /dev/null +++ b/TradingSimulationPanel.js @@ -0,0 +1,273 @@ + +function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulationPanel () { + + var thisObject = { + onEventRaised: onEventRaised, + container: undefined, + draw: draw, + getContainer: getContainer, + initialize: initialize + }; + + var container = newContainer(); + container.initialize(); + thisObject.container = container; + + container.displacement.containerName = "Simulated Records Panel"; + container.frame.containerName = "Simulated Records Panel"; + + let currentRecord; + + return thisObject; + + function initialize() { + + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 1.5; + + thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1; + thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; + + } + + function getContainer(point) { + + var container; + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point, true) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } + + + function onEventRaised(lastCurrentRecord) { + + currentRecord = lastCurrentRecord; + + } + + + function draw() { + + this.container.frame.draw(false, false, true); + + plotCurrentRecordInfo(); + + } + + + function plotCurrentRecordInfo() { + + if (currentRecord === undefined) { return; } + if (currentRecord.innerRecord === undefined) { return; } + + const frameBodyHeight = thisObject.container.frame.getBodyHeight(); + const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; + + const X_AXIS = thisObject.container.frame.width / 2; + const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; + + var recordPoint1 = { + x: X_AXIS - currentRecord.bodyWidth / 2, + y: Y_AXIS - currentRecord.leftBodyHeight / 2 - currentRecord.bottomDelta / 4 + }; + + var recordPoint2 = { + x: X_AXIS - currentRecord.bodyWidth / 2, + y: Y_AXIS + currentRecord.leftBodyHeight / 2 - currentRecord.topDelta / 4 + }; + + var recordPoint3 = { + x: X_AXIS + currentRecord.bodyWidth / 2, + y: Y_AXIS + currentRecord.rightBodyHeight / 2 + currentRecord.topDelta / 4 + }; + + var recordPoint4 = { + x: X_AXIS + currentRecord.bodyWidth / 2, + y: Y_AXIS - currentRecord.rightBodyHeight / 2 + currentRecord.bottomDelta / 4 + }; + + + + /* Extra bounderies due to constrained space */ + + const upperLimit = frameTitleHeight + frameBodyHeight * 0.15; + const downLimit = frameTitleHeight + frameBodyHeight * 0.85; + + if (recordPoint1.y > downLimit) { recordPoint1.y = downLimit; } + if (recordPoint4.y > downLimit) { recordPoint4.y = downLimit; } + + if (recordPoint2.y < upperLimit) { recordPoint2.y = upperLimit; } + if (recordPoint3.y < upperLimit) { recordPoint3.y = upperLimit; } + + recordPoint1 = thisObject.container.frame.frameThisPoint(recordPoint1); + recordPoint2 = thisObject.container.frame.frameThisPoint(recordPoint2); + recordPoint3 = thisObject.container.frame.frameThisPoint(recordPoint3); + recordPoint4 = thisObject.container.frame.frameThisPoint(recordPoint4); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); + browserCanvasContext.lineTo(recordPoint2.x, recordPoint2.y); + browserCanvasContext.lineTo(recordPoint3.x, recordPoint3.y); + browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y); + + browserCanvasContext.closePath(); + + const OPACITY = '0.1'; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + OPACITY + ')'; + + browserCanvasContext.fill(); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); + browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y); + browserCanvasContext.moveTo(recordPoint2.x, recordPoint2.y); + browserCanvasContext.lineTo(recordPoint3.x, recordPoint3.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', 1)'; + + browserCanvasContext.lineWidth = 0.2; + browserCanvasContext.stroke(); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y + (recordPoint2.y - recordPoint1.y) / 2); + browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y - (recordPoint4.y - recordPoint3.y) / 2); + + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'; + + browserCanvasContext.lineWidth = 0.2; + browserCanvasContext.stroke(); + + + browserCanvasContext.beginPath(); + + /* put the labels with the records values */ + + + + + let y = 0; + let increment = 0.03; + + y = y + increment; + printLabel('Balance A', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.balanceA, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Balance B', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.balanceB, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Last Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.lastProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Last Profit %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Stop Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Roundtrips', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + y = y + increment; + printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + + function printLabel(labelToPrint, x, y, opacity) { + + let labelPoint; + let fontSize = 10; + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY; + + let label = '' + labelToPrint; + if (isNaN(label) === false) { + label = Number(label).toLocaleString(); + } + let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + + labelPoint = { + x: x - xOffset, + y: y + }; + + labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + + } + + browserCanvasContext.closePath(); + browserCanvasContext.fill(); + + } + + +} + diff --git a/this.plotter.config.json b/this.plotter.config.json new file mode 100644 index 000000000..488a19e4e --- /dev/null +++ b/this.plotter.config.json @@ -0,0 +1,20 @@ +{ + "displayName": "Plotters Trading Simulation", + "codeName": "PlottersTradingSimulation", + "devTeam": "AAMasters", + "modules": [ + { + "codeName": "TradingSimulation", + "moduleName": "TradingSimulation", + "description": "Plots Bollinger Records.", + "profilePicture": "TradingSimulation.png", + "panels": [ + { + "codeName": "TradingSimulationPanel", + "moduleName": "TradingSimulationPanel", + "event": "Current Record Changed" + } + ] + } + ] +} \ No newline at end of file From 1f3ce20e524ac3e6954c08401fa8db17c7f30744 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Feb 2019 20:28:03 +0100 Subject: [PATCH 002/157] Emojis Implemented --- TradingSimulation.js | 149 +++++++++++++++++++++++++++++++------------ 1 file changed, 108 insertions(+), 41 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 96d781c85..1d0a54673 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -1,5 +1,4 @@ -function newAAMastersPlottersTradingSimulationTradingSimulation () -{ +function newAAMastersPlottersTradingSimulationTradingSimulation() { const MODULE_NAME = "Simulation Plotter"; const INFO_LOG = false; @@ -18,11 +17,11 @@ setTimePeriod: setTimePeriod, setDatetime: setDatetime, draw: draw, - recalculateScale: recalculateScale, + recalculateScale: recalculateScale, /* Events declared outside the plotter. */ - onDailyFileLoaded: onDailyFileLoaded, + onDailyFileLoaded: onDailyFileLoaded, // Secondary functions and properties. @@ -50,6 +49,11 @@ let records = []; // Here we keep the records to be ploted every time the Draw() function is called by the AAWebPlatform. + let smileyHappy; + let smileySad; + let smileyGhost; + + return thisObject; function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { @@ -88,6 +92,28 @@ recalculate(); + /* Loading a few icons */ + + smileyHappy = loadEmoji("Smiley/Emoji Smiley-51.png"); + smileySad = loadEmoji("Smiley/Emoji Smiley-26.png"); + smileyGhost = loadEmoji("Objects/Emoji Objects-12.png"); + + function loadEmoji(pPath) { + + let newImage; + + newImage = new Image(); + newImage.onload = onImageLoaded; + + function onImageLoaded() { + newImage.isLoaded = true; + } + + newImage.src = window.canvasApp.urlPrefix + "Images/Emoji/" + pPath; + + return newImage; + } + callBackFunction(); } catch (err) { @@ -384,7 +410,8 @@ days: undefined, anualizedRateOfReturn: undefined, sellRate: undefined, - lastProfitPercent: undefined + lastProfitPercent: undefined, + signal: undefined }; record.begin = marketFile[i][0]; @@ -407,6 +434,7 @@ record.anualizedRateOfReturn = marketFile[i][17]; record.sellRate = marketFile[i][18]; record.lastProfitPercent = marketFile[i][19]; + record.signal = marketFile[i][20]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -503,7 +531,7 @@ if (record.type === 'Buy') { direction = -1; } if (record.type === 'Sell-1') { direction = +1; } if (record.type === 'Sell-2') { direction = +1; } - if (record.type === 'Pre-Sell') { direction = +1; } + if (record.signal === 'Pre-Sell') { direction = +1; } let recordPoint1 = { x: record.begin + (record.end - record.begin) / 2, @@ -599,7 +627,7 @@ /* highlight the current record */ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + } } browserCanvasContext.lineWidth = 1 @@ -630,7 +658,7 @@ /* Continue with the pins */ - if (record.type !== '') { + if (record.type !== '' || record.signal !== '') { /* Next we are drawing the stick */ @@ -660,7 +688,7 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; } - browserCanvasContext.setLineDash([4, 2]) + browserCanvasContext.setLineDash([4, 3]) browserCanvasContext.lineWidth = 0.2 browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) @@ -670,54 +698,91 @@ let radius = 5; let color = UI_COLOR.DARK; - if (record.type === 'Buy') { color = UI_COLOR.GREEN; } - if (record.type === 'Sell-1') { color = UI_COLOR.RUSTED_RED; } - if (record.type === 'Sell-2') { color = UI_COLOR.MANGANESE_PURPLE; } - if (record.type === 'Pre-Sell') { color = UI_COLOR.GOLDEN_ORANGE; } + browserCanvasContext.beginPath(); - // browserCanvasContext.moveTo(recordPoint3.x, recordPoint3.y); - browserCanvasContext.arc(recordPoint3.x, recordPoint3.y, radius, 0, Math.PI * 2, true); + let imageSize = 20; + let imageToDraw; - browserCanvasContext.closePath(); + let line1; + let line2; + + if (record.type === 'Buy') { + + line1 = 'Buying back.'; + + if (record.lastProfit < 0) { + + line2 = 'Lost ' + (record.lastProfit * 100).toFixed(2) + ' %'; + imageToDraw = smileySad; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { - /* highlight the current record */ - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } else { - browserCanvasContext.fillStyle = 'rgba(' + color + ', 1)'; + + line2 = 'Won ' + (record.lastProfit * 100).toFixed(2) + ' %'; + imageToDraw = smileyHappy; } - } else { - browserCanvasContext.fillStyle = 'rgba(' + color + ', 1)'; + } + if (record.type === 'Sell-1') { + + line1 = 'Sold because '; + line2 = 'market reversed.'; + + imageToDraw = smileyHappy; + } + if (record.type === 'Sell-2') { + + line1 = 'Sold because '; + line2 = 'resistance collapsed.'; + + imageToDraw = smileyHappy; + } + if (record.signal === 'Pre-Sell') { + + line1 = 'Time to Sell!'; + line2 = ''; + + imageToDraw = smileyGhost; + } + + if (smileyHappy.isLoaded === true) { + browserCanvasContext.drawImage(imageToDraw, recordPoint3.x - imageSize / 2, recordPoint3.y - imageSize / 2, imageSize, imageSize); + } + if ( - recordPoint1.x < viewPort.visibleArea.topLeft.x + 50 + recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 || - recordPoint1.x > viewPort.visibleArea.bottomRight.x - 50 + recordPoint3.x > viewPort.visibleArea.bottomRight.x - 250 + || + recordPoint3.y > viewPort.visibleArea.bottomRight.y - 150 + || + recordPoint3.y < viewPort.visibleArea.topLeft.y + 150 ) { - // we leave this candles without fill. + // we do not write any text } else { - browserCanvasContext.fill(); + printLabel(line1, recordPoint3.x + imageSize / 2 + 5, recordPoint3.y + 0, '0.50'); + printLabel(line2, recordPoint3.x + imageSize / 2 + 5, recordPoint3.y + 15, '0.50'); } - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } else { - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; - } - } else { - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; - } - browserCanvasContext.lineWidth = 0.2; - browserCanvasContext.stroke(); + + function printLabel(labelToPrint, x, y, opacity) { + + let labelPoint; + let fontSize = 12; + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY; + + let label = '' + labelToPrint; + + let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillText(label, x, y); + + } } } @@ -776,3 +841,5 @@ } } + + From 7bb42aa3fa04ba4c7db5222e31cdd7393713e5c1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Feb 2019 21:00:12 +0100 Subject: [PATCH 003/157] Monkey added --- TradingSimulation.js | 68 +++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 1d0a54673..a168ccd7c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -52,6 +52,7 @@ let smileyHappy; let smileySad; let smileyGhost; + let smileyMonkeyEyes; return thisObject; @@ -97,6 +98,7 @@ smileyHappy = loadEmoji("Smiley/Emoji Smiley-51.png"); smileySad = loadEmoji("Smiley/Emoji Smiley-26.png"); smileyGhost = loadEmoji("Objects/Emoji Objects-12.png"); + smileyMonkeyEyes = loadEmoji("Smiley/Emoji Smiley-85.png"); function loadEmoji(pPath) { @@ -540,45 +542,40 @@ let recordPoint2 = { x: record.begin + (record.end - record.begin) / 2, - y: record.rate + record.rate * 0.05 * direction + y: 0 }; let recordPoint3 = { - x: record.begin + (record.end - record.begin) / 2, - y: record.rate + record.rate * 0.05 * direction - }; - - let recordPoint4 = { x: record.begin, y: record.stopLoss }; - let recordPoint5 = { + let recordPoint4 = { x: record.end, y: record.stopLoss }; if (record.stopLoss === 0) { // Put these points out of range if stopLoss is zero. + recordPoint3.x = 0; recordPoint4.x = 0; - recordPoint5.x = 0; } - let recordPoint6 = { + let recordPoint5 = { x: record.begin, y: record.sellRate }; - let recordPoint7 = { + let recordPoint6 = { x: record.end, y: record.sellRate }; if (record.sellRate === 0) { // Put these points out of range if sellRate is zero. + recordPoint5.x = 0; recordPoint6.x = 0; - recordPoint7.x = 0; } @@ -588,7 +585,6 @@ recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); recordPoint5 = timeLineCoordinateSystem.transformThisPoint(recordPoint5); recordPoint6 = timeLineCoordinateSystem.transformThisPoint(recordPoint6); - recordPoint7 = timeLineCoordinateSystem.transformThisPoint(recordPoint7); recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); @@ -596,26 +592,26 @@ recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); recordPoint5 = transformThisPoint(recordPoint5, thisObject.container); recordPoint6 = transformThisPoint(recordPoint6, thisObject.container); - recordPoint7 = transformThisPoint(recordPoint7, thisObject.container); if (recordPoint1.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { continue; } + recordPoint2.y = recordPoint1.y - 150 * direction; + recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); recordPoint5 = viewPort.fitIntoVisibleArea(recordPoint5); recordPoint6 = viewPort.fitIntoVisibleArea(recordPoint6); - recordPoint7 = viewPort.fitIntoVisibleArea(recordPoint7); /* Next we are drawing the stopLoss floor / ceilling */ browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y); - browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y); + browserCanvasContext.moveTo(recordPoint3.x, recordPoint3.y); + browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y); browserCanvasContext.closePath(); @@ -637,8 +633,8 @@ browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint6.x, recordPoint6.y); - browserCanvasContext.lineTo(recordPoint7.x, recordPoint7.y); + browserCanvasContext.moveTo(recordPoint5.x, recordPoint5.y); + browserCanvasContext.lineTo(recordPoint6.x, recordPoint6.y); browserCanvasContext.closePath(); @@ -656,6 +652,10 @@ browserCanvasContext.lineWidth = 1 browserCanvasContext.stroke() + + + + /* Continue with the pins */ if (record.type !== '' || record.signal !== '') { @@ -708,6 +708,14 @@ let line1; let line2; + if (record.signal === 'Pre-Sell') { + + line1 = 'Time to Sell!'; + line2 = ''; + + imageToDraw = smileyGhost; + } + if (record.type === 'Buy') { line1 = 'Buying back.'; @@ -729,7 +737,7 @@ line1 = 'Sold because '; line2 = 'market reversed.'; - imageToDraw = smileyHappy; + imageToDraw = smileyMonkeyEyes; } if (record.type === 'Sell-2') { @@ -738,32 +746,26 @@ imageToDraw = smileyHappy; } - if (record.signal === 'Pre-Sell') { - line1 = 'Time to Sell!'; - line2 = ''; - - imageToDraw = smileyGhost; - } if (smileyHappy.isLoaded === true) { - browserCanvasContext.drawImage(imageToDraw, recordPoint3.x - imageSize / 2, recordPoint3.y - imageSize / 2, imageSize, imageSize); + browserCanvasContext.drawImage(imageToDraw, recordPoint2.x - imageSize / 2, recordPoint2.y - imageSize / 2, imageSize, imageSize); } if ( - recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 + recordPoint2.x < viewPort.visibleArea.topLeft.x + 250 || - recordPoint3.x > viewPort.visibleArea.bottomRight.x - 250 + recordPoint2.x > viewPort.visibleArea.bottomRight.x - 250 || - recordPoint3.y > viewPort.visibleArea.bottomRight.y - 150 + recordPoint2.y > viewPort.visibleArea.bottomRight.y - 100 || - recordPoint3.y < viewPort.visibleArea.topLeft.y + 150 + recordPoint2.y < viewPort.visibleArea.topLeft.y + 100 ) { // we do not write any text } else { - printLabel(line1, recordPoint3.x + imageSize / 2 + 5, recordPoint3.y + 0, '0.50'); - printLabel(line2, recordPoint3.x + imageSize / 2 + 5, recordPoint3.y + 15, '0.50'); + printLabel(line1, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 0, '0.50'); + printLabel(line2, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 15, '0.50'); } @@ -843,3 +845,5 @@ + + From 1f9ce2648533c18a4d25bea420ba196c0d296ab3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Feb 2019 21:17:34 +0100 Subject: [PATCH 004/157] Text overlapping problem solved --- TradingSimulation.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index a168ccd7c..99ff34689 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -519,6 +519,7 @@ if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } let record; + lastImage = 0; if (records.length > 0) { @@ -660,6 +661,16 @@ if (record.type !== '' || record.signal !== '') { + let noText = false; + + if (lastImage < 5) { + noText = true; // we avoid image texts to overlap. + } else { + noText = false; + lastImage = 0; + } + + /* Next we are drawing the stick */ browserCanvasContext.beginPath(); @@ -764,8 +775,10 @@ ) { // we do not write any text } else { - printLabel(line1, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 0, '0.50'); - printLabel(line2, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 15, '0.50'); + if (noText === false) { + printLabel(line1, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 0, '0.50'); + printLabel(line2, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 15, '0.50'); + } } @@ -786,6 +799,8 @@ } + } else { + lastImage++; } } } From 7c96d2961b185ee1a31b173d40dad8ce0a22933f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Feb 2019 15:17:10 +0100 Subject: [PATCH 005/157] Text Improvements --- TradingSimulation.js | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 99ff34689..478a0c81f 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -518,8 +518,10 @@ if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } + let direction let record; - lastImage = 0; + let lastImageUp = 0; + let lastImageDown = 0; if (records.length > 0) { @@ -529,7 +531,7 @@ record = records[i]; - let direction = 0; + direction = 0; if (record.type === 'Buy') { direction = -1; } if (record.type === 'Sell-1') { direction = +1; } @@ -661,16 +663,27 @@ if (record.type !== '' || record.signal !== '') { - let noText = false; + let noTextUp = false; + let noTextDown = false; - if (lastImage < 5) { - noText = true; // we avoid image texts to overlap. + if (direction > 0) { + if (lastImageUp < 5) { + noTextUp = true; // we avoid image texts to overlap. + } else { + noTextUp = false; + lastImageUp = 0; + } } else { - noText = false; - lastImage = 0; + if (lastImageDown < 5) { + noTextDown = true; // we avoid image texts to overlap. + } else { + noTextDown = false; + lastImageDown = 0; + } } + /* Next we are drawing the stick */ browserCanvasContext.beginPath(); @@ -775,7 +788,10 @@ ) { // we do not write any text } else { - if (noText === false) { + if ( + (direction > 0 && noTextUp === false) || + (direction < 0 && noTextDown === false) + ) { printLabel(line1, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 0, '0.50'); printLabel(line2, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 15, '0.50'); } @@ -800,7 +816,9 @@ } } else { - lastImage++; + + lastImageUp++; + lastImageDown++; } } } From b8d6f29420a8d666c03521e8d8a704c2545bba8a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Feb 2019 22:46:17 +0100 Subject: [PATCH 006/157] Strategies and Phases working --- TradingSimulation.js | 632 +++++++++++++++++++++++++++---------------- 1 file changed, 393 insertions(+), 239 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 478a0c81f..57e12602b 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -53,7 +53,8 @@ let smileySad; let smileyGhost; let smileyMonkeyEyes; - + let imageStrategy; + let imageStrategyPhase; return thisObject; @@ -99,6 +100,9 @@ smileySad = loadEmoji("Smiley/Emoji Smiley-26.png"); smileyGhost = loadEmoji("Objects/Emoji Objects-12.png"); smileyMonkeyEyes = loadEmoji("Smiley/Emoji Smiley-85.png"); + imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); + imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); + function loadEmoji(pPath) { @@ -413,7 +417,9 @@ anualizedRateOfReturn: undefined, sellRate: undefined, lastProfitPercent: undefined, - signal: undefined + signal: undefined, + strategy: undefined, + strategyPhase: undefined }; record.begin = marketFile[i][0]; @@ -437,6 +443,8 @@ record.sellRate = marketFile[i][18]; record.lastProfitPercent = marketFile[i][19]; record.signal = marketFile[i][20]; + record.strategy = marketFile[i][21]; + record.strategyPhase = marketFile[i][22]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -518,107 +526,271 @@ if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } - let direction + let directionShort; + let directionLong; + let record; - let lastImageUp = 0; - let lastImageDown = 0; + let lastShortImageUp = 0; + let lastShortImageDown = 0; + let lastLongImageUp = 0; + let lastLongImageDown = 0; - if (records.length > 0) { + /* Now we calculate and plot the records */ - /* Now we calculate and plot the records */ + for (let i = 1; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 - for (let i = 0; i < records.length; i++) { + record = records[i]; + directionShort = 0; + let strategy = 0; + let strategyPhase = 0; - record = records[i]; + if (record.strategy !== records[i - 1].strategy) { // When a change in the strategy field is detected, it is time to plot it. + strategy = record.strategy; + } - direction = 0; + if (record.strategyPhase !== records[i - 1].strategyPhase) { // When a change in the strategy phase field is detected, it is time to plot it. + strategyPhase = record.strategyPhase; + } - if (record.type === 'Buy') { direction = -1; } - if (record.type === 'Sell-1') { direction = +1; } - if (record.type === 'Sell-2') { direction = +1; } - if (record.signal === 'Pre-Sell') { direction = +1; } + if (record.type === 'Buy') { directionShort = -1; } + if (record.type === 'Sell-1') { directionShort = +1; } + if (record.type === 'Sell-2') { directionShort = +1; } + if (record.signal === 'Pre-Sell') { directionShort = +1; } - let recordPoint1 = { - x: record.begin + (record.end - record.begin) / 2, - y: record.rate - }; + if (strategyPhase > 0) { + if (strategyPhase % 2 !== 0) { //Depending if the phase is oddd or even goes above or below. + directionLong = 1; + } else { + directionLong = -1; + } + } - let recordPoint2 = { - x: record.begin + (record.end - record.begin) / 2, - y: 0 - }; + if (strategy > 0) { + directionLong = -1; + } - let recordPoint3 = { - x: record.begin, - y: record.stopLoss - }; + let recordPoint1 = { + x: record.begin + (record.end - record.begin) / 2, + y: record.rate + }; - let recordPoint4 = { - x: record.end, - y: record.stopLoss - }; + let recordPoint2 = { // Long Stick Head + x: record.begin + (record.end - record.begin) / 2, + y: 0 + }; - if (record.stopLoss === 0) { // Put these points out of range if stopLoss is zero. + let recordPoint3 = { // Short Stick Head + x: record.begin + (record.end - record.begin) / 2, + y: 0 + }; - recordPoint3.x = 0; - recordPoint4.x = 0; + let recordPoint4 = { + x: record.begin, + y: record.stopLoss + }; + let recordPoint5 = { + x: record.end, + y: record.stopLoss + }; + + if (record.stopLoss === 0) { // Put these points out of range if stopLoss is zero. + + recordPoint4.x = 0; + recordPoint5.x = 0; + + } + + let recordPoint6 = { + x: record.begin, + y: record.sellRate + }; + + let recordPoint7 = { + x: record.end, + y: record.sellRate + }; + + if (record.sellRate === 0) { // Put these points out of range if sellRate is zero. + + recordPoint6.x = 0; + recordPoint7.x = 0; + + } + + recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); + recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); + recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); + recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); + recordPoint5 = timeLineCoordinateSystem.transformThisPoint(recordPoint5); + recordPoint6 = timeLineCoordinateSystem.transformThisPoint(recordPoint6); + recordPoint7 = timeLineCoordinateSystem.transformThisPoint(recordPoint7); + + recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); + recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); + recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); + recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); + recordPoint5 = transformThisPoint(recordPoint5, thisObject.container); + recordPoint6 = transformThisPoint(recordPoint6, thisObject.container); + recordPoint7 = transformThisPoint(recordPoint7, thisObject.container); + + if (recordPoint1.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { + continue; + } + + recordPoint2.y = recordPoint1.y - 250 * directionLong; + recordPoint3.y = recordPoint1.y - 150 * directionShort; + + recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); + recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); + recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); + recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); + recordPoint5 = viewPort.fitIntoVisibleArea(recordPoint5); + recordPoint6 = viewPort.fitIntoVisibleArea(recordPoint6); + recordPoint7 = viewPort.fitIntoVisibleArea(recordPoint7); + + /* Next we are drawing the stopLoss floor / ceilling */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y); + browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } + } + + browserCanvasContext.lineWidth = 1 + browserCanvasContext.stroke() + + /* Next we are drawing the sellRate */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint6.x, recordPoint6.y); + browserCanvasContext.lineTo(recordPoint7.x, recordPoint7.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', 1)'; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } + } + + browserCanvasContext.lineWidth = 1 + browserCanvasContext.stroke() + + + /* Continue with the pins --> Next stuff is to avoid text overlapping. */ + + let noShortTextUp = false; + let noShortTextDown = false; + + if ( + record.type !== '' || + record.signal !== '' + ) { + + if (directionShort > 0) { + if (lastShortImageUp < 5) { + noShortTextUp = true; // we avoid image texts to overlap. + } else { + noShortTextUp = false; + lastShortImageUp = 0; + } + } else { + if (lastShortImageDown < 5) { + noShortTextDown = true; // we avoid image texts to overlap. + } else { + noShortTextDown = false; + lastShortImageDown = 0; + } } - let recordPoint5 = { - x: record.begin, - y: record.sellRate - }; + } else { - let recordPoint6 = { - x: record.end, - y: record.sellRate - }; + lastShortImageUp++; + lastShortImageDown++; + } - if (record.sellRate === 0) { // Put these points out of range if sellRate is zero. + let noLongTextUp = false; + let noLongTextDown = false; - recordPoint5.x = 0; - recordPoint6.x = 0; + if ( + strategy > 0 || + strategyPhase > 0 + ) { + if (directionLong > 0) { + if (lastLongImageUp < 5) { + noLongTextUp = true; // we avoid image texts to overlap. + } else { + noLongTextUp = false; + lastLongImageUp = 0; + } + } else { + if (lastLongImageDown < 3) { + noLongTextDown = true; // we avoid image texts to overlap. + } else { + noLongTextDown = false; + lastLongImageDown = 0; + } } - recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); - recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); - recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); - recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); - recordPoint5 = timeLineCoordinateSystem.transformThisPoint(recordPoint5); - recordPoint6 = timeLineCoordinateSystem.transformThisPoint(recordPoint6); + } else { - recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); - recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); - recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); - recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); - recordPoint5 = transformThisPoint(recordPoint5, thisObject.container); - recordPoint6 = transformThisPoint(recordPoint6, thisObject.container); + lastLongImageUp++; + lastLongImageDown++; + } - if (recordPoint1.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { - continue; - } - recordPoint2.y = recordPoint1.y - 150 * direction; + if ( + strategy > 0 || + strategyPhase > 0 + ) { - recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); - recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); - recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); - recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); - recordPoint5 = viewPort.fitIntoVisibleArea(recordPoint5); - recordPoint6 = viewPort.fitIntoVisibleArea(recordPoint6); + /* Next we are drawing the LONG stick */ - /* Next we are drawing the stopLoss floor / ceilling */ + drawStick(recordPoint2); + + } + + if ( + record.type !== '' || + record.signal !== '' + ) { + + /* Next we are drawing the SHORT stick */ + + drawStick(recordPoint3); + + } + + function drawStick(headPoint) { browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint3.x, recordPoint3.y); - browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y); + browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); + browserCanvasContext.lineTo(headPoint.x, headPoint.y); browserCanvasContext.closePath(); - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'; + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.25)'; if (datetime !== undefined) { let dateValue = datetime.valueOf(); @@ -626,203 +798,183 @@ /* highlight the current record */ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + + let currentRecord = { + innerRecord: record + }; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); } } - browserCanvasContext.lineWidth = 1 + browserCanvasContext.setLineDash([4, 3]) + browserCanvasContext.lineWidth = 0.2 browserCanvasContext.stroke() + browserCanvasContext.setLineDash([0, 0]) - /* Next we are drawing the sellRate */ + } - browserCanvasContext.beginPath(); + //browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint5.x, recordPoint5.y); - browserCanvasContext.lineTo(recordPoint6.x, recordPoint6.y); + let imageSize = 20; + let imageToDraw; - browserCanvasContext.closePath(); + let line1; + let line2; - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', 1)'; + longPinHead(); + shortPinHead(); - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + function longPinHead() { - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + if (strategyPhase > 0) { + + line1 = 'Entering into '; + line2 = 'Phase ' + strategyPhase; + + imageToDraw = imageStrategyPhase; + } + if (strategy === 1) { + + line1 = 'Trend Following '; + line2 = 'strategy started.'; + + imageToDraw = imageStrategy; + } + if (strategy === 2) { + + line1 = 'Range Trading '; + line2 = 'strategy started.'; + + imageToDraw = imageStrategy; } - browserCanvasContext.lineWidth = 1 - browserCanvasContext.stroke() + if (imageToDraw !== undefined) { - - - - - /* Continue with the pins */ - - if (record.type !== '' || record.signal !== '') { - - let noTextUp = false; - let noTextDown = false; - - if (direction > 0) { - if (lastImageUp < 5) { - noTextUp = true; // we avoid image texts to overlap. - } else { - noTextUp = false; - lastImageUp = 0; - } - } else { - if (lastImageDown < 5) { - noTextDown = true; // we avoid image texts to overlap. - } else { - noTextDown = false; - lastImageDown = 0; - } - } - - - - /* Next we are drawing the stick */ - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); - browserCanvasContext.lineTo(recordPoint2.x, recordPoint2.y); - - browserCanvasContext.closePath(); - - - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { - - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - - let currentRecord = { - innerRecord: record - }; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); - } else { - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; - } - } else { - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 1)'; - } - - browserCanvasContext.setLineDash([4, 3]) - browserCanvasContext.lineWidth = 0.2 - browserCanvasContext.stroke() - browserCanvasContext.setLineDash([0, 0]) - - /* We will draw a circle */ - - let radius = 5; - let color = UI_COLOR.DARK; - - - - browserCanvasContext.beginPath(); - - let imageSize = 20; - let imageToDraw; - - let line1; - let line2; - - if (record.signal === 'Pre-Sell') { - - line1 = 'Time to Sell!'; - line2 = ''; - - imageToDraw = smileyGhost; - } - - if (record.type === 'Buy') { - - line1 = 'Buying back.'; - - if (record.lastProfit < 0) { - - line2 = 'Lost ' + (record.lastProfit * 100).toFixed(2) + ' %'; - imageToDraw = smileySad; - - } else { - - line2 = 'Won ' + (record.lastProfit * 100).toFixed(2) + ' %'; - imageToDraw = smileyHappy; - } - - } - if (record.type === 'Sell-1') { - - line1 = 'Sold because '; - line2 = 'market reversed.'; - - imageToDraw = smileyMonkeyEyes; - } - if (record.type === 'Sell-2') { - - line1 = 'Sold because '; - line2 = 'resistance collapsed.'; - - imageToDraw = smileyHappy; - } - - - if (smileyHappy.isLoaded === true) { + if (imageToDraw.isLoaded === true) { browserCanvasContext.drawImage(imageToDraw, recordPoint2.x - imageSize / 2, recordPoint2.y - imageSize / 2, imageSize, imageSize); + imageToDraw = undefined; } + } + if ( + recordPoint2.x < viewPort.visibleArea.topLeft.x + 250 + || + recordPoint2.x > viewPort.visibleArea.bottomRight.x - 250 + || + recordPoint2.y > viewPort.visibleArea.bottomRight.y - 100 + || + recordPoint2.y < viewPort.visibleArea.topLeft.y + 100 + ) { + // we do not write any text + } else { + if (line1 !== undefined) { - if ( - recordPoint2.x < viewPort.visibleArea.topLeft.x + 250 - || - recordPoint2.x > viewPort.visibleArea.bottomRight.x - 250 - || - recordPoint2.y > viewPort.visibleArea.bottomRight.y - 100 - || - recordPoint2.y < viewPort.visibleArea.topLeft.y + 100 - ) { - // we do not write any text - } else { if ( - (direction > 0 && noTextUp === false) || - (direction < 0 && noTextDown === false) + (directionLong > 0 && noLongTextUp === false) || + (directionLong < 0 && noLongTextDown === false) ) { printLabel(line1, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 0, '0.50'); printLabel(line2, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 15, '0.50'); } } - - - - function printLabel(labelToPrint, x, y, opacity) { - - let labelPoint; - let fontSize = 12; - - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY; - - let label = '' + labelToPrint; - - let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; - browserCanvasContext.fillText(label, x, y); - - } - - } else { - - lastImageUp++; - lastImageDown++; } } + + function shortPinHead() { + + if (record.signal === 'Pre-Sell') { + + line1 = 'Sell as soon as Bollinger'; + line2 = 'moving average heads down.'; + + imageToDraw = smileyGhost; + } + + if (record.type === 'Buy') { + + line1 = 'Buying back.'; + + if (record.lastProfit < 0) { + + line2 = 'Lost ' + (record.lastProfit * 100).toFixed(2) + ' %'; + imageToDraw = smileySad; + + } else { + + line2 = 'Won ' + (record.lastProfit * 100).toFixed(2) + ' %'; + imageToDraw = smileyHappy; + } + + } + if (record.type === 'Sell-1') { + + line1 = 'Sold because '; + line2 = 'market reversed.'; + + imageToDraw = smileyMonkeyEyes; + } + if (record.type === 'Sell-2') { + + line1 = 'Sold because '; + line2 = 'resistance collapsed.'; + + imageToDraw = smileyHappy; + } + + if (imageToDraw !== undefined) { + + if (imageToDraw.isLoaded === true) { + browserCanvasContext.drawImage(imageToDraw, recordPoint3.x - imageSize / 2, recordPoint3.y - imageSize / 2, imageSize, imageSize); + imageToDraw = undefined; + } + } + + if ( + recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 + || + recordPoint3.x > viewPort.visibleArea.bottomRight.x - 250 + || + recordPoint3.y > viewPort.visibleArea.bottomRight.y - 100 + || + recordPoint3.y < viewPort.visibleArea.topLeft.y + 100 + ) { + // we do not write any text + } else { + if (line1 !== undefined) { + if ( + (directionShort > 0 && noShortTextUp === false) || + (directionShort < 0 && noShortTextDown === false) + ) { + printLabel(line1, recordPoint3.x + imageSize / 2 + 5, recordPoint3.y + 0, '0.50'); + printLabel(line2, recordPoint3.x + imageSize / 2 + 5, recordPoint3.y + 15, '0.50'); + } + } + } + } + + + /* This is how we write the text */ + + function printLabel(labelToPrint, x, y, opacity) { + + let labelPoint; + let fontSize = 12; + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY; + + let label = '' + labelToPrint; + + let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillText(label, x, y); + + } + + } + } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } @@ -880,3 +1032,5 @@ + + From 5e166d8b5d7539152bb5ba3b30c109a9ed0a45ca Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Feb 2019 23:12:00 +0100 Subject: [PATCH 007/157] Monkey Ears --- TradingSimulation.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 57e12602b..96d40ea3c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -53,6 +53,7 @@ let smileySad; let smileyGhost; let smileyMonkeyEyes; + let smileyMonkeyEars; let imageStrategy; let imageStrategyPhase; @@ -100,6 +101,7 @@ smileySad = loadEmoji("Smiley/Emoji Smiley-26.png"); smileyGhost = loadEmoji("Objects/Emoji Objects-12.png"); smileyMonkeyEyes = loadEmoji("Smiley/Emoji Smiley-85.png"); + smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); @@ -918,7 +920,7 @@ line1 = 'Sold because '; line2 = 'resistance collapsed.'; - imageToDraw = smileyHappy; + imageToDraw = smileyMonkeyEars; } if (imageToDraw !== undefined) { From 8ade9c4bcf1cf845b3a3e063924f4340adbffdf0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 27 Feb 2019 13:57:51 +0100 Subject: [PATCH 008/157] Buy Order Implemented --- TradingSimulation.js | 79 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 96d40ea3c..0891649a0 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -421,7 +421,8 @@ lastProfitPercent: undefined, signal: undefined, strategy: undefined, - strategyPhase: undefined + strategyPhase: undefined, + buyOrder: undefined }; record.begin = marketFile[i][0]; @@ -447,6 +448,7 @@ record.signal = marketFile[i][20]; record.strategy = marketFile[i][21]; record.strategyPhase = marketFile[i][22]; + record.buyOrder = marketFile[i][23]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -554,7 +556,8 @@ strategyPhase = record.strategyPhase; } - if (record.type === 'Buy') { directionShort = -1; } + if (record.type === 'Buy@BuyOrder') { directionShort = -1; } + if (record.type === 'Buy@StopLoss') { directionShort = 1; } if (record.type === 'Sell-1') { directionShort = +1; } if (record.type === 'Sell-2') { directionShort = +1; } if (record.signal === 'Pre-Sell') { directionShort = +1; } @@ -600,7 +603,6 @@ recordPoint4.x = 0; recordPoint5.x = 0; - } let recordPoint6 = { @@ -617,7 +619,22 @@ recordPoint6.x = 0; recordPoint7.x = 0; + } + let recordPoint8 = { + x: record.begin, + y: record.buyOrder + }; + + let recordPoint9 = { + x: record.end, + y: record.buyOrder + }; + + if (record.buyOrder === 0) { // Put these points out of range if buyOrder is zero. + + recordPoint8.x = 0; + recordPoint9.x = 0; } recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); @@ -627,6 +644,8 @@ recordPoint5 = timeLineCoordinateSystem.transformThisPoint(recordPoint5); recordPoint6 = timeLineCoordinateSystem.transformThisPoint(recordPoint6); recordPoint7 = timeLineCoordinateSystem.transformThisPoint(recordPoint7); + recordPoint8 = timeLineCoordinateSystem.transformThisPoint(recordPoint8); + recordPoint9 = timeLineCoordinateSystem.transformThisPoint(recordPoint9); recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); @@ -635,6 +654,8 @@ recordPoint5 = transformThisPoint(recordPoint5, thisObject.container); recordPoint6 = transformThisPoint(recordPoint6, thisObject.container); recordPoint7 = transformThisPoint(recordPoint7, thisObject.container); + recordPoint8 = transformThisPoint(recordPoint8, thisObject.container); + recordPoint9 = transformThisPoint(recordPoint9, thisObject.container); if (recordPoint1.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { continue; @@ -650,6 +671,8 @@ recordPoint5 = viewPort.fitIntoVisibleArea(recordPoint5); recordPoint6 = viewPort.fitIntoVisibleArea(recordPoint6); recordPoint7 = viewPort.fitIntoVisibleArea(recordPoint7); + recordPoint8 = viewPort.fitIntoVisibleArea(recordPoint8); + recordPoint9 = viewPort.fitIntoVisibleArea(recordPoint9); /* Next we are drawing the stopLoss floor / ceilling */ @@ -683,6 +706,31 @@ browserCanvasContext.closePath(); + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } + } + + browserCanvasContext.setLineDash([1, 4]) + browserCanvasContext.lineWidth = 1 + browserCanvasContext.stroke() + browserCanvasContext.setLineDash([0, 0]) + + /* Next we are drawing the Buy Order */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint8.x, recordPoint8.y); + browserCanvasContext.lineTo(recordPoint9.x, recordPoint9.y); + + browserCanvasContext.closePath(); + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', 1)'; if (datetime !== undefined) { @@ -697,7 +745,6 @@ browserCanvasContext.lineWidth = 1 browserCanvasContext.stroke() - /* Continue with the pins --> Next stuff is to avoid text overlapping. */ let noShortTextUp = false; @@ -830,22 +877,22 @@ if (strategyPhase > 0) { - line1 = 'Entering into '; - line2 = 'Phase ' + strategyPhase; + line1 = ''; + line2 = strategyPhase; imageToDraw = imageStrategyPhase; } if (strategy === 1) { - line1 = 'Trend Following '; - line2 = 'strategy started.'; + line1 = 'Trend Following'; + line2 = ''; imageToDraw = imageStrategy; } if (strategy === 2) { - line1 = 'Range Trading '; - line2 = 'strategy started.'; + line1 = 'Range Trading'; + line2 = ''; imageToDraw = imageStrategy; } @@ -892,10 +939,17 @@ imageToDraw = smileyGhost; } - if (record.type === 'Buy') { + if (record.type === 'Buy@StopLoss' || record.type === 'Buy@BuyOrder') { - line1 = 'Buying back.'; + if (record.type === 'Buy@StopLoss') { + line1 = 'Buying at Stop Loss.'; + + } else { + + line1 = 'Buying at Buy Order.'; + } + if (record.lastProfit < 0) { line2 = 'Lost ' + (record.lastProfit * 100).toFixed(2) + ' %'; @@ -1036,3 +1090,4 @@ + From 6dc65b38367ffb329f5c7a4c8a38cb42880fddcc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 27 Feb 2019 15:34:59 +0100 Subject: [PATCH 009/157] Bug on % displayed --- TradingSimulation.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 0891649a0..95c3281c5 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -590,12 +590,12 @@ }; let recordPoint4 = { - x: record.begin, + x: record.begin + timePeriod, y: record.stopLoss }; let recordPoint5 = { - x: record.end, + x: record.end + timePeriod, y: record.stopLoss }; @@ -606,12 +606,12 @@ } let recordPoint6 = { - x: record.begin, + x: record.begin + timePeriod, y: record.sellRate }; let recordPoint7 = { - x: record.end, + x: record.end + timePeriod, y: record.sellRate }; @@ -622,12 +622,12 @@ } let recordPoint8 = { - x: record.begin, + x: record.begin + timePeriod, y: record.buyOrder }; let recordPoint9 = { - x: record.end, + x: record.end + timePeriod, y: record.buyOrder }; @@ -878,7 +878,7 @@ if (strategyPhase > 0) { line1 = ''; - line2 = strategyPhase; + line2 = strategyPhase; imageToDraw = imageStrategyPhase; } @@ -949,15 +949,15 @@ line1 = 'Buying at Buy Order.'; } - + if (record.lastProfit < 0) { - line2 = 'Lost ' + (record.lastProfit * 100).toFixed(2) + ' %'; + line2 = 'Lost ' + (record.lastProfitPercent).toFixed(2) + ' %'; imageToDraw = smileySad; } else { - line2 = 'Won ' + (record.lastProfit * 100).toFixed(2) + ' %'; + line2 = 'Won ' + (record.lastProfitPercent).toFixed(2) + ' %'; imageToDraw = smileyHappy; } @@ -1091,3 +1091,4 @@ + From 0ae1669ebb29c328040ab8a3fda32325bef79691 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 28 Feb 2019 11:53:45 +0100 Subject: [PATCH 010/157] Latest changes working --- TradingSimulation.js | 104 ++++++++++++++++++++++++-------------- TradingSimulationPanel.js | 10 ++++ 2 files changed, 77 insertions(+), 37 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 95c3281c5..5d505e83d 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -56,6 +56,8 @@ let smileyMonkeyEars; let imageStrategy; let imageStrategyPhase; + let imageStopLossPhase; + let imageBuyOrderPhase; return thisObject; @@ -104,7 +106,8 @@ smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); - + imageStopLossPhase = loadEmoji("Objects/Emoji Objects-55.png"); + imageBuyOrderPhase = loadEmoji("Objects/Emoji Objects-114.png"); function loadEmoji(pPath) { @@ -422,7 +425,9 @@ signal: undefined, strategy: undefined, strategyPhase: undefined, - buyOrder: undefined + buyOrder: undefined, + stopLossPhase: undefined, + buyOrderPhase: undefined }; record.begin = marketFile[i][0]; @@ -449,6 +454,8 @@ record.strategy = marketFile[i][21]; record.strategyPhase = marketFile[i][22]; record.buyOrder = marketFile[i][23]; + record.stopLossPhase = marketFile[i][24]; + record.buyOrderPhase = marketFile[i][25]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -547,15 +554,25 @@ directionShort = 0; let strategy = 0; let strategyPhase = 0; + let stopLossPhase = 0; + let buyOrderPhase = 0; if (record.strategy !== records[i - 1].strategy) { // When a change in the strategy field is detected, it is time to plot it. strategy = record.strategy; } - if (record.strategyPhase !== records[i - 1].strategyPhase) { // When a change in the strategy phase field is detected, it is time to plot it. + if (record.strategyPhase !== records[i - 1].strategyPhase) { strategyPhase = record.strategyPhase; } + if (record.stopLossPhase !== records[i - 1].stopLossPhase) { + stopLossPhase = record.stopLossPhase; + } + + if (record.buyOrderPhase !== records[i - 1].buyOrderPhase) { + buyOrderPhase = record.buyOrderPhase; + } + if (record.type === 'Buy@BuyOrder') { directionShort = -1; } if (record.type === 'Buy@StopLoss') { directionShort = 1; } if (record.type === 'Sell-1') { directionShort = +1; } @@ -590,12 +607,12 @@ }; let recordPoint4 = { - x: record.begin + timePeriod, + x: record.begin, y: record.stopLoss }; let recordPoint5 = { - x: record.end + timePeriod, + x: record.end, y: record.stopLoss }; @@ -606,12 +623,12 @@ } let recordPoint6 = { - x: record.begin + timePeriod, + x: record.begin, y: record.sellRate }; let recordPoint7 = { - x: record.end + timePeriod, + x: record.end, y: record.sellRate }; @@ -622,12 +639,12 @@ } let recordPoint8 = { - x: record.begin + timePeriod, + x: record.begin, y: record.buyOrder }; let recordPoint9 = { - x: record.end + timePeriod, + x: record.end, y: record.buyOrder }; @@ -674,29 +691,6 @@ recordPoint8 = viewPort.fitIntoVisibleArea(recordPoint8); recordPoint9 = viewPort.fitIntoVisibleArea(recordPoint9); - /* Next we are drawing the stopLoss floor / ceilling */ - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y); - browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y); - - browserCanvasContext.closePath(); - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'; - - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { - - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } - } - - browserCanvasContext.lineWidth = 1 - browserCanvasContext.stroke() - /* Next we are drawing the sellRate */ browserCanvasContext.beginPath(); @@ -722,6 +716,37 @@ browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) + let imageSize = 20; + let imageToDraw; + + /* Next we are drawing the stopLoss floor / ceilling */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y); + browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } + } + + browserCanvasContext.lineWidth = 1 + browserCanvasContext.stroke() + + if (imageStopLossPhase.isLoaded === true && stopLossPhase > 0) { + browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize, imageSize, imageSize); + printLabel(stopLossPhase, recordPoint5.x, recordPoint5.y - 2, '0.50'); + } + /* Next we are drawing the Buy Order */ browserCanvasContext.beginPath(); @@ -745,6 +770,11 @@ browserCanvasContext.lineWidth = 1 browserCanvasContext.stroke() + if (imageBuyOrderPhase.isLoaded === true && buyOrderPhase > 0) { + browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize, recordPoint9.y + imageSize / 4, imageSize, imageSize); + printLabel(buyOrderPhase, recordPoint9.x - imageSize / 2, recordPoint9.y + imageSize * 1.75, '0.50'); + } + /* Continue with the pins --> Next stuff is to avoid text overlapping. */ let noShortTextUp = false; @@ -864,9 +894,6 @@ //browserCanvasContext.beginPath(); - let imageSize = 20; - let imageToDraw; - let line1; let line2; @@ -922,8 +949,8 @@ (directionLong > 0 && noLongTextUp === false) || (directionLong < 0 && noLongTextDown === false) ) { - printLabel(line1, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 0, '0.50'); - printLabel(line2, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 15, '0.50'); + printLabel(line1, recordPoint2.x + imageSize / 2, recordPoint2.y + 0, '0.50'); + printLabel(line2, recordPoint2.x + imageSize / 2, recordPoint2.y + 15, '0.50'); } } } @@ -1092,3 +1119,6 @@ + + + diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index e700483e5..662405276 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -193,11 +193,21 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + y = y + increment; + printLabel('Sell Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + y = y + increment; printLabel('Stop Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + y = y + increment; + printLabel('Buy Order', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.buyOrder, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + y = y + increment; printLabel('Roundtrips', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; From 1baa176fd8e77d75e94eaacf193a4ed4cf28d6a4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 5 Mar 2019 15:48:40 +0100 Subject: [PATCH 011/157] Labels Updated --- TradingSimulation.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 5d505e83d..09a32ac55 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -960,8 +960,8 @@ if (record.signal === 'Pre-Sell') { - line1 = 'Sell as soon as Bollinger'; - line2 = 'moving average heads down.'; + line1 = 'Get ready'; + line2 = 'to SELL.'; imageToDraw = smileyGhost; } @@ -970,36 +970,36 @@ if (record.type === 'Buy@StopLoss') { - line1 = 'Buying at Stop Loss.'; + line1 = 'Stop Loss hit.'; } else { - line1 = 'Buying at Buy Order.'; + line1 = 'Buy Order hit.'; } if (record.lastProfit < 0) { - line2 = 'Lost ' + (record.lastProfitPercent).toFixed(2) + ' %'; + line2 = 'Loss: ' + (record.lastProfitPercent).toFixed(2) + ' %'; imageToDraw = smileySad; } else { - line2 = 'Won ' + (record.lastProfitPercent).toFixed(2) + ' %'; + line2 = 'Profit: ' + (record.lastProfitPercent).toFixed(2) + ' %'; imageToDraw = smileyHappy; } } if (record.type === 'Sell-1') { - line1 = 'Sold because '; - line2 = 'market reversed.'; + line1 = 'Sold on'; + line2 = 'condition 1.'; imageToDraw = smileyMonkeyEyes; } if (record.type === 'Sell-2') { - line1 = 'Sold because '; - line2 = 'resistance collapsed.'; + line1 = 'Sold on'; + line2 = 'condition 2.'; imageToDraw = smileyMonkeyEars; } @@ -1122,3 +1122,4 @@ + From a414ed951f1266af1dc230b77ddc71816eb148b2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 5 Mar 2019 18:21:00 +0100 Subject: [PATCH 012/157] Pre Sell Cancelled --- TradingSimulation.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 09a32ac55..1d05de3cd 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -578,6 +578,7 @@ if (record.type === 'Sell-1') { directionShort = +1; } if (record.type === 'Sell-2') { directionShort = +1; } if (record.signal === 'Pre-Sell') { directionShort = +1; } + if (record.signal === 'Pre-Sell-Cancelled') { directionShort = -1; } if (strategyPhase > 0) { if (strategyPhase % 2 !== 0) { //Depending if the phase is oddd or even goes above or below. @@ -960,7 +961,15 @@ if (record.signal === 'Pre-Sell') { - line1 = 'Get ready'; + line1 = 'Ready'; + line2 = 'to SELL.'; + + imageToDraw = smileyGhost; + } + + if (record.signal === 'Pre-Sell-Cancelled') { + + line1 = 'Not ready'; line2 = 'to SELL.'; imageToDraw = smileyGhost; @@ -1123,3 +1132,4 @@ + From a935e2ad771f761ea54a208600c3d8a766fe0d13 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 6 Mar 2019 11:47:31 +0100 Subject: [PATCH 013/157] Signal removed --- TradingSimulation.js | 76 +++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 1d05de3cd..80493171d 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -422,7 +422,6 @@ anualizedRateOfReturn: undefined, sellRate: undefined, lastProfitPercent: undefined, - signal: undefined, strategy: undefined, strategyPhase: undefined, buyOrder: undefined, @@ -450,12 +449,11 @@ record.anualizedRateOfReturn = marketFile[i][17]; record.sellRate = marketFile[i][18]; record.lastProfitPercent = marketFile[i][19]; - record.signal = marketFile[i][20]; - record.strategy = marketFile[i][21]; - record.strategyPhase = marketFile[i][22]; - record.buyOrder = marketFile[i][23]; - record.stopLossPhase = marketFile[i][24]; - record.buyOrderPhase = marketFile[i][25]; + record.strategy = marketFile[i][20]; + record.strategyPhase = marketFile[i][21]; + record.buyOrder = marketFile[i][22]; + record.stopLossPhase = marketFile[i][23]; + record.buyOrderPhase = marketFile[i][24]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -552,7 +550,7 @@ record = records[i]; directionShort = 0; - let strategy = 0; + let strategy; let strategyPhase = 0; let stopLossPhase = 0; let buyOrderPhase = 0; @@ -577,8 +575,6 @@ if (record.type === 'Buy@StopLoss') { directionShort = 1; } if (record.type === 'Sell-1') { directionShort = +1; } if (record.type === 'Sell-2') { directionShort = +1; } - if (record.signal === 'Pre-Sell') { directionShort = +1; } - if (record.signal === 'Pre-Sell-Cancelled') { directionShort = -1; } if (strategyPhase > 0) { if (strategyPhase % 2 !== 0) { //Depending if the phase is oddd or even goes above or below. @@ -588,10 +584,14 @@ } } - if (strategy > 0) { + if (strategy === 0) { directionLong = -1; } + if (strategy > 0) { + directionLong = 1; + } + let recordPoint1 = { x: record.begin + (record.end - record.begin) / 2, y: record.rate @@ -679,8 +679,8 @@ continue; } - recordPoint2.y = recordPoint1.y - 250 * directionLong; - recordPoint3.y = recordPoint1.y - 150 * directionShort; + recordPoint2.y = recordPoint1.y - 200 * directionLong; + recordPoint3.y = recordPoint1.y - 100 * directionShort; recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); @@ -782,8 +782,7 @@ let noShortTextDown = false; if ( - record.type !== '' || - record.signal !== '' + record.type !== '' ) { if (directionShort > 0) { @@ -840,8 +839,7 @@ if ( - strategy > 0 || - strategyPhase > 0 + strategy !== undefined ) { /* Next we are drawing the LONG stick */ @@ -851,8 +849,7 @@ } if ( - record.type !== '' || - record.signal !== '' + record.type !== '' ) { /* Next we are drawing the SHORT stick */ @@ -903,26 +900,26 @@ function longPinHead() { - if (strategyPhase > 0) { + if (strategy === 0) { - line1 = ''; - line2 = strategyPhase; + line1 = 'Strategy'; + line2 = 'Exit'; - imageToDraw = imageStrategyPhase; + imageToDraw = smileyGhost; } if (strategy === 1) { - line1 = 'Trend Following'; - line2 = ''; + line1 = 'Trend'; + line2 = 'Following'; - imageToDraw = imageStrategy; + imageToDraw = smileyGhost; } if (strategy === 2) { - line1 = 'Range Trading'; - line2 = ''; + line1 = 'Range'; + line2 = 'Trading'; - imageToDraw = imageStrategy; + imageToDraw = smileyGhost; } if (imageToDraw !== undefined) { @@ -950,8 +947,8 @@ (directionLong > 0 && noLongTextUp === false) || (directionLong < 0 && noLongTextDown === false) ) { - printLabel(line1, recordPoint2.x + imageSize / 2, recordPoint2.y + 0, '0.50'); - printLabel(line2, recordPoint2.x + imageSize / 2, recordPoint2.y + 15, '0.50'); + printLabel(line1, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 0, '0.50'); + printLabel(line2, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 15, '0.50'); } } } @@ -959,22 +956,6 @@ function shortPinHead() { - if (record.signal === 'Pre-Sell') { - - line1 = 'Ready'; - line2 = 'to SELL.'; - - imageToDraw = smileyGhost; - } - - if (record.signal === 'Pre-Sell-Cancelled') { - - line1 = 'Not ready'; - line2 = 'to SELL.'; - - imageToDraw = smileyGhost; - } - if (record.type === 'Buy@StopLoss' || record.type === 'Buy@BuyOrder') { if (record.type === 'Buy@StopLoss') { @@ -1133,3 +1114,4 @@ + From 07aedb0563ec01f978fad372317e287a86f499ee Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 6 Mar 2019 18:05:13 +0100 Subject: [PATCH 014/157] See conditions dinamically --- TradingSimulation.js | 27 +++++++++++++++++++++------ TradingSimulationPanel.js | 18 ++++++++++++++++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 80493171d..f7b465f0c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -426,7 +426,8 @@ strategyPhase: undefined, buyOrder: undefined, stopLossPhase: undefined, - buyOrderPhase: undefined + buyOrderPhase: undefined, + conditions: undefined }; record.begin = marketFile[i][0]; @@ -454,6 +455,11 @@ record.buyOrder = marketFile[i][22]; record.stopLossPhase = marketFile[i][23]; record.buyOrderPhase = marketFile[i][24]; + record.conditions = marketFile[i][25]; + + if (i === 0) { // The first record contains headers needed to be printed. + records.push(record); + } if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -875,11 +881,6 @@ /* highlight the current record */ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - - let currentRecord = { - innerRecord: record - }; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); } } @@ -1025,6 +1026,20 @@ } } + /* Send the current record to the panel */ + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + let currentRecord = { + conditionsNames: records[0].conditions, + conditionsValues: record.conditions, + innerRecord: record + }; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); + } + } /* This is how we write the text */ diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 662405276..bbc814680 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -23,7 +23,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function initialize() { thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 1.5; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2; thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; @@ -166,7 +166,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let y = 0; - let increment = 0.03; + let increment = 0.025; y = y + increment; printLabel('Balance A', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); @@ -248,6 +248,20 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + y = y + increment; + y = y + increment; + + for (let i = 0; i < currentRecord.conditionsNames.length; i++) { + y = y + increment; + let opacity; + if (currentRecord.conditionsValues[i] === 1) { + opacity = '1.00' + } else { + opacity = '0.50'; + } + printLabel(currentRecord.conditionsNames[i], X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity); + } + function printLabel(labelToPrint, x, y, opacity) { let labelPoint; From 94a3b8d330a8a7296e75ab04942a900137344afd Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 7 Mar 2019 01:54:22 +0100 Subject: [PATCH 015/157] Conditions Plotter and Panel --- Conditions.js | 578 ++++++++++++++++++++++++++++++++++++++ ConditionsPanel.js | 130 +++++++++ Project.njsproj | 6 + TradingSimulation.js | 10 +- TradingSimulationPanel.js | 101 +------ this.plotter.config.json | 13 + 6 files changed, 730 insertions(+), 108 deletions(-) create mode 100644 Conditions.js create mode 100644 ConditionsPanel.js diff --git a/Conditions.js b/Conditions.js new file mode 100644 index 000000000..be5e1e429 --- /dev/null +++ b/Conditions.js @@ -0,0 +1,578 @@ +function newAAMastersPlottersTradingSimulationConditions() { + + const MODULE_NAME = "Conditions Plotter"; + const INFO_LOG = false; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; + + let thisObject = { + + // Main functions and properties. + + initialize: initialize, + container: undefined, + getContainer: getContainer, + setTimePeriod: setTimePeriod, + setDatetime: setDatetime, + draw: draw, + recalculateScale: recalculateScale, + + /* Events declared outside the plotter. */ + + onDailyFileLoaded: onDailyFileLoaded, + + // Secondary functions and properties. + + currentRecord: undefined + }; + + /* this is part of the module template */ + + let container = newContainer(); // Do not touch this 3 lines, they are just needed. + container.initialize(); + thisObject.container = container; + + let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + + let timePeriod; // This will hold the current Time Period the user is at. + let datetime; // This will hold the current Datetime the user is at. + + let marketFile; // This is the current Market File being plotted. + let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. + + let marketFiles; // This object will provide the different Market Files at different Time Periods. + let dailyFiles; // This object will provide the different File Cursors at different Time Periods. + + /* these are module specific variables: */ + + let conditions = []; + + let smileyHappy; + let smileySad; + let smileyGhost; + let smileyMonkeyEyes; + let smileyMonkeyEars; + let imageStrategy; + let imageStrategyPhase; + let imageStopLossPhase; + let imageBuyOrderPhase; + + return thisObject; + + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + + /* Store the information received. */ + + marketFiles = pStorage.marketFiles[0]; + dailyFiles = pStorage.dailyFiles[0]; + + datetime = pDatetime; + timePeriod = pTimePeriod; + + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ + + marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. + + recalculateScale(); + + /* Now we set the right files according to current Period. */ + + marketFile = marketFiles.getFile(pTimePeriod); + fileCursor = dailyFiles.getFileCursor(pTimePeriod); + + /* Listen to the necesary events. */ + + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + + /* Get ready for plotting. */ + + recalculate(); + + /* Loading a few icons */ + + smileyHappy = loadEmoji("Smiley/Emoji Smiley-51.png"); + smileySad = loadEmoji("Smiley/Emoji Smiley-26.png"); + smileyGhost = loadEmoji("Objects/Emoji Objects-12.png"); + smileyMonkeyEyes = loadEmoji("Smiley/Emoji Smiley-85.png"); + smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); + imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); + imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); + imageStopLossPhase = loadEmoji("Objects/Emoji Objects-55.png"); + imageBuyOrderPhase = loadEmoji("Objects/Emoji Objects-114.png"); + + function loadEmoji(pPath) { + + let newImage; + + newImage = new Image(); + newImage.onload = onImageLoaded; + + function onImageLoaded() { + newImage.isLoaded = true; + } + + newImage.src = window.canvasApp.urlPrefix + "Images/Emoji/" + pPath; + + return newImage; + } + + callBackFunction(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); } + } + } + + function getContainer(point) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } + + let container; + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err.message = " + err.message); } + } + } + + function onFilesUpdated() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } + + let newMarketFile = marketFiles.getFile(timePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err.message = " + err.message); } + } + } + + function setTimePeriod(pTimePeriod) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } + + if (timePeriod !== pTimePeriod) { + + timePeriod = pTimePeriod; + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + let newMarketFile = marketFiles.getFile(pTimePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } else { + + let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + + if (newFileCursor !== undefined) { + + fileCursor = newFileCursor; + recalculate(); + } + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err.message = " + err.message); } + } + } + + function setDatetime(pDatetime) { + + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } + + datetime = pDatetime; + + } + + function onDailyFileLoaded(event) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onDailyFileLoaded -> Entering function."); } + + if (event.currentValue === event.totalValue) { + + /* This happens only when all of the files in the cursor have been loaded. */ + + recalculate(); + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err.message = " + err.message); } + } + } + + function draw() { + + try { + + if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); } + + this.container.frame.draw(); + + plotChart(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); } + } + } + + function recalculate() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + recalculateUsingMarketFiles(); + + } else { + + recalculateUsingDailyFiles(); + + } + + thisObject.container.eventHandler.raiseEvent("Conditions Changed", conditions); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); } + } + } + + function recalculateUsingDailyFiles() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } + + if (fileCursor === undefined) { return; } // We need to wait + + if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor + + let daysOnSides = getSideDays(timePeriod); + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + + let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + + let currentDate = new Date(farLeftDate.valueOf()); + + conditions = []; + + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { + + let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); + + let dailyFile = fileCursor.files.get(stringDate); + + if (dailyFile !== undefined) { + + for (let i = 0; i < dailyFile.length; i++) { + + let record = { + begin: undefined, + end: undefined, + conditions: undefined + }; + + record.begin = dailyFile[i][0]; + record.end = dailyFile[i][1]; + record.conditions = dailyFile[i]; + + if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + + conditions.push(record); + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Condition Changed", thisObject.currentRecord); + + } + } + } + } + + currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS); + } + + /* Lests check if all the visible screen is going to be covered by conditions. */ + + let lowerEnd = leftDate.valueOf(); + let upperEnd = rightDate.valueOf(); + + if (conditions.length > 0) { + + if (conditions[0].begin > lowerEnd || conditions[conditions.length - 1].end < upperEnd) { + + setTimeout(recalculate, 2000); + + //console.log("File missing while calculating conditions, scheduling a recalculation in 2 seconds."); + + } + } + + //console.log("Olivia > recalculateUsingDailyFiles > total conditions generated : " + conditions.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err.message = " + err.message); } + } + } + + function recalculateUsingMarketFiles() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingMarketFiles -> Entering function."); } + + if (marketFile === undefined) { return; } // Initialization not complete yet. + + let daysOnSides = getSideDays(timePeriod); + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + + leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + + conditions = []; + + for (let i = 0; i < marketFile.length; i++) { + + let record = { + begin: undefined, + end: undefined, + conditions: undefined + }; + + record.begin = marketFile[i][0]; + record.end = marketFile[i][1]; + record.conditions = marketFile[i]; + + if (i === 0) { // The first record contains headers needed to be printed. + conditions.push(record); + } + + if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { + + conditions.push(record); + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Condition Changed", thisObject.currentRecord); + + } + } + } + + //console.log("Olivia > recalculateUsingMarketFiles > total conditions generated : " + conditions.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); } + } + } + + function recalculateScale() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); } + + if (marketFile === undefined) { return; } // We need the market file to be loaded to make the calculation. + + if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + + let minValue = { + x: EARLIEST_DATE.valueOf(), + y: 0 + }; + + let maxValue = { + x: MAX_PLOTABLE_DATE.valueOf(), + y: nextPorwerOf10(getMaxRate()) / 4 // TODO: This 4 is temporary + }; + + + timeLineCoordinateSystem.initialize( + minValue, + maxValue, + thisObject.container.frame.width, + thisObject.container.frame.height + ); + + function getMaxRate() { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> getMaxRate -> Entering function."); } + + let maxValue = 0; + + for (let i = 0; i < marketFile.length; i++) { + + let currentMax = 25000; // TODO Fix this, since when there are not records above 10k the scales is dissincronized with the scale of the candles. marketFile[i][3]; // 3 = rate. + + if (maxValue < currentMax) { + maxValue = currentMax; + } + } + + return maxValue; + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err.message = " + err.message); } + } + } + + function plotChart() { + + try { + + if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } + + let conditionRecord; + + for (let i = 1; i < conditions.length; i++) { // We do not start in 0 because there we have the headers. + + conditionRecord = conditions[i]; + + /* Send the current record to the panel */ + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= conditionRecord.begin && dateValue <= conditionRecord.end) { + + let currentRecord = { + conditionsNames: conditions[0].conditions, + conditionsValues: conditionRecord.conditions + }; + thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", currentRecord); + } + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } + } + } + + + function onZoomChanged(event) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err.message = " + err.message); } + } + } + + function onOffsetChanged() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + + if (Math.random() * 100 > 95) { + + recalculate() + }; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err.message = " + err.message); } + } + } + + function onDragFinished() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onDragFinished -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err.message = " + err.message); } + } + } +} + + + + + + + + + + + + + + + + diff --git a/ConditionsPanel.js b/ConditionsPanel.js new file mode 100644 index 000000000..55e820318 --- /dev/null +++ b/ConditionsPanel.js @@ -0,0 +1,130 @@ + +function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { + + var thisObject = { + onEventRaised: onEventRaised, + container: undefined, + draw: draw, + getContainer: getContainer, + initialize: initialize + }; + + var container = newContainer(); + container.initialize(); + thisObject.container = container; + + container.displacement.containerName = "Conditions Panel"; + container.frame.containerName = "Conditions Panel"; + + let currentRecord; + + return thisObject; + + function initialize() { + + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 1; + + thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 2; + thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; + + } + + function getContainer(point) { + + var container; + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point, true) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } + + + function onEventRaised(lastCurrentRecord) { + + currentRecord = lastCurrentRecord; + + } + + + function draw() { + + this.container.frame.draw(false, false, true); + + plotCurrentRecordInfo(); + + } + + + function plotCurrentRecordInfo() { + + if (currentRecord === undefined) { return; } + if (currentRecord.conditionsNames === undefined) { return; } + + const frameBodyHeight = thisObject.container.frame.getBodyHeight(); + const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; + + const X_AXIS = thisObject.container.frame.width / 2; + const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; + + let y = 0; + let increment = 0.06; + + browserCanvasContext.beginPath(); + + for (let i = 2; i < currentRecord.conditionsNames.length; i++) { // Jump the first 2 items since they are the .begin and the .end of the record. + y = y + increment; + let opacity; + if (currentRecord.conditionsValues[i] === 1) { + opacity = '1.00' + } else { + opacity = '0.50'; + } + printLabel(currentRecord.conditionsNames[i], X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity); + } + + function printLabel(labelToPrint, x, y, opacity) { + + let labelPoint; + let fontSize = 10; + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY; + + let label = '' + labelToPrint; + if (isNaN(label) === false) { + label = Number(label).toLocaleString(); + } + let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + + labelPoint = { + x: x - xOffset, + y: y + }; + + labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + + } + + browserCanvasContext.closePath(); + browserCanvasContext.fill(); + + } + + +} + + + diff --git a/Project.njsproj b/Project.njsproj index 2e95d5370..22f4dcca1 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -17,6 +17,12 @@ + + Code + + + Code + diff --git a/TradingSimulation.js b/TradingSimulation.js index f7b465f0c..c9bd8e390 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -426,8 +426,7 @@ strategyPhase: undefined, buyOrder: undefined, stopLossPhase: undefined, - buyOrderPhase: undefined, - conditions: undefined + buyOrderPhase: undefined }; record.begin = marketFile[i][0]; @@ -455,11 +454,6 @@ record.buyOrder = marketFile[i][22]; record.stopLossPhase = marketFile[i][23]; record.buyOrderPhase = marketFile[i][24]; - record.conditions = marketFile[i][25]; - - if (i === 0) { // The first record contains headers needed to be printed. - records.push(record); - } if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -1033,8 +1027,6 @@ if (dateValue >= record.begin && dateValue <= record.end) { let currentRecord = { - conditionsNames: records[0].conditions, - conditionsValues: record.conditions, innerRecord: record }; thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index bbc814680..d9884e73a 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -77,93 +77,10 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation const X_AXIS = thisObject.container.frame.width / 2; const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; - var recordPoint1 = { - x: X_AXIS - currentRecord.bodyWidth / 2, - y: Y_AXIS - currentRecord.leftBodyHeight / 2 - currentRecord.bottomDelta / 4 - }; - - var recordPoint2 = { - x: X_AXIS - currentRecord.bodyWidth / 2, - y: Y_AXIS + currentRecord.leftBodyHeight / 2 - currentRecord.topDelta / 4 - }; - - var recordPoint3 = { - x: X_AXIS + currentRecord.bodyWidth / 2, - y: Y_AXIS + currentRecord.rightBodyHeight / 2 + currentRecord.topDelta / 4 - }; - - var recordPoint4 = { - x: X_AXIS + currentRecord.bodyWidth / 2, - y: Y_AXIS - currentRecord.rightBodyHeight / 2 + currentRecord.bottomDelta / 4 - }; - - - - /* Extra bounderies due to constrained space */ - - const upperLimit = frameTitleHeight + frameBodyHeight * 0.15; - const downLimit = frameTitleHeight + frameBodyHeight * 0.85; - - if (recordPoint1.y > downLimit) { recordPoint1.y = downLimit; } - if (recordPoint4.y > downLimit) { recordPoint4.y = downLimit; } - - if (recordPoint2.y < upperLimit) { recordPoint2.y = upperLimit; } - if (recordPoint3.y < upperLimit) { recordPoint3.y = upperLimit; } - - recordPoint1 = thisObject.container.frame.frameThisPoint(recordPoint1); - recordPoint2 = thisObject.container.frame.frameThisPoint(recordPoint2); - recordPoint3 = thisObject.container.frame.frameThisPoint(recordPoint3); - recordPoint4 = thisObject.container.frame.frameThisPoint(recordPoint4); - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); - browserCanvasContext.lineTo(recordPoint2.x, recordPoint2.y); - browserCanvasContext.lineTo(recordPoint3.x, recordPoint3.y); - browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y); - - browserCanvasContext.closePath(); - - const OPACITY = '0.1'; - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + OPACITY + ')'; - - browserCanvasContext.fill(); - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); - browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y); - browserCanvasContext.moveTo(recordPoint2.x, recordPoint2.y); - browserCanvasContext.lineTo(recordPoint3.x, recordPoint3.y); - - browserCanvasContext.closePath(); - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', 1)'; - - browserCanvasContext.lineWidth = 0.2; - browserCanvasContext.stroke(); - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y + (recordPoint2.y - recordPoint1.y) / 2); - browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y - (recordPoint4.y - recordPoint3.y) / 2); - - - browserCanvasContext.closePath(); - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'; - - browserCanvasContext.lineWidth = 0.2; - browserCanvasContext.stroke(); - - - browserCanvasContext.beginPath(); /* put the labels with the records values */ - - + browserCanvasContext.beginPath(); let y = 0; let increment = 0.025; @@ -247,21 +164,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); - - y = y + increment; - y = y + increment; - - for (let i = 0; i < currentRecord.conditionsNames.length; i++) { - y = y + increment; - let opacity; - if (currentRecord.conditionsValues[i] === 1) { - opacity = '1.00' - } else { - opacity = '0.50'; - } - printLabel(currentRecord.conditionsNames[i], X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity); - } - + function printLabel(labelToPrint, x, y, opacity) { let labelPoint; diff --git a/this.plotter.config.json b/this.plotter.config.json index 488a19e4e..1976dcda4 100644 --- a/this.plotter.config.json +++ b/this.plotter.config.json @@ -15,6 +15,19 @@ "event": "Current Record Changed" } ] + }, + { + "codeName": "Conditions", + "moduleName": "Conditions", + "description": "Plots Simulation Conditions.", + "profilePicture": "Conditions.png", + "panels": [ + { + "codeName": "ConditionsPanel", + "moduleName": "ConditionsPanel", + "event": "Current Condition Record Changed" + } + ] } ] } \ No newline at end of file From e0e7483e384ef14f0e7d576af75d3caa43b77520 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 7 Mar 2019 13:57:15 +0100 Subject: [PATCH 016/157] Conditions Panel Working from SimulationLogic --- Conditions.js | 17 +++++++-------- ConditionsPanel.js | 54 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/Conditions.js b/Conditions.js index be5e1e429..b352eef41 100644 --- a/Conditions.js +++ b/Conditions.js @@ -48,6 +48,7 @@ /* these are module specific variables: */ let conditions = []; + let headers; let smileyHappy; let smileySad; @@ -390,8 +391,9 @@ rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); conditions = []; + headers = marketFile[0]; - for (let i = 0; i < marketFile.length; i++) { + for (let i = 0; i < marketFile[1].length; i++) { let record = { begin: undefined, @@ -399,13 +401,9 @@ conditions: undefined }; - record.begin = marketFile[i][0]; - record.end = marketFile[i][1]; - record.conditions = marketFile[i]; - - if (i === 0) { // The first record contains headers needed to be printed. - conditions.push(record); - } + record.begin = marketFile[1][i][0]; + record.end = marketFile[1][i][1]; + record.conditions = marketFile[1][i]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -500,7 +498,7 @@ if (dateValue >= conditionRecord.begin && dateValue <= conditionRecord.end) { let currentRecord = { - conditionsNames: conditions[0].conditions, + conditionsNames: headers, conditionsValues: conditionRecord.conditions }; thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", currentRecord); @@ -576,3 +574,4 @@ + diff --git a/ConditionsPanel.js b/ConditionsPanel.js index 55e820318..fe9087e59 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -79,21 +79,59 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let y = 0; let increment = 0.06; + let opacity; + let label; browserCanvasContext.beginPath(); - for (let i = 2; i < currentRecord.conditionsNames.length; i++) { // Jump the first 2 items since they are the .begin and the .end of the record. + let simulationLogic = currentRecord.conditionsNames; + let conditionIndex = 2; // Jump the first 2 items since they are the .begin and the .end of the record. + + for (let j = 0; j < simulationLogic.strategies.length; j++) { + + let strategy = simulationLogic.strategies[j]; + y = y + increment; - let opacity; - if (currentRecord.conditionsValues[i] === 1) { - opacity = '1.00' - } else { + y = y + increment; + opacity = '1.00'; + label = 'Strategy: ' + strategy.name; + printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + y = y + increment; + opacity = '0.50'; + label = 'Entry Point'; + printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let k = 0; k < strategy.entryPoint.situations.length; k++) { + + let situation = strategy.entryPoint.situations[k]; + + y = y + increment; opacity = '0.50'; + label = 'Situation: ' + situation.name; + printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let m = 0; m < situation.conditions.length; m++) { + + let condition = situation.conditions[m]; + let color; + + y = y + increment; + if (currentRecord.conditionsValues[conditionIndex] === 1) { + opacity = '0.50' + color = UI_COLOR.PATINATED_TURQUOISE; + } else { + opacity = '0.50'; + color = UI_COLOR.RUSTED_RED; + } + conditionIndex++; + label = condition.name; + printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, color); + } } - printLabel(currentRecord.conditionsNames[i], X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity); } - function printLabel(labelToPrint, x, y, opacity) { + function printLabel(labelToPrint, x, y, opacity, color) { let labelPoint; let fontSize = 10; @@ -113,7 +151,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillStyle = 'rgba(' + color + ', ' + opacity + ')'; browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); } From dd0364f3ff74c79912bdae15e708b7ad0c7be4d3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 7 Mar 2019 19:31:47 +0100 Subject: [PATCH 017/157] Sell Points --- ConditionsPanel.js | 86 +++++++++++++++++++++++++++++--------------- TradingSimulation.js | 16 +++------ 2 files changed, 62 insertions(+), 40 deletions(-) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index fe9087e59..6302815a0 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -22,10 +22,10 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { function initialize() { - thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 1; + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 2; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2; - thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 2; + thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - UI_PANEL.WIDTH.NORMAL * 3; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; } @@ -74,13 +74,14 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { const frameBodyHeight = thisObject.container.frame.getBodyHeight(); const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; - const X_AXIS = thisObject.container.frame.width / 2; + const X_AXIS = thisObject.container.frame.width * 1 / 10; const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; let y = 0; - let increment = 0.06; + let increment = 0.03; let opacity; let label; + let indent = 5; browserCanvasContext.beginPath(); @@ -99,36 +100,63 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { y = y + increment; opacity = '0.50'; - label = 'Entry Point'; - printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + label = 'Entry Points'; + printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); for (let k = 0; k < strategy.entryPoint.situations.length; k++) { let situation = strategy.entryPoint.situations[k]; + processSituation(situation); + } + + y = y + increment; + opacity = '0.50'; + label = 'Exit Points'; + printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let k = 0; k < strategy.exitPoint.situations.length; k++) { + + let situation = strategy.exitPoint.situations[k]; + processSituation(situation); + } + + y = y + increment; + opacity = '0.50'; + label = 'Sell Points'; + printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let k = 0; k < strategy.sellPoint.situations.length; k++) { + + let situation = strategy.sellPoint.situations[k]; + processSituation(situation); + } + } + + function processSituation(situation) { + + y = y + increment; + opacity = '0.50'; + label = 'Situation: ' + situation.name; + printLabel(label, X_AXIS + indent * 2, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let m = 0; m < situation.conditions.length; m++) { + + let condition = situation.conditions[m]; + let color; y = y + increment; - opacity = '0.50'; - label = 'Situation: ' + situation.name; - printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); - - for (let m = 0; m < situation.conditions.length; m++) { - - let condition = situation.conditions[m]; - let color; - - y = y + increment; - if (currentRecord.conditionsValues[conditionIndex] === 1) { - opacity = '0.50' - color = UI_COLOR.PATINATED_TURQUOISE; - } else { - opacity = '0.50'; - color = UI_COLOR.RUSTED_RED; - } - conditionIndex++; - label = condition.name; - printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, color); + if (currentRecord.conditionsValues[conditionIndex] === 1) { + opacity = '0.50' + color = UI_COLOR.PATINATED_TURQUOISE; + } else { + opacity = '0.50'; + color = UI_COLOR.RUSTED_RED; } + conditionIndex++; + label = condition.name; + printLabel(label, X_AXIS + indent * 3, frameTitleHeight + frameBodyHeight * y, opacity, color); } + } function printLabel(labelToPrint, x, y, opacity, color) { @@ -145,7 +173,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; labelPoint = { - x: x - xOffset, + x: x, y: y }; @@ -166,3 +194,5 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { + + diff --git a/TradingSimulation.js b/TradingSimulation.js index c9bd8e390..8239cb2be 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -573,8 +573,7 @@ if (record.type === 'Buy@BuyOrder') { directionShort = -1; } if (record.type === 'Buy@StopLoss') { directionShort = 1; } - if (record.type === 'Sell-1') { directionShort = +1; } - if (record.type === 'Sell-2') { directionShort = +1; } + if (record.type === 'Sell') { directionShort = +1; } if (strategyPhase > 0) { if (strategyPhase % 2 !== 0) { //Depending if the phase is oddd or even goes above or below. @@ -974,20 +973,13 @@ } } - if (record.type === 'Sell-1') { + if (record.type === 'Sell') { - line1 = 'Sold on'; - line2 = 'condition 1.'; + line1 = 'Sold'; + line2 = ''; imageToDraw = smileyMonkeyEyes; } - if (record.type === 'Sell-2') { - - line1 = 'Sold on'; - line2 = 'condition 2.'; - - imageToDraw = smileyMonkeyEars; - } if (imageToDraw !== undefined) { From 979cf88368b769bcb95913b69186aedcc353cd3e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 8 Mar 2019 11:08:44 +0100 Subject: [PATCH 018/157] Stop Loss at simulation logic --- ConditionsPanel.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index 6302815a0..f77f03173 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -130,6 +130,28 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let situation = strategy.sellPoint.situations[k]; processSituation(situation); } + + y = y + increment; + opacity = '0.50'; + label = 'Stop Loss Management'; + printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let p = 0; p < strategy.stopLoss.phases.length; p++) { + + let phase = strategy.stopLoss.phases[p]; + + y = y + increment; + opacity = '0.50'; + label = 'Phase: ' + phase.name; + printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let k = 0; k < phase.situations.length; k++) { + + let situation = phase.situations[k]; + processSituation(situation); + } + + } } function processSituation(situation) { From 0c8d713fe3f8b2f147440966e1751ac896720449 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 8 Mar 2019 11:37:40 +0100 Subject: [PATCH 019/157] full height --- ConditionsPanel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index f77f03173..145621739 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -23,7 +23,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { function initialize() { thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 2; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2; + thisObject.container.frame.height = viewPort.visibleArea.bottomLeft.y - viewPort.visibleArea.topLeft.y; thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - UI_PANEL.WIDTH.NORMAL * 3; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; From 94dc2e1bfb9ab6765192664b3681c2df22a507a5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 8 Mar 2019 12:37:19 +0100 Subject: [PATCH 020/157] Buy Order added --- ConditionsPanel.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index 145621739..a9481547a 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -78,7 +78,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; let y = 0; - let increment = 0.03; + let increment = 0.02; let opacity; let label; let indent = 5; @@ -92,7 +92,6 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let strategy = simulationLogic.strategies[j]; - y = y + increment; y = y + increment; opacity = '1.00'; label = 'Strategy: ' + strategy.name; @@ -150,7 +149,27 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let situation = phase.situations[k]; processSituation(situation); } + } + y = y + increment; + opacity = '0.50'; + label = 'Buy Order Management'; + printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let p = 0; p < strategy.buyOrder.phases.length; p++) { + + let phase = strategy.buyOrder.phases[p]; + + y = y + increment; + opacity = '0.50'; + label = 'Phase: ' + phase.name; + printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let k = 0; k < phase.situations.length; k++) { + + let situation = phase.situations[k]; + processSituation(situation); + } } } @@ -218,3 +237,4 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { + From 367af99cfba1e4fd875143ceb2e86d14cd47d402 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 8 Mar 2019 13:58:05 +0100 Subject: [PATCH 021/157] Receiveing extra status information on the file --- Conditions.js | 12 ++++++++++-- ConditionsPanel.js | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Conditions.js b/Conditions.js index b352eef41..054ce6179 100644 --- a/Conditions.js +++ b/Conditions.js @@ -403,7 +403,11 @@ record.begin = marketFile[1][i][0]; record.end = marketFile[1][i][1]; - record.conditions = marketFile[1][i]; + record.strategyNumber = marketFile[1][i][2]; + record.strategyPhase = marketFile[1][i][3]; + record.stopLossPhase = marketFile[1][i][4]; + record.buyOrderPhase = marketFile[1][i][5]; + record.conditions = marketFile[1][i][6]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -487,7 +491,7 @@ let conditionRecord; - for (let i = 1; i < conditions.length; i++) { // We do not start in 0 because there we have the headers. + for (let i = 0; i < conditions.length; i++) { conditionRecord = conditions[i]; @@ -499,6 +503,10 @@ let currentRecord = { conditionsNames: headers, + strategyNumber: conditionRecord.strategyNumber, + strategyPhase: conditionRecord.strategyPhase, + stopLossPhase: conditionRecord.stopLossPhase, + buyOrderPhase: conditionRecord.buyOrderPhase, conditionsValues: conditionRecord.conditions }; thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", currentRecord); diff --git a/ConditionsPanel.js b/ConditionsPanel.js index a9481547a..39389a392 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -86,7 +86,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { browserCanvasContext.beginPath(); let simulationLogic = currentRecord.conditionsNames; - let conditionIndex = 2; // Jump the first 2 items since they are the .begin and the .end of the record. + let conditionIndex = 0; for (let j = 0; j < simulationLogic.strategies.length; j++) { From bd905cb4ac5f22d8c8eda8026a259aeaa4940401 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 8 Mar 2019 14:29:28 +0100 Subject: [PATCH 022/157] Conditional display of conditions --- ConditionsPanel.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index 39389a392..b09e6994c 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -82,22 +82,27 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let opacity; let label; let indent = 5; + let showLabel; browserCanvasContext.beginPath(); let simulationLogic = currentRecord.conditionsNames; - let conditionIndex = 0; + let conditionIndex = 0; for (let j = 0; j < simulationLogic.strategies.length; j++) { let strategy = simulationLogic.strategies[j]; - y = y + increment; + showLabel = true; + + if (currentRecord.strategyNumber > 0 && currentRecord.strategyNumber - 1 !== j) { showLabel = false; } + + if (showLabel) { y = y + increment; } opacity = '1.00'; label = 'Strategy: ' + strategy.name; printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); - y = y + increment; + if (showLabel) { y = y + increment; } opacity = '0.50'; label = 'Entry Points'; printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); @@ -108,7 +113,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { processSituation(situation); } - y = y + increment; + if (showLabel) { y = y + increment; } opacity = '0.50'; label = 'Exit Points'; printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); @@ -119,7 +124,9 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { processSituation(situation); } - y = y + increment; + if (currentRecord.strategyNumber - 1 !== j) { showLabel = false; } + + if (showLabel) { y = y + increment; } opacity = '0.50'; label = 'Sell Points'; printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); @@ -130,7 +137,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { processSituation(situation); } - y = y + increment; + if (showLabel) { y = y + increment; } opacity = '0.50'; label = 'Stop Loss Management'; printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); @@ -139,7 +146,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let phase = strategy.stopLoss.phases[p]; - y = y + increment; + if (showLabel) { y = y + increment; } opacity = '0.50'; label = 'Phase: ' + phase.name; printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); @@ -151,7 +158,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { } } - y = y + increment; + if (showLabel) { y = y + increment; } opacity = '0.50'; label = 'Buy Order Management'; printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); @@ -160,7 +167,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let phase = strategy.buyOrder.phases[p]; - y = y + increment; + if (showLabel) { y = y + increment; } opacity = '0.50'; label = 'Phase: ' + phase.name; printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); @@ -175,7 +182,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { function processSituation(situation) { - y = y + increment; + if (showLabel) { y = y + increment; } opacity = '0.50'; label = 'Situation: ' + situation.name; printLabel(label, X_AXIS + indent * 2, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); @@ -185,7 +192,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let condition = situation.conditions[m]; let color; - y = y + increment; + if (showLabel) { y = y + increment; } if (currentRecord.conditionsValues[conditionIndex] === 1) { opacity = '0.50' color = UI_COLOR.PATINATED_TURQUOISE; @@ -197,11 +204,12 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { label = condition.name; printLabel(label, X_AXIS + indent * 3, frameTitleHeight + frameBodyHeight * y, opacity, color); } - } function printLabel(labelToPrint, x, y, opacity, color) { + if (showLabel === false) { return; } + let labelPoint; let fontSize = 10; @@ -238,3 +246,4 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { + From 82f5f7ddbb1d0af292ba0036f901360ec44ac079 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 17 Mar 2019 18:38:12 +0100 Subject: [PATCH 023/157] Adaption for Lastes Objects coming in file --- Conditions.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Conditions.js b/Conditions.js index 054ce6179..698bad68d 100644 --- a/Conditions.js +++ b/Conditions.js @@ -310,16 +310,18 @@ let currentDate = new Date(farLeftDate.valueOf()); conditions = []; + headers = dailyFile[0]; + let lastObjects = dailyFile[1]; // Here we get the values of the last 5 objects while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); - let dailyFile = fileCursor.files.get(stringDate); + let dailyFile[2] = fileCursor.files.get(stringDate); - if (dailyFile !== undefined) { + if (dailyFile[2] !== undefined) { - for (let i = 0; i < dailyFile.length; i++) { + for (let i = 0; i < dailyFile[2].length; i++) { let record = { begin: undefined, @@ -327,9 +329,13 @@ conditions: undefined }; - record.begin = dailyFile[i][0]; - record.end = dailyFile[i][1]; - record.conditions = dailyFile[i]; + record.begin = dailyFile[2][i][0]; + record.end = dailyFile[2][i][1]; + record.strategyNumber = dailyFile[2][i][2]; + record.strategyPhase = dailyFile[2][i][3]; + record.stopLossPhase = dailyFile[2][i][4]; + record.buyOrderPhase = dailyFile[2][i][5]; + record.conditions = dailyFile[2][i][6]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -392,8 +398,9 @@ conditions = []; headers = marketFile[0]; + let lastObjects = marketFile[1]; // Here we get the values of the last 5 objects - for (let i = 0; i < marketFile[1].length; i++) { + for (let i = 0; i < marketFile[2].length; i++) { let record = { begin: undefined, @@ -401,13 +408,13 @@ conditions: undefined }; - record.begin = marketFile[1][i][0]; - record.end = marketFile[1][i][1]; - record.strategyNumber = marketFile[1][i][2]; - record.strategyPhase = marketFile[1][i][3]; - record.stopLossPhase = marketFile[1][i][4]; - record.buyOrderPhase = marketFile[1][i][5]; - record.conditions = marketFile[1][i][6]; + record.begin = marketFile[2][i][0]; + record.end = marketFile[2][i][1]; + record.strategyNumber = marketFile[2][i][2]; + record.strategyPhase = marketFile[2][i][3]; + record.stopLossPhase = marketFile[2][i][4]; + record.buyOrderPhase = marketFile[2][i][5]; + record.conditions = marketFile[2][i][6]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { From 1f253d933a51f356f64171d318a38c7196f180fc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 17 Mar 2019 20:29:37 +0100 Subject: [PATCH 024/157] Update Conditions.js --- Conditions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conditions.js b/Conditions.js index 698bad68d..00991af86 100644 --- a/Conditions.js +++ b/Conditions.js @@ -317,7 +317,7 @@ let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); - let dailyFile[2] = fileCursor.files.get(stringDate); + let dailyFile = fileCursor.files.get(stringDate); if (dailyFile[2] !== undefined) { From 827c42148da811cc9248d8dbcc2a576e9259dcce Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 17 Mar 2019 21:37:28 +0100 Subject: [PATCH 025/157] Daily Working --- Conditions.js | 8 ++++--- TradingSimulation.js | 52 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/Conditions.js b/Conditions.js index 00991af86..c921c5c40 100644 --- a/Conditions.js +++ b/Conditions.js @@ -310,8 +310,8 @@ let currentDate = new Date(farLeftDate.valueOf()); conditions = []; - headers = dailyFile[0]; - let lastObjects = dailyFile[1]; // Here we get the values of the last 5 objects + + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { @@ -319,7 +319,9 @@ let dailyFile = fileCursor.files.get(stringDate); - if (dailyFile[2] !== undefined) { + if (dailyFile !== undefined) { + + headers = dailyFile[0]; for (let i = 0; i < dailyFile[2].length; i++) { diff --git a/TradingSimulation.js b/TradingSimulation.js index 8239cb2be..568a5000c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -327,16 +327,52 @@ rate: undefined, amount: undefined, balanceA: undefined, - balanceB: undefined + balanceB: undefined, + profit: undefined, + lastProfit: undefined, + stopLoss: undefined, + roundtrips: undefined, + hits: undefined, + fails: undefined, + hitRatio: undefined, + ROI: undefined, + periods: undefined, + days: undefined, + anualizedRateOfReturn: undefined, + sellRate: undefined, + lastProfitPercent: undefined, + strategy: undefined, + strategyPhase: undefined, + buyOrder: undefined, + stopLossPhase: undefined, + buyOrderPhase: undefined }; - record.begin = marketFile[i][0]; - record.end = marketFile[i][1]; - record.type = marketFile[i][2]; - record.rate = marketFile[i][3]; - record.amount = marketFile[i][4]; - record.balanceA = marketFile[i][5]; - record.balanceB = marketFile[i][6]; + record.begin = dailyFile[i][0]; + record.end = dailyFile[i][1]; + record.type = dailyFile[i][2]; + record.rate = dailyFile[i][3]; + record.amount = dailyFile[i][4]; + record.balanceA = dailyFile[i][5]; + record.balanceB = dailyFile[i][6]; + record.profit = dailyFile[i][7]; + record.lastProfit = dailyFile[i][8]; + record.stopLoss = dailyFile[i][9]; + record.roundtrips = dailyFile[i][10]; + record.hits = dailyFile[i][11]; + record.fails = dailyFile[i][12]; + record.hitRatio = dailyFile[i][13]; + record.ROI = dailyFile[i][14]; + record.periods = dailyFile[i][15]; + record.days = dailyFile[i][16]; + record.anualizedRateOfReturn = dailyFile[i][17]; + record.sellRate = dailyFile[i][18]; + record.lastProfitPercent = dailyFile[i][19]; + record.strategy = dailyFile[i][20]; + record.strategyPhase = dailyFile[i][21]; + record.buyOrder = dailyFile[i][22]; + record.stopLossPhase = dailyFile[i][23]; + record.buyOrderPhase = dailyFile[i][24]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { From c16ee902cd35cdc8077be975e0a11d5dd2827459 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 19 Mar 2019 21:33:20 +0100 Subject: [PATCH 026/157] Better Icons Choosed --- TradingSimulation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 568a5000c..4407d28e3 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -106,8 +106,8 @@ smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); - imageStopLossPhase = loadEmoji("Objects/Emoji Objects-55.png"); - imageBuyOrderPhase = loadEmoji("Objects/Emoji Objects-114.png"); + imageStopLossPhase = loadEmoji("Nature/Emoji Natur-85.png"); + imageBuyOrderPhase = loadEmoji("Nature/Emoji Natur-67.png"); function loadEmoji(pPath) { From e387db1f913ba5312627b461be4aaee6cfd82c34 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 20 Mar 2019 22:45:38 +0100 Subject: [PATCH 027/157] Tab Button --- ConditionsPanel.js | 9 +++++++++ TradingSimulation.js | 2 +- TradingSimulationPanel.js | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index b09e6994c..e88e4509e 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -17,6 +17,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { container.frame.containerName = "Conditions Panel"; let currentRecord; + let panelTabButton return thisObject; @@ -28,12 +29,19 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - UI_PANEL.WIDTH.NORMAL * 3; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; + panelTabButton = newPanelTabButton() + panelTabButton.parentContainer = thisObject.container + panelTabButton.container.frame.parentFrame = thisObject.container.frame + panelTabButton.initialize() } function getContainer(point) { var container; + container = panelTabButton.getContainer(point) + if (container !== undefined) { return container } + /* First we check if this point is inside this space. */ if (this.container.frame.isThisPointHere(point, true) === true) { @@ -63,6 +71,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { plotCurrentRecordInfo(); + panelTabButton.draw() } diff --git a/TradingSimulation.js b/TradingSimulation.js index 4407d28e3..c4a12c786 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -106,7 +106,7 @@ smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); - imageStopLossPhase = loadEmoji("Nature/Emoji Natur-85.png"); + imageStopLossPhase = loadEmoji("Nature/Emoji Natur-71.png"); imageBuyOrderPhase = loadEmoji("Nature/Emoji Natur-67.png"); function loadEmoji(pPath) { diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index d9884e73a..9f9fb1718 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -17,6 +17,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation container.frame.containerName = "Simulated Records Panel"; let currentRecord; + let panelTabButton return thisObject; @@ -28,12 +29,19 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; + panelTabButton = newPanelTabButton() + panelTabButton.parentContainer = thisObject.container + panelTabButton.container.frame.parentFrame = thisObject.container.frame + panelTabButton.initialize() } function getContainer(point) { var container; + container = panelTabButton.getContainer(point) + if (container !== undefined) { return container } + /* First we check if this point is inside this space. */ if (this.container.frame.isThisPointHere(point, true) === true) { @@ -63,6 +71,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation plotCurrentRecordInfo(); + panelTabButton.draw() } From 9698e0fb1fc240a5c11aeaf8ccb2c415ffa9fc11 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 20 Mar 2019 23:12:47 +0100 Subject: [PATCH 028/157] Wider stop loss lines --- TradingSimulation.js | 78 ++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index c4a12c786..f49002f87 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -462,7 +462,7 @@ strategyPhase: undefined, buyOrder: undefined, stopLossPhase: undefined, - buyOrderPhase: undefined + buyOrderPhase: undefined }; record.begin = marketFile[i][0]; @@ -609,7 +609,7 @@ if (record.type === 'Buy@BuyOrder') { directionShort = -1; } if (record.type === 'Buy@StopLoss') { directionShort = 1; } - if (record.type === 'Sell') { directionShort = +1; } + if (record.type === 'Sell') { directionShort = +1; } if (strategyPhase > 0) { if (strategyPhase % 2 !== 0) { //Depending if the phase is oddd or even goes above or below. @@ -737,18 +737,22 @@ browserCanvasContext.closePath(); browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; + browserCanvasContext.lineWidth = 1 + browserCanvasContext.setLineDash([1, 4]) if (datetime !== undefined) { let dateValue = datetime.valueOf(); if (dateValue >= record.begin && dateValue <= record.end) { + browserCanvasContext.lineWidth = 5 + browserCanvasContext.setLineDash([3, 4]) /* highlight the current record */ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } } - browserCanvasContext.setLineDash([1, 4]) - browserCanvasContext.lineWidth = 1 + + browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) @@ -757,27 +761,33 @@ /* Next we are drawing the stopLoss floor / ceilling */ - browserCanvasContext.beginPath(); + for (j = 0; j < 8; j++) { + browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y); - browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y); - browserCanvasContext.closePath(); + browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y - j); + browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y - j); - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 1)'; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + browserCanvasContext.closePath(); - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + let opacity = 0.8 - j / 10 + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ''; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } } + + browserCanvasContext.lineWidth = 1 + browserCanvasContext.stroke() + } - - browserCanvasContext.lineWidth = 1 - browserCanvasContext.stroke() - if (imageStopLossPhase.isLoaded === true && stopLossPhase > 0) { browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize, imageSize, imageSize); printLabel(stopLossPhase, recordPoint5.x, recordPoint5.y - 2, '0.50'); @@ -785,27 +795,30 @@ /* Next we are drawing the Buy Order */ - browserCanvasContext.beginPath(); + for (j = 0; j < 8; j++) { + browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint8.x, recordPoint8.y); - browserCanvasContext.lineTo(recordPoint9.x, recordPoint9.y); + browserCanvasContext.moveTo(recordPoint8.x, recordPoint8.y + j); + browserCanvasContext.lineTo(recordPoint9.x, recordPoint9.y + j); - browserCanvasContext.closePath(); + browserCanvasContext.closePath(); - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', 1)'; + let opacity = 0.6 - j / 10 - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ''; - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.begin && dateValue <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } } + + browserCanvasContext.lineWidth = 1 + browserCanvasContext.stroke() } - - browserCanvasContext.lineWidth = 1 - browserCanvasContext.stroke() - if (imageBuyOrderPhase.isLoaded === true && buyOrderPhase > 0) { browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize, recordPoint9.y + imageSize / 4, imageSize, imageSize); printLabel(buyOrderPhase, recordPoint9.x - imageSize / 2, recordPoint9.y + imageSize * 1.75, '0.50'); @@ -1150,3 +1163,4 @@ + From 9133c382b5507dc07f0b301562d107e547562777 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 21 Mar 2019 08:39:06 +0100 Subject: [PATCH 029/157] Lines highlighted --- TradingSimulation.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index f49002f87..0ab6060f5 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -917,17 +917,22 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.25)'; + browserCanvasContext.setLineDash([4, 3]) + browserCanvasContext.lineWidth = 0.2 + if (datetime !== undefined) { let dateValue = datetime.valueOf(); if (dateValue >= record.begin && dateValue <= record.end) { /* highlight the current record */ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + + browserCanvasContext.setLineDash([1, 6]) + browserCanvasContext.lineWidth = 1 } } - browserCanvasContext.setLineDash([4, 3]) - browserCanvasContext.lineWidth = 0.2 + browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) @@ -1164,3 +1169,4 @@ + From 99e33f3f02b5237ba325c18fd0b122cced28b993 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 22 Mar 2019 17:24:18 +0100 Subject: [PATCH 030/157] Saira Font --- ConditionsPanel.js | 2 +- TradingSimulation.js | 19 +++++++------------ TradingSimulationPanel.js | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index e88e4509e..bbd491bed 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -222,7 +222,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let labelPoint; let fontSize = 10; - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY; + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; let label = '' + labelToPrint; if (isNaN(label) === false) { diff --git a/TradingSimulation.js b/TradingSimulation.js index 0ab6060f5..768c232ee 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -789,8 +789,8 @@ } if (imageStopLossPhase.isLoaded === true && stopLossPhase > 0) { - browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize, imageSize, imageSize); - printLabel(stopLossPhase, recordPoint5.x, recordPoint5.y - 2, '0.50'); + browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize * 1.25, imageSize, imageSize); + printLabel(stopLossPhase, recordPoint5.x - imageSize / 2, recordPoint5.y - imageSize * 1.5, '0.50'); } /* Next we are drawing the Buy Order */ @@ -820,8 +820,8 @@ browserCanvasContext.stroke() } if (imageBuyOrderPhase.isLoaded === true && buyOrderPhase > 0) { - browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize, recordPoint9.y + imageSize / 4, imageSize, imageSize); - printLabel(buyOrderPhase, recordPoint9.x - imageSize / 2, recordPoint9.y + imageSize * 1.75, '0.50'); + browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4, imageSize, imageSize); + printLabel(buyOrderPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.50'); } /* Continue with the pins --> Next stuff is to avoid text overlapping. */ @@ -917,22 +917,17 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.25)'; - browserCanvasContext.setLineDash([4, 3]) - browserCanvasContext.lineWidth = 0.2 - if (datetime !== undefined) { let dateValue = datetime.valueOf(); if (dateValue >= record.begin && dateValue <= record.end) { /* highlight the current record */ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - - browserCanvasContext.setLineDash([1, 6]) - browserCanvasContext.lineWidth = 1 } } - + browserCanvasContext.setLineDash([4, 3]) + browserCanvasContext.lineWidth = 0.2 browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) @@ -1086,7 +1081,7 @@ let labelPoint; let fontSize = 12; - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY; + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; let label = '' + labelToPrint; diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 9f9fb1718..52f9ea907 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -179,7 +179,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let labelPoint; let fontSize = 10; - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY; + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; let label = '' + labelToPrint; if (isNaN(label) === false) { From d2bec1a39bffd4c487842eb4b554956cf5cbc794 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Mar 2019 10:02:57 +0100 Subject: [PATCH 031/157] Finalize() function implemented --- Conditions.js | 68 +++++++++++++++++++------------------------- TradingSimulation.js | 42 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 38 deletions(-) diff --git a/Conditions.js b/Conditions.js index c921c5c40..be917ba1c 100644 --- a/Conditions.js +++ b/Conditions.js @@ -12,6 +12,7 @@ // Main functions and properties. initialize: initialize, + finalize: finalize, container: undefined, getContainer: getContainer, setTimePeriod: setTimePeriod, @@ -50,18 +51,37 @@ let conditions = []; let headers; - let smileyHappy; - let smileySad; - let smileyGhost; - let smileyMonkeyEyes; - let smileyMonkeyEars; - let imageStrategy; - let imageStrategyPhase; - let imageStopLossPhase; - let imageBuyOrderPhase; - return thisObject; + function finalize() { + try { + + if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } + + /* Stop listening to the necesary events. */ + + viewPort.eventHandler.stopListening("Zoom Changed", onZoomChanged); + viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); + canvas.eventHandler.stopListening("Drag Finished", onDragFinished); + + /* Destroyd References */ + + marketFiles = undefined; + dailyFiles = undefined; + + datetime = undefined; + timePeriod = undefined; + + marketFile = undefined; + fileCursor = undefined; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + } + } + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { try { @@ -98,34 +118,6 @@ recalculate(); - /* Loading a few icons */ - - smileyHappy = loadEmoji("Smiley/Emoji Smiley-51.png"); - smileySad = loadEmoji("Smiley/Emoji Smiley-26.png"); - smileyGhost = loadEmoji("Objects/Emoji Objects-12.png"); - smileyMonkeyEyes = loadEmoji("Smiley/Emoji Smiley-85.png"); - smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); - imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); - imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); - imageStopLossPhase = loadEmoji("Objects/Emoji Objects-55.png"); - imageBuyOrderPhase = loadEmoji("Objects/Emoji Objects-114.png"); - - function loadEmoji(pPath) { - - let newImage; - - newImage = new Image(); - newImage.onload = onImageLoaded; - - function onImageLoaded() { - newImage.isLoaded = true; - } - - newImage.src = window.canvasApp.urlPrefix + "Images/Emoji/" + pPath; - - return newImage; - } - callBackFunction(); } catch (err) { diff --git a/TradingSimulation.js b/TradingSimulation.js index 768c232ee..a80ab4e41 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -12,6 +12,7 @@ // Main functions and properties. initialize: initialize, + finalize: finalize, container: undefined, getContainer: getContainer, setTimePeriod: setTimePeriod, @@ -61,6 +62,47 @@ return thisObject; + function finalize() { + try { + + if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } + + /* Stop listening to the necesary events. */ + + viewPort.eventHandler.stopListening("Zoom Changed", onZoomChanged); + viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); + canvas.eventHandler.stopListening("Drag Finished", onDragFinished); + + /* icons */ + + smileyHappy = undefined; + smileySad = undefined; + smileyGhost = undefined; + smileyMonkeyEyes = undefined; + smileyMonkeyEars = undefined; + imageStrategy = undefined; + imageStrategyPhase = undefined; + imageStopLossPhase = undefined; + imageBuyOrderPhase = undefined; + + /* Destroy References */ + + marketFiles = undefined; + dailyFiles = undefined; + + datetime = undefined; + timePeriod = undefined; + + marketFile = undefined; + fileCursor = undefined; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + } + } + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { try { From f0fc58433729b14356356840343a527f25de67d7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 31 Mar 2019 09:29:00 +0200 Subject: [PATCH 032/157] Work in progress on the Simulation Executor --- Project.njsproj | 3 + SimulationExecution.js | 955 +++++++++++++++++++++++++++++++++++++++ this.plotter.config.json | 8 + 3 files changed, 966 insertions(+) create mode 100644 SimulationExecution.js diff --git a/Project.njsproj b/Project.njsproj index 22f4dcca1..f3ac2708b 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -23,6 +23,9 @@ Code + + Code + diff --git a/SimulationExecution.js b/SimulationExecution.js new file mode 100644 index 000000000..d912be97b --- /dev/null +++ b/SimulationExecution.js @@ -0,0 +1,955 @@ +function newAAMastersPlottersTradingSimulationSimulationExecution() { + + const MODULE_NAME = "Simulation Execution Plotter"; + const INFO_LOG = false; + const INTENSIVE_LOG = false; + const ERROR_LOG = true; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; + + let thisObject = { + + // Main functions and properties. + + initialize: initialize, + finalize: finalize, + container: undefined, + getContainer: getContainer, + setTimePeriod: setTimePeriod, + setDatetime: setDatetime, + recalculateScale: recalculateScale, + draw: draw, + payload: { + profile: { + position: { + x: 0, + y: 0 + }, + visible: false + }, + notes: [] + } + }; + + /* this is part of the module template */ + + let container = newContainer(); // Do not touch this 3 lines, they are just needed. + container.initialize(); + thisObject.container = container; + + let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + + let timePeriod; // This will hold the current Time Period the user is at. + let datetime; // This will hold the current Datetime the user is at. + + /* these are module specific variables: */ + + let fileSequence; + let plotElements = []; // This is where the elements to be plotted are stored before plotting. + let plotLines = []; // Here we store the lines of open positions. + let notes = []; // Here we store the notes with messages from the bot. + + let notesChangedEventRaised = true; // This controls when to raise the event that notes changed. + + let previousNotesSetKey; + let currentNotesSetKey; + + return thisObject; + + function finalize() { + try { + + if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } + + /* Stop listening to the necesary events. */ + + viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); + fileSequence.eventHandler.stopListening("Files Updated", onFilesUpdated); + + /* Destroyd References */ + + datetime = undefined; + timePeriod = undefined; + + fileSequence = undefined; + plotElements = undefined; + plotLines = undefined; + notes = undefined; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + } + } + + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + + datetime = pDatetime; + timePeriod = pTimePeriod; + + fileSequence = pStorage.fileSequences[0]; + + recalculate(callBackFunction); + recalculateScale(callBackFunction); + + fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. + viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } + } + + function getContainer(point) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } + + let container; + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + } + } + + function onFilesUpdated() { + + recalculate(); + + } + + function setTimePeriod(pTimePeriod) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } + + timePeriod = pTimePeriod; + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err); } + } + } + + function setDatetime(newDatetime) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } + + datetime = newDatetime; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err); } + } + } + + function onOffsetChanged() { + + if (Math.random() * 100 > 95) { + + recalculate() + }; + + } + + function recalculate(callBackFunction) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + + if (fileSequence === undefined) { return; } + + /* + + We are going to filter the records depending on the Time Period. We want that for a 1 min time peroid all the records appears on screen, + but for higher periods, we will filter out some records, so that they do not overlap ever. + + */ + + plotElements = []; + plotLines = []; + notes = []; + + let lastSellRate; + let lastSellDate; + let sellExecRate; + + let lastBuyRate; + let lastBuyDate; + let buyExecRate; + + let maxSequence = fileSequence.getFilesLoaded(); + + for (let j = 0; j < maxSequence; j++) { + + let file = fileSequence.getFile(j); + + let history = []; + let lines = []; + + /* First the small balls */ + + const ONE_MIN_IN_MILISECONDS = 60 * 1000; + let step = timePeriod / ONE_MIN_IN_MILISECONDS; + let step = 1; // For now we dont discard records depending on the zoom level. + + let i = 0; + let lastRecordPushed = 0; + + for (i = 0; i < file.length; i = i + step) { + + let newHistoryRecord = { + + date: Math.trunc(file[i][0] / 60000) * 60000 + 30000, + buyAvgRate: file[i][1], + sellAvgRate: file[i][2], + + lastSellRate: file[i][3], + sellExecRate: file[i][4], + lastBuyRate: file[i][5], + buyExecRate: file[i][6], + + marketRate: file[i][7], + newPositions: file[i][8], + newTrades: file[i][9], + movedPositions: file[i][10], + profitsAssetA: file[i][11], + profitsAssetB: file[i][12], + combinedProfitsA: file[i][13], + combinedProfitsB: file[i][14], + + messageRelevance: file[i][15], + messageTitle: file[i][16], + messageBody: file[i][17], + + mqServiceMessages: file[i][18] + }; + + /* + + Now we are going to inflate the mqService Messages in order to use them during the plotting. + + */ + + if (newHistoryRecord.mqServiceMessages !== undefined) { + for (let i = 0; i < newHistoryRecord.mqServiceMessages.length; i++) { + let mqMessage = mqServiceMessages[i]; + } + } + + /* Finally we add this History Record to the Array */ + + history.push(newHistoryRecord); + lastRecordPushed = i; + + /* Here we build the lines. */ + + if (timePeriod <= 1 * 60 * 1000) { + + if (newHistoryRecord.lastSellRate > 0) { + + lastSellRate = newHistoryRecord.lastSellRate; + lastSellDate = newHistoryRecord.date; + + } + + if (newHistoryRecord.sellExecRate > 0) { + + let newLine = { + type: "sell", + x1: lastSellDate, + y1: lastSellRate, + x2: newHistoryRecord.date, + y2: newHistoryRecord.sellExecRate + }; + + lines.push(newLine); + + } + + if (newHistoryRecord.lastBuyRate > 0) { + + lastBuyRate = newHistoryRecord.lastBuyRate; + lastBuyDate = newHistoryRecord.date; + + } + + if (newHistoryRecord.buyExecRate > 0) { + + let newLine = { + type: "buy", + x1: lastBuyDate, + y1: lastBuyRate, + x2: newHistoryRecord.date, + y2: newHistoryRecord.buyExecRate + }; + + lines.push(newLine); + + } + } + + } + + /* We allways want to put the last record of the file on the filterd dataset, so as to allways show the latest advance of the bot. */ + + i = file.length - 1; + + if (lastRecordPushed !== i) { + + let newHistoryRecord = { + + date: Math.trunc(file[i][0] / 60000) * 60000 + 30000, + buyAvgRate: file[i][1], + sellAvgRate: file[i][2], + + lastSellRate: file[i][3], + sellExecRate: file[i][4], + lastBuyRate: file[i][5], + buyExecRate: file[i][6], + + marketRate: file[i][7], + newPositions: file[i][8], + newTrades: file[i][9], + movedPositions: file[i][10], + profitsAssetA: file[i][11], + profitsAssetB: file[i][12], + combinedProfitsA: file[i][13], + combinedProfitsB: file[i][14], + + messageRelevance: file[i][15], + messageTitle: file[i][16], + messageBody: file[i][17], + + mqServiceMessages: file[i][18] + }; + + history.push(newHistoryRecord); + + } + + + /* Second we process the text */ + + for (let i = 0; i < file.length; i++) { + + let newHistoryRecord = { + + date: Math.trunc(file[i][0] / 60000) * 60000 + 30000, + buyAvgRate: file[i][1], + sellAvgRate: file[i][2], + + lastSellRate: file[i][3], + sellExecRate: file[i][4], + lastBuyRate: file[i][5], + buyExecRate: file[i][6], + + marketRate: file[i][7], + newPositions: file[i][8], + newTrades: file[i][9], + movedPositions: file[i][10], + profitsAssetA: file[i][11], + profitsAssetB: file[i][12], + combinedProfitsA: file[i][13], + combinedProfitsB: file[i][14], + + messageRelevance: file[i][15], + messageTitle: file[i][16], + messageBody: file[i][17] + }; + + if (newHistoryRecord.messageTitle !== "" && newHistoryRecord.messageBody !== "") { + + if (newHistoryRecord.messageRelevance >= 0 && newHistoryRecord.messageRelevance <= 10) { + + let relevanceTimePeriod = (dailyFilePeriods[10 - newHistoryRecord.messageRelevance][0]); + + if (timePeriod <= relevanceTimePeriod) { + + let note = { + title: newHistoryRecord.messageTitle, + body: newHistoryRecord.messageBody, + date: newHistoryRecord.date, + rate: newHistoryRecord.marketRate, + position: { + x: 0, + y: 0 + }, + visible: false + }; + + notes.push(note); + } + } + } + } + + plotElements.push(history); + plotLines.push(lines); + + } + + notesChangedEventRaised = false; + + thisObject.container.eventHandler.raiseEvent("History Changed", history); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } + } + + function recalculateScale(callBackFunction) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); } + + if (fileSequence === undefined) { return; } // We need the market file to be loaded to make the calculation. + + if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + + let minValue = { + x: EARLIEST_DATE.valueOf(), + y: 0 + }; + + let maxValue = { + x: MAX_PLOTABLE_DATE.valueOf(), + y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + }; + + + timeLineCoordinateSystem.initialize( + minValue, + maxValue, + thisObject.container.frame.width, + thisObject.container.frame.height + ); + + function getMaxRate() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> getMaxRate > Entering function."); } + + let maxValue = 0; + + let maxSequence = fileSequence.getFilesLoaded(); + + for (let j = 0; j < maxSequence; j++) { + + let file = fileSequence.getFile(j); + + for (let i = 0; i < file.length; i++) { + + let currentMax = file[i][1] + file[i][2]; // 1 = rates. + + if (maxValue < currentMax) { + maxValue = currentMax; + } + } + } + + return maxValue; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> getMaxRate -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } + } + + function draw() { + + try { + + if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); } + + plotChart(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err); } + } + } + + function plotChart() { + + try { + + if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } + + let point = { + x: 0, + y: 0 + }; + + let history; + + for (let j = 0; j < plotElements.length; j++) { + + let history = plotElements[j]; + + for (let i = 0; i < history.length; i++) { + + record = history[i]; + + let timestamp = Math.trunc(record.date / timePeriod) * timePeriod + timePeriod / 2; + + point = { + x: timestamp, + y: record.marketRate + }; + + point = timeLineCoordinateSystem.transformThisPoint(point); + point = transformThisPoint(point, thisObject.container); + + if (point.x < viewPort.visibleArea.bottomLeft.x || point.x > viewPort.visibleArea.bottomRight.x) { continue; } + + point = viewPort.fitIntoVisibleArea(point); + + let isCurrentRecord = false; + + if (datetime !== undefined) { + let dateValue = datetime.valueOf(); + if (dateValue >= record.date - timePeriod / 2 && dateValue <= record.date + timePeriod / 2 - 1) { + isCurrentRecord = true; + } + } + + let radius = 3; + + let opacity = '0.2'; + + browserCanvasContext.lineWidth = 1; + + /* Outer Circle */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.LIGHT + ', ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true); + browserCanvasContext.closePath(); + + if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + browserCanvasContext.fill(); + } + + browserCanvasContext.stroke(); + + /* Draw a red inverted triangle on exec sell */ + + if (record.sellExecRate > 0) { + + opacity = '0.5'; + + let point1 = { + x: record.date, + y: record.sellExecRate + }; + + let point2 = { + x: record.date + timePeriod / 7 * 2, + y: record.sellExecRate + }; + + let point3 = { + x: record.date - timePeriod / 7 * 2, + y: record.sellExecRate + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = transformThisPoint(point3, thisObject.container); + point3 = viewPort.fitIntoVisibleArea(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y - diff; + point3.y = point3.y - diff; + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(219, 18, 18, ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, ' + opacity + ')'; + browserCanvasContext.stroke(); + + } + + /* Draw a green triangle on exec buy */ + + if (record.buyExecRate > 0) { + + opacity = '0.5'; + + let point1 = { + x: record.date, + y: record.buyExecRate + }; + + let point2 = { + x: record.date + timePeriod / 7 * 2, + y: record.buyExecRate + }; + + let point3 = { + x: record.date - timePeriod / 7 * 2, + y: record.buyExecRate + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = transformThisPoint(point3, thisObject.container); + point3 = viewPort.fitIntoVisibleArea(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y + diff; + point3.y = point3.y + diff; + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(64, 217, 26, ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; + browserCanvasContext.stroke(); + + } + + /* Draw a red inverted triangle on sell */ + + if (record.lastSellRate > 0) { + + opacity = '0.5'; + + let point1 = { + x: record.date, + y: record.lastSellRate + }; + + let point2 = { + x: record.date + timePeriod / 7 * 2, + y: record.lastSellRate + }; + + let point3 = { + x: record.date - timePeriod / 7 * 2, + y: record.lastSellRate + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = transformThisPoint(point3, thisObject.container); + point3 = viewPort.fitIntoVisibleArea(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y - diff; + point3.y = point3.y - diff; + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(255, 255, 255, ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, ' + opacity + ')'; + browserCanvasContext.stroke(); + + } + + /* Draw a green triangle on buy */ + + if (record.lastBuyRate > 0) { + + opacity = '0.5'; + + let point1 = { + x: record.date, + y: record.lastBuyRate + }; + + let point2 = { + x: record.date + timePeriod / 7 * 2, + y: record.lastBuyRate + }; + + let point3 = { + x: record.date - timePeriod / 7 * 2, + y: record.lastBuyRate + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = transformThisPoint(point3, thisObject.container); + point3 = viewPort.fitIntoVisibleArea(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y + diff; + point3.y = point3.y + diff; + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(255, 255, 255, ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; + browserCanvasContext.stroke(); + + } + + + /* Since there is at least some point plotted, then the profile should be visible. */ + + thisObject.payload.profile.visible = true; + } + + /* Draw the lines connecting plot elements. */ + + let lines = plotLines[j]; + + for (let i = 0; i < lines.length; i++) { + + let line = lines[i]; + + opacity = '0.2'; + + let point1 = { + x: line.x1, + y: line.y1 + }; + + let point2 = { + x: line.x2, + y: line.y2 + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + + browserCanvasContext.closePath(); + + if (line.type === "sell") { + + browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, ' + opacity + ')'; + + } else { + + browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; + + } + + browserCanvasContext.stroke(); + + } + + /* Now we calculate the anchor position of notes. */ + + currentNotesSetKey = ""; + + for (let i = 0; i < notes.length; i++) { + + let note = notes[i]; + + opacity = '0.2'; + + note.position = { + x: note.date, + y: note.rate + }; + + note.position = timeLineCoordinateSystem.transformThisPoint(note.position); + note.position = transformThisPoint(note.position, thisObject.container); + + if (note.position.x < (viewPort.visibleArea.bottomRight.x / 2) * (-1) || note.position.x > (viewPort.visibleArea.bottomRight.x) * (1.5)) { + note.visible = false; + currentNotesSetKey = currentNotesSetKey + "0"; + } else { + note.visible = true; + currentNotesSetKey = currentNotesSetKey + "1"; + } + } + + if (notesChangedEventRaised === false) { + + /* In this case the event is raised because we might have a different set of notes. */ + + thisObject.container.eventHandler.raiseEvent("Notes Changed", notes); + thisObject.payload.notes = notes; + + notesChangedEventRaised = true; + + } else { + + if (currentNotesSetKey !== previousNotesSetKey) { + + /* In this case the event is raised because the visibility of some of the notes changed. */ + + thisObject.container.eventHandler.raiseEvent("Notes Changed", notes); + thisObject.payload.notes = notes; + + previousNotesSetKey = currentNotesSetKey; + } + } + + } + + /* + + We replace the coordinate of the profile point so that whoever has a reference to it, gets the new position. + We will use the last point plotted on screen as the profilePoint. + + */ + + thisObject.payload.profile.position.x = point.x; + thisObject.payload.profile.position.y = point.y; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err); } + } + } +} + diff --git a/this.plotter.config.json b/this.plotter.config.json index 1976dcda4..38e54024c 100644 --- a/this.plotter.config.json +++ b/this.plotter.config.json @@ -28,6 +28,14 @@ "event": "Current Condition Record Changed" } ] + }, + { + "codeName": "SimulationExecution", + "moduleName": "SimulationExecution", + "description": "Plots Simulation Execution.", + "profilePicture": "SimulationExecution.png", + "panels": [ + ] } ] } \ No newline at end of file From 8df97497df0a9194510ce313a4f415cc4415a107 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 11 Apr 2019 13:56:36 +0200 Subject: [PATCH 033/157] Adapted to new version of Canvas App --- Conditions.js | 30 +++++++-------- SimulationExecution.js | 2 +- TradingSimulation.js | 83 ++++++++++++++++++++---------------------- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/Conditions.js b/Conditions.js index be917ba1c..cc703ee01 100644 --- a/Conditions.js +++ b/Conditions.js @@ -78,7 +78,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } @@ -122,7 +122,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err.stack); } } } @@ -149,7 +149,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err = " + err.stack); } } } @@ -169,7 +169,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } } } @@ -207,7 +207,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } } } @@ -235,7 +235,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err = " + err.stack); } } } @@ -251,7 +251,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err.stack); } } } @@ -275,7 +275,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } } } @@ -368,7 +368,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err = " + err.stack); } } } @@ -427,7 +427,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err = " + err.stack); } } } @@ -480,7 +480,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } } } @@ -517,7 +517,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } } } @@ -532,7 +532,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } } } @@ -549,7 +549,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } } } @@ -563,7 +563,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err = " + err.stack); } } } } diff --git a/SimulationExecution.js b/SimulationExecution.js index d912be97b..701d65563 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -78,7 +78,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } diff --git a/TradingSimulation.js b/TradingSimulation.js index a80ab4e41..284937281 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -73,6 +73,7 @@ viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); canvas.eventHandler.stopListening("Drag Finished", onDragFinished); + thisObject.container.eventHandler.stopListening('Dimmensions Changed') /* icons */ @@ -99,7 +100,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } @@ -139,6 +140,13 @@ recalculate(); + /* Ready for when dimmension changes. */ + + thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + recalculateScale() + recalculate(); + }) + /* Loading a few icons */ smileyHappy = loadEmoji("Smiley/Emoji Smiley-51.png"); @@ -171,7 +179,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err.stack); } } } @@ -198,7 +206,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err = " + err.stack); } } } @@ -218,7 +226,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } } } @@ -256,7 +264,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } } } @@ -284,7 +292,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err = " + err.stack); } } } @@ -300,7 +308,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err.stack); } } } @@ -324,7 +332,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } } } @@ -453,7 +461,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err = " + err.stack); } } } @@ -550,7 +558,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err = " + err.stack); } } } @@ -603,7 +611,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } } } @@ -611,7 +619,8 @@ try { - if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } + let userPosition = getUserPosition() + let userPositionDate = userPosition.point.x let directionShort; let directionLong; @@ -782,19 +791,14 @@ browserCanvasContext.lineWidth = 1 browserCanvasContext.setLineDash([1, 4]) - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { - browserCanvasContext.lineWidth = 5 - browserCanvasContext.setLineDash([3, 4]) + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + browserCanvasContext.lineWidth = 5 + browserCanvasContext.setLineDash([3, 4]) - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } - - browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) @@ -817,13 +821,10 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ''; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + if (userPositionDate >= record.begin && userPositionDate <= record.end) { - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } browserCanvasContext.lineWidth = 1 @@ -849,13 +850,10 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ''; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + if (userPositionDate >= record.begin && userPositionDate <= record.end) { - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } browserCanvasContext.lineWidth = 1 @@ -959,13 +957,10 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.25)'; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + if (userPositionDate >= record.begin && userPositionDate <= record.end) { - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } browserCanvasContext.setLineDash([4, 3]) @@ -1140,7 +1135,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } } } @@ -1155,7 +1150,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } } } @@ -1172,7 +1167,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } } } @@ -1186,7 +1181,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err = " + err.stack); } } } } From 520f499543373f0dbe028c9eedb0677dbdcf9bb3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 17 Apr 2019 20:40:52 +0200 Subject: [PATCH 034/157] Variable Name Standarization --- Conditions.js | 2 +- SimulationExecution.js | 4 ++-- TradingSimulation.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Conditions.js b/Conditions.js index cc703ee01..c4c2fd96a 100644 --- a/Conditions.js +++ b/Conditions.js @@ -442,7 +442,7 @@ if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { - x: EARLIEST_DATE.valueOf(), + x: MIN_PLOTABLE_DATE.valueOf(), y: 0 }; diff --git a/SimulationExecution.js b/SimulationExecution.js index 701d65563..cc06fb980 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -220,7 +220,7 @@ const ONE_MIN_IN_MILISECONDS = 60 * 1000; let step = timePeriod / ONE_MIN_IN_MILISECONDS; - let step = 1; // For now we dont discard records depending on the zoom level. + step = 1; // For now we dont discard records depending on the zoom level. let i = 0; let lastRecordPushed = 0; @@ -440,7 +440,7 @@ if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { - x: EARLIEST_DATE.valueOf(), + x: MIN_PLOTABLE_DATE.valueOf(), y: 0 }; diff --git a/TradingSimulation.js b/TradingSimulation.js index 284937281..b37c0e8ae 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -573,7 +573,7 @@ if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { - x: EARLIEST_DATE.valueOf(), + x: MIN_PLOTABLE_DATE.valueOf(), y: 0 }; From 8c0feba9780a11724771060174879105921f0d79 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 20 Apr 2019 12:01:05 +0200 Subject: [PATCH 035/157] Allow to show only some time periods --- Conditions.js | 18 +++++++++++------- TradingSimulation.js | 16 ++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Conditions.js b/Conditions.js index c4c2fd96a..03f92778e 100644 --- a/Conditions.js +++ b/Conditions.js @@ -197,11 +197,9 @@ let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); - if (newFileCursor !== undefined) { - - fileCursor = newFileCursor; - recalculate(); - } + fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. + recalculate(); + } } @@ -285,9 +283,15 @@ if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } - if (fileCursor === undefined) { return; } // We need to wait + if (fileCursor === undefined) { + conditions = []; + return; + } // We need to wait - if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor + if (fileCursor.files.size === 0) { + conditions = []; + return; + } // We need to wait until there are files in the cursor let daysOnSides = getSideDays(timePeriod); diff --git a/TradingSimulation.js b/TradingSimulation.js index b37c0e8ae..84dae0166 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -254,11 +254,9 @@ let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); - if (newFileCursor !== undefined) { + fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. + recalculate(); - fileCursor = newFileCursor; - recalculate(); - } } } @@ -342,9 +340,15 @@ if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } - if (fileCursor === undefined) { return; } // We need to wait + if (fileCursor === undefined) { + records = []; + return; + } // We need to wait - if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor + if (fileCursor.files.size === 0) { + records = []; + return; + } // We need to wait until there are files in the cursor let daysOnSides = getSideDays(timePeriod); From 1bf9c85bfd70b11c122b45bad3e4fbb93c054ecd Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 20 Apr 2019 12:06:35 +0200 Subject: [PATCH 036/157] Cleaning Panel when there is no valid data --- Conditions.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Conditions.js b/Conditions.js index 03f92778e..a007323d6 100644 --- a/Conditions.js +++ b/Conditions.js @@ -494,6 +494,8 @@ if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } + thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", undefined); + let conditionRecord; for (let i = 0; i < conditions.length; i++) { From d4be90b2c9d68e502c0ec9fb5b7f9bac17d4fca6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 22 Apr 2019 14:04:40 +0200 Subject: [PATCH 037/157] Improvements on the plotting --- TradingSimulation.js | 48 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 84dae0166..16f23bb5c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -52,7 +52,7 @@ let smileyHappy; let smileySad; - let smileyGhost; + let strategyImages = []; let smileyMonkeyEyes; let smileyMonkeyEars; let imageStrategy; @@ -60,6 +60,8 @@ let imageStopLossPhase; let imageBuyOrderPhase; + let lastStrategyImage + return thisObject; function finalize() { @@ -79,7 +81,7 @@ smileyHappy = undefined; smileySad = undefined; - smileyGhost = undefined; + strategyImages = undefined; smileyMonkeyEyes = undefined; smileyMonkeyEars = undefined; imageStrategy = undefined; @@ -151,7 +153,6 @@ smileyHappy = loadEmoji("Smiley/Emoji Smiley-51.png"); smileySad = loadEmoji("Smiley/Emoji Smiley-26.png"); - smileyGhost = loadEmoji("Objects/Emoji Objects-12.png"); smileyMonkeyEyes = loadEmoji("Smiley/Emoji Smiley-85.png"); smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); @@ -159,6 +160,11 @@ imageStopLossPhase = loadEmoji("Nature/Emoji Natur-71.png"); imageBuyOrderPhase = loadEmoji("Nature/Emoji Natur-67.png"); + for (let i = 1; i < 15; i++) { + let strategyImage = loadEmoji("Symbols/Emoji Symbols-" + (112 + i) + ".png"); + strategyImages.push(strategyImage); + } + function loadEmoji(pPath) { let newImage; @@ -984,26 +990,13 @@ function longPinHead() { + if (strategy < 15 && strategy > 0) { + imageToDraw = strategyImages[strategy - 1]; + lastStrategyImage = imageToDraw; + } + if (strategy === 0) { - - line1 = 'Strategy'; - line2 = 'Exit'; - - imageToDraw = smileyGhost; - } - if (strategy === 1) { - - line1 = 'Trend'; - line2 = 'Following'; - - imageToDraw = smileyGhost; - } - if (strategy === 2) { - - line1 = 'Range'; - line2 = 'Trading'; - - imageToDraw = smileyGhost; + imageToDraw = lastStrategyImage; } if (imageToDraw !== undefined) { @@ -1044,28 +1037,28 @@ if (record.type === 'Buy@StopLoss') { - line1 = 'Stop Loss hit.'; + line1 = 'Stopped'; } else { - line1 = 'Buy Order hit.'; + line1 = 'Profit Taken'; } if (record.lastProfit < 0) { - line2 = 'Loss: ' + (record.lastProfitPercent).toFixed(2) + ' %'; + line2 = (record.lastProfitPercent).toFixed(2) + ' %'; imageToDraw = smileySad; } else { - line2 = 'Profit: ' + (record.lastProfitPercent).toFixed(2) + ' %'; + line2 = (record.lastProfitPercent).toFixed(2) + ' %'; imageToDraw = smileyHappy; } } if (record.type === 'Sell') { - line1 = 'Sold'; + line1 = 'Entering'; line2 = ''; imageToDraw = smileyMonkeyEyes; @@ -1206,3 +1199,4 @@ + From 427da855a07a1df913d884ece08767aae2e312b1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 22 Apr 2019 17:22:37 +0200 Subject: [PATCH 038/157] Strategy Objects being displayed --- Conditions.js | 36 ++++++++++-------- TradingSimulation.js | 90 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 30 deletions(-) diff --git a/Conditions.js b/Conditions.js index a007323d6..7aad536a4 100644 --- a/Conditions.js +++ b/Conditions.js @@ -64,6 +64,7 @@ viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); canvas.eventHandler.stopListening("Drag Finished", onDragFinished); + thisObject.container.eventHandler.stopListening('Dimmensions Changed') /* Destroyd References */ @@ -118,6 +119,13 @@ recalculate(); + /* Ready for when dimmension changes. */ + + thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + recalculateScale() + recalculate(); + }) + callBackFunction(); } catch (err) { @@ -492,7 +500,8 @@ try { - if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } + let userPosition = getUserPosition() + let userPositionDate = userPosition.point.x thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", undefined); @@ -503,21 +512,18 @@ conditionRecord = conditions[i]; /* Send the current record to the panel */ + + if (userPositionDate >= conditionRecord.begin && userPositionDate <= conditionRecord.end) { - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= conditionRecord.begin && dateValue <= conditionRecord.end) { - - let currentRecord = { - conditionsNames: headers, - strategyNumber: conditionRecord.strategyNumber, - strategyPhase: conditionRecord.strategyPhase, - stopLossPhase: conditionRecord.stopLossPhase, - buyOrderPhase: conditionRecord.buyOrderPhase, - conditionsValues: conditionRecord.conditions - }; - thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", currentRecord); - } + let currentRecord = { + conditionsNames: headers, + strategyNumber: conditionRecord.strategyNumber, + strategyPhase: conditionRecord.strategyPhase, + stopLossPhase: conditionRecord.stopLossPhase, + buyOrderPhase: conditionRecord.buyOrderPhase, + conditionsValues: conditionRecord.conditions + }; + thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", currentRecord); } } diff --git a/TradingSimulation.js b/TradingSimulation.js index 16f23bb5c..29895f6e4 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -60,8 +60,6 @@ let imageStopLossPhase; let imageBuyOrderPhase; - let lastStrategyImage - return thisObject; function finalize() { @@ -641,19 +639,26 @@ let lastLongImageUp = 0; let lastLongImageDown = 0; + let strategy = { + begin: undefined, + end: undefined, + image: undefined, + entryPoint: undefined + } + /* Now we calculate and plot the records */ for (let i = 1; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 record = records[i]; directionShort = 0; - let strategy; + let strategyNumber; let strategyPhase = 0; let stopLossPhase = 0; let buyOrderPhase = 0; if (record.strategy !== records[i - 1].strategy) { // When a change in the strategy field is detected, it is time to plot it. - strategy = record.strategy; + strategyNumber = record.strategy; } if (record.strategyPhase !== records[i - 1].strategyPhase) { @@ -680,12 +685,12 @@ } } - if (strategy === 0) { + if (strategyNumber === 0) { directionLong = -1; } - if (strategy > 0) { - directionLong = 1; + if (strategyNumber > 0) { + directionLong = -1; } let recordPoint1 = { @@ -775,7 +780,7 @@ continue; } - recordPoint2.y = recordPoint1.y - 200 * directionLong; + recordPoint2.y = recordPoint1.y - 2000 * directionLong; recordPoint3.y = recordPoint1.y - 100 * directionShort; recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); @@ -909,7 +914,7 @@ let noLongTextDown = false; if ( - strategy > 0 || + strategyNumber > 0 || strategyPhase > 0 ) { @@ -937,7 +942,7 @@ if ( - strategy !== undefined + strategyNumber !== undefined ) { /* Next we are drawing the LONG stick */ @@ -990,13 +995,56 @@ function longPinHead() { - if (strategy < 15 && strategy > 0) { - imageToDraw = strategyImages[strategy - 1]; - lastStrategyImage = imageToDraw; + if (strategyNumber < 15 && strategyNumber > 0) { + strategy.image = strategyImages[strategyNumber - 1]; + strategy.entryPoint = recordPoint2; + strategy.begin = record.begin + strategy.end = record.end + + + if (strategy.entryPoint !== undefined) { + + /* Draw the line that represents the duration of an open strategy */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(strategy.entryPoint.x + imageSize / 2, strategy.entryPoint.y); + browserCanvasContext.lineTo(recordPoint2.x - imageSize / 2, recordPoint2.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; + browserCanvasContext.lineWidth = 0 + browserCanvasContext.setLineDash([1, 2]) + + browserCanvasContext.stroke() + + browserCanvasContext.setLineDash([0, 0]) + } + + imageToDraw = strategy.image; + } - if (strategy === 0) { - imageToDraw = lastStrategyImage; + if (strategyNumber === 0) { + + if (strategy.entryPoint !== undefined) { + /* Draw the line that represents the duration of closed strategy */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(strategy.entryPoint.x + imageSize / 2, strategy.entryPoint.y); + browserCanvasContext.lineTo(recordPoint2.x - imageSize / 2, recordPoint2.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; + browserCanvasContext.lineWidth = 1 + + browserCanvasContext.stroke() + } + + imageToDraw = strategy.image; } if (imageToDraw !== undefined) { @@ -1007,6 +1055,15 @@ } } + if (strategyNumber === 0) { + strategy = { + begin: undefined, + end: undefined, + image: undefined, + entryPoint: undefined + } + } + if ( recordPoint2.x < viewPort.visibleArea.topLeft.x + 250 || @@ -1199,4 +1256,7 @@ + + + From d1174988f4ff4466fd02135a18826818f3736afe Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 22 Apr 2019 17:32:37 +0200 Subject: [PATCH 039/157] Cleaning --- TradingSimulation.js | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 29895f6e4..add77f763 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -1001,27 +1001,6 @@ strategy.begin = record.begin strategy.end = record.end - - if (strategy.entryPoint !== undefined) { - - /* Draw the line that represents the duration of an open strategy */ - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(strategy.entryPoint.x + imageSize / 2, strategy.entryPoint.y); - browserCanvasContext.lineTo(recordPoint2.x - imageSize / 2, recordPoint2.y); - - browserCanvasContext.closePath(); - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; - browserCanvasContext.lineWidth = 0 - browserCanvasContext.setLineDash([1, 2]) - - browserCanvasContext.stroke() - - browserCanvasContext.setLineDash([0, 0]) - } - imageToDraw = strategy.image; } @@ -1258,5 +1237,6 @@ + From 1c22398e0b6d1e91137982976362aac05b3aec17 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 22 Apr 2019 18:37:07 +0200 Subject: [PATCH 040/157] Trade Triangle done --- TradingSimulation.js | 127 +++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 72 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index add77f763..0f1ece60c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -646,6 +646,13 @@ entryPoint: undefined } + let trade = { + begin: undefined, + end: undefined, + image: undefined, + entryPoint: undefined + } + /* Now we calculate and plot the records */ for (let i = 1; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 @@ -673,8 +680,8 @@ buyOrderPhase = record.buyOrderPhase; } - if (record.type === 'Buy@BuyOrder') { directionShort = -1; } - if (record.type === 'Buy@StopLoss') { directionShort = 1; } + if (record.type === 'Buy@BuyOrder') { directionShort = +1; } + if (record.type === 'Buy@StopLoss') { directionShort = +1; } if (record.type === 'Sell') { directionShort = +1; } if (strategyPhase > 0) { @@ -781,7 +788,7 @@ } recordPoint2.y = recordPoint1.y - 2000 * directionLong; - recordPoint3.y = recordPoint1.y - 100 * directionShort; + recordPoint3.y = recordPoint1.y - 0 * directionShort; recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); @@ -940,17 +947,6 @@ lastLongImageDown++; } - - if ( - strategyNumber !== undefined - ) { - - /* Next we are drawing the LONG stick */ - - drawStick(recordPoint2); - - } - if ( record.type !== '' ) { @@ -990,10 +986,10 @@ let line1; let line2; - longPinHead(); + drawStrategy(); shortPinHead(); - function longPinHead() { + function drawStrategy() { if (strategyNumber < 15 && strategyNumber > 0) { strategy.image = strategyImages[strategyNumber - 1]; @@ -1028,6 +1024,12 @@ if (imageToDraw !== undefined) { + if (strategyNumber !== undefined) { + + drawStick(recordPoint2); + + } + if (imageToDraw.isLoaded === true) { browserCanvasContext.drawImage(imageToDraw, recordPoint2.x - imageSize / 2, recordPoint2.y - imageSize / 2, imageSize, imageSize); imageToDraw = undefined; @@ -1042,29 +1044,6 @@ entryPoint: undefined } } - - if ( - recordPoint2.x < viewPort.visibleArea.topLeft.x + 250 - || - recordPoint2.x > viewPort.visibleArea.bottomRight.x - 250 - || - recordPoint2.y > viewPort.visibleArea.bottomRight.y - 100 - || - recordPoint2.y < viewPort.visibleArea.topLeft.y + 100 - ) { - // we do not write any text - } else { - if (line1 !== undefined) { - - if ( - (directionLong > 0 && noLongTextUp === false) || - (directionLong < 0 && noLongTextDown === false) - ) { - printLabel(line1, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 0, '0.50'); - printLabel(line2, recordPoint2.x + imageSize / 2 + 5, recordPoint2.y + 15, '0.50'); - } - } - } } function shortPinHead() { @@ -1073,11 +1052,11 @@ if (record.type === 'Buy@StopLoss') { - line1 = 'Stopped'; + line1 = 'Stop'; } else { - line1 = 'Profit Taken'; + line1 = 'PT'; } if (record.lastProfit < 0) { @@ -1091,43 +1070,45 @@ imageToDraw = smileyHappy; } + if (trade.entryPoint !== undefined) { + /* Draw the triangle that represents the trade. */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(trade.entryPoint.x, trade.entryPoint.y); + browserCanvasContext.lineTo(recordPoint3.x, recordPoint3.y); + browserCanvasContext.lineTo(recordPoint3.x, trade.entryPoint.y); + + browserCanvasContext.closePath(); + + let opacity = '0.25'; + + if (recordPoint3.y > trade.entryPoint.y) { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')'; + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; + } + + browserCanvasContext.fill(); + + browserCanvasContext.lineWidth = 1; + browserCanvasContext.stroke(); + } + } + if (record.type === 'Sell') { - line1 = 'Entering'; + line1 = ''; line2 = ''; - imageToDraw = smileyMonkeyEyes; - } + imageToDraw = smileyHappy; - if (imageToDraw !== undefined) { - - if (imageToDraw.isLoaded === true) { - browserCanvasContext.drawImage(imageToDraw, recordPoint3.x - imageSize / 2, recordPoint3.y - imageSize / 2, imageSize, imageSize); - imageToDraw = undefined; - } - } - - if ( - recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 - || - recordPoint3.x > viewPort.visibleArea.bottomRight.x - 250 - || - recordPoint3.y > viewPort.visibleArea.bottomRight.y - 100 - || - recordPoint3.y < viewPort.visibleArea.topLeft.y + 100 - ) { - // we do not write any text - } else { - if (line1 !== undefined) { - if ( - (directionShort > 0 && noShortTextUp === false) || - (directionShort < 0 && noShortTextDown === false) - ) { - printLabel(line1, recordPoint3.x + imageSize / 2 + 5, recordPoint3.y + 0, '0.50'); - printLabel(line2, recordPoint3.x + imageSize / 2 + 5, recordPoint3.y + 15, '0.50'); - } - } + trade.begin = record.begin; + trade.end = record.end; + trade.entryPoint = recordPoint3; } } @@ -1237,6 +1218,8 @@ + + From b51ab08e1203af9963a71ed79f623479b59616c9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 22 Apr 2019 19:38:13 +0200 Subject: [PATCH 041/157] Printing the text of profit or losses --- TradingSimulation.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 0f1ece60c..74782dbc7 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -711,7 +711,7 @@ }; let recordPoint3 = { // Short Stick Head - x: record.begin + (record.end - record.begin) / 2, + x: record.end, y: 0 }; @@ -1097,6 +1097,28 @@ browserCanvasContext.stroke(); } + if ( + recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 + || + recordPoint3.x > viewPort.visibleArea.bottomRight.x - 250 + || + recordPoint3.y > viewPort.visibleArea.bottomRight.y - 100 + || + recordPoint3.y < viewPort.visibleArea.topLeft.y + 100 + ) { + // we do not write any text + } else { + if (line1 !== undefined && trade.entryPoint !== undefined) { + if ( + (directionShort > 0 && noShortTextUp === false) || + (directionShort < 0 && noShortTextDown === false) + ) { + printLabel(line1, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint3.y - 230, '0.50'); + printLabel(line2, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint3.y - 215, '0.50'); + } + } + } + } if (record.type === 'Sell') { @@ -1221,5 +1243,6 @@ + From 23320ed2ad5c9da117cde11192c800e22b3a264b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 23 Apr 2019 19:11:32 +0200 Subject: [PATCH 042/157] Cleaning + thiner lines --- TradingSimulation.js | 139 +++++++++++-------------------------------- 1 file changed, 36 insertions(+), 103 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 74782dbc7..41c7ca61c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -155,7 +155,7 @@ smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); - imageStopLossPhase = loadEmoji("Nature/Emoji Natur-71.png"); + imageStopLossPhase = loadEmoji("stop.png"); imageBuyOrderPhase = loadEmoji("Nature/Emoji Natur-67.png"); for (let i = 1; i < 15; i++) { @@ -634,10 +634,6 @@ let directionLong; let record; - let lastShortImageUp = 0; - let lastShortImageDown = 0; - let lastLongImageUp = 0; - let lastLongImageDown = 0; let strategy = { begin: undefined, @@ -829,30 +825,30 @@ /* Next we are drawing the stopLoss floor / ceilling */ - for (j = 0; j < 8; j++) { - browserCanvasContext.beginPath(); + + browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y - j); - browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y - j); + browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y); + browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y); - browserCanvasContext.closePath(); + browserCanvasContext.closePath(); - let opacity = 0.8 - j / 10 + let opacity = 0.8 - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ''; + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ''; - if (userPositionDate >= record.begin && userPositionDate <= record.end) { - - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } - - browserCanvasContext.lineWidth = 1 - browserCanvasContext.stroke() + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } + + browserCanvasContext.lineWidth = 5 + browserCanvasContext.stroke() + + if (imageStopLossPhase.isLoaded === true && stopLossPhase > 0) { browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize * 1.25, imageSize, imageSize); printLabel(stopLossPhase, recordPoint5.x - imageSize / 2, recordPoint5.y - imageSize * 1.5, '0.50'); @@ -860,93 +856,32 @@ /* Next we are drawing the Buy Order */ - for (j = 0; j < 8; j++) { - browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint8.x, recordPoint8.y + j); - browserCanvasContext.lineTo(recordPoint9.x, recordPoint9.y + j); + browserCanvasContext.beginPath(); - browserCanvasContext.closePath(); + browserCanvasContext.moveTo(recordPoint8.x, recordPoint8.y); + browserCanvasContext.lineTo(recordPoint9.x, recordPoint9.y); - let opacity = 0.6 - j / 10 + browserCanvasContext.closePath(); - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ''; + opacity = 0.6 - if (userPositionDate >= record.begin && userPositionDate <= record.end) { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ''; - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + if (userPositionDate >= record.begin && userPositionDate <= record.end) { - browserCanvasContext.lineWidth = 1 - browserCanvasContext.stroke() + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } + + browserCanvasContext.lineWidth = 5 + browserCanvasContext.stroke() + if (imageBuyOrderPhase.isLoaded === true && buyOrderPhase > 0) { browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4, imageSize, imageSize); printLabel(buyOrderPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.50'); } - /* Continue with the pins --> Next stuff is to avoid text overlapping. */ - - let noShortTextUp = false; - let noShortTextDown = false; - - if ( - record.type !== '' - ) { - - if (directionShort > 0) { - if (lastShortImageUp < 5) { - noShortTextUp = true; // we avoid image texts to overlap. - } else { - noShortTextUp = false; - lastShortImageUp = 0; - } - } else { - if (lastShortImageDown < 5) { - noShortTextDown = true; // we avoid image texts to overlap. - } else { - noShortTextDown = false; - lastShortImageDown = 0; - } - } - - } else { - - lastShortImageUp++; - lastShortImageDown++; - } - - let noLongTextUp = false; - let noLongTextDown = false; - - if ( - strategyNumber > 0 || - strategyPhase > 0 - ) { - - if (directionLong > 0) { - if (lastLongImageUp < 5) { - noLongTextUp = true; // we avoid image texts to overlap. - } else { - noLongTextUp = false; - lastLongImageUp = 0; - } - } else { - if (lastLongImageDown < 3) { - noLongTextDown = true; // we avoid image texts to overlap. - } else { - noLongTextDown = false; - lastLongImageDown = 0; - } - } - - } else { - - lastLongImageUp++; - lastLongImageDown++; - } - if ( record.type !== '' ) { @@ -987,7 +922,7 @@ let line2; drawStrategy(); - shortPinHead(); + drawTrade(); function drawStrategy() { @@ -1046,7 +981,7 @@ } } - function shortPinHead() { + function drawTrade() { if (record.type === 'Buy@StopLoss' || record.type === 'Buy@BuyOrder') { @@ -1109,13 +1044,10 @@ // we do not write any text } else { if (line1 !== undefined && trade.entryPoint !== undefined) { - if ( - (directionShort > 0 && noShortTextUp === false) || - (directionShort < 0 && noShortTextDown === false) - ) { - printLabel(line1, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint3.y - 230, '0.50'); - printLabel(line2, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint3.y - 215, '0.50'); - } + + printLabel(line1, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint4.y - 30, '0.50'); + printLabel(line2, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint4.y - 15, '0.50'); + } } @@ -1244,5 +1176,6 @@ + From 46c733b872c5357e78827c1a6d2b49f3fd81e2a7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 23 Apr 2019 19:19:58 +0200 Subject: [PATCH 043/157] Text improvements --- TradingSimulation.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 41c7ca61c..a3ea914e9 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -851,7 +851,7 @@ if (imageStopLossPhase.isLoaded === true && stopLossPhase > 0) { browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize * 1.25, imageSize, imageSize); - printLabel(stopLossPhase, recordPoint5.x - imageSize / 2, recordPoint5.y - imageSize * 1.5, '0.50'); + printLabel(stopLossPhase, recordPoint5.x - imageSize / 2, recordPoint5.y - imageSize * 1.5, '0.9', 8); } /* Next we are drawing the Buy Order */ @@ -879,7 +879,7 @@ if (imageBuyOrderPhase.isLoaded === true && buyOrderPhase > 0) { browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4, imageSize, imageSize); - printLabel(buyOrderPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.50'); + printLabel(buyOrderPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.9', 8); } if ( @@ -1044,10 +1044,10 @@ // we do not write any text } else { if (line1 !== undefined && trade.entryPoint !== undefined) { - - printLabel(line1, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint4.y - 30, '0.50'); - printLabel(line2, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint4.y - 15, '0.50'); - + + printLabel(line1, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint4.y - 30, '0.50', 12); + printLabel(line2, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint4.y - 15, '0.50', 12); + } } @@ -1081,10 +1081,9 @@ /* This is how we write the text */ - function printLabel(labelToPrint, x, y, opacity) { + function printLabel(labelToPrint, x, y, opacity, fontSize) { let labelPoint; - let fontSize = 12; browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; From 78146c6ca4b98924950addf8ba7bc3aae40551c6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 23 Apr 2019 21:44:14 +0200 Subject: [PATCH 044/157] Label Sizes --- TradingSimulation.js | 17 +++++++-------- TradingSimulationPanel.js | 44 +++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index a3ea914e9..c612d8c00 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -987,11 +987,11 @@ if (record.type === 'Buy@StopLoss') { - line1 = 'Stop'; + line1 = 'STOP'; } else { - line1 = 'PT'; + line1 = 'TP'; } if (record.lastProfit < 0) { @@ -1068,15 +1068,12 @@ /* Send the current record to the panel */ - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + if (userPositionDate >= record.begin && userPositionDate <= record.end) { - let currentRecord = { - innerRecord: record - }; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); - } + let currentRecord = { + innerRecord: record + }; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); } /* This is how we write the text */ diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 52f9ea907..307922662 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -97,87 +97,87 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel('Balance A', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.balanceA, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.balanceA, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Balance B', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.balanceB, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.balanceB, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Last Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.lastProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.lastProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Last Profit %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; - printLabel('Sell Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; - printLabel('Stop Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; - printLabel('Buy Order', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.buyOrder, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.buyOrder, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; - printLabel('Roundtrips', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); y = y + increment; printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50'); + printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); - function printLabel(labelToPrint, x, y, opacity) { + function printLabel(labelToPrint, x, y, opacity, fontSize) { let labelPoint; - let fontSize = 10; + if (fontSize === undefined) { fontSize = 10 }; browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; From 21bc8d7e6bc2b5df433f98647b172e70a3eb2aec Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 24 Apr 2019 20:38:00 +0200 Subject: [PATCH 045/157] EventHandling Improved --- SimulationExecution.js | 19 +++++++++++++++---- TradingSimulation.js | 26 ++++++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/SimulationExecution.js b/SimulationExecution.js index cc06fb980..8b820610d 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -54,6 +54,10 @@ let previousNotesSetKey; let currentNotesSetKey; + let offsetChangedEventSubscriptionId + let filesUpdatedEventSubscriptionId + let dimmensionsChangedEventSubscriptionId + return thisObject; function finalize() { @@ -63,8 +67,9 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); - fileSequence.eventHandler.stopListening("Files Updated", onFilesUpdated); + viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + fileSequence.eventHandler.stopListening(filesUpdatedEventSubscriptionId); + thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) /* Destroyd References */ @@ -96,9 +101,15 @@ recalculate(callBackFunction); recalculateScale(callBackFunction); - fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. - viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + filesUpdatedEventSubscriptionId = fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + /* Ready for when dimmension changes. */ + + dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + recalculate(callBackFunction); + recalculateScale(callBackFunction); + }) callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); } catch (err) { diff --git a/TradingSimulation.js b/TradingSimulation.js index c612d8c00..8b307f952 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -60,6 +60,12 @@ let imageStopLossPhase; let imageBuyOrderPhase; + let zoomChangedEventSubscriptionId + let offsetChangedEventSubscriptionId + let filesUpdatedEventSubscriptionId + let dragFinishedEventSubscriptionId + let dimmensionsChangedEventSubscriptionId + return thisObject; function finalize() { @@ -69,11 +75,11 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening("Zoom Changed", onZoomChanged); - viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); - canvas.eventHandler.stopListening("Drag Finished", onDragFinished); - thisObject.container.eventHandler.stopListening('Dimmensions Changed') + viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); + viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + marketFiles.eventHandler.stopListening(filesUpdatedEventSubscriptionId); + canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); + thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) /* icons */ @@ -131,10 +137,10 @@ /* Listen to the necesary events. */ - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + filesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); + dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); /* Get ready for plotting. */ @@ -142,7 +148,7 @@ /* Ready for when dimmension changes. */ - thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { recalculateScale() recalculate(); }) From aeae50c6e419fd05f1e20a4734bbebfdb8b17b1b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 28 Apr 2019 08:16:59 +0200 Subject: [PATCH 046/157] Removing INFO LOG and fixing BUG when scaling --- SimulationExecution.js | 49 ------------------------------------------ TradingSimulation.js | 47 +--------------------------------------- 2 files changed, 1 insertion(+), 95 deletions(-) diff --git a/SimulationExecution.js b/SimulationExecution.js index 8b820610d..f3cc3eb37 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -1,7 +1,6 @@ function newAAMastersPlottersTradingSimulationSimulationExecution() { const MODULE_NAME = "Simulation Execution Plotter"; - const INFO_LOG = false; const INTENSIVE_LOG = false; const ERROR_LOG = true; const logger = newWebDebugLog(); @@ -63,8 +62,6 @@ function finalize() { try { - if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } - /* Stop listening to the necesary events. */ viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); @@ -91,8 +88,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - datetime = pDatetime; timePeriod = pTimePeriod; @@ -123,8 +118,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } - let container; /* First we check if this point is inside this space. */ @@ -156,8 +149,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - timePeriod = pTimePeriod; recalculate(); @@ -172,8 +163,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } - datetime = newDatetime; } catch (err) { @@ -195,8 +184,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } - if (fileSequence === undefined) { return; } /* @@ -444,8 +431,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); } - if (fileSequence === undefined) { return; } // We need the market file to be loaded to make the calculation. if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. @@ -460,7 +445,6 @@ y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary }; - timeLineCoordinateSystem.initialize( minValue, maxValue, @@ -468,39 +452,6 @@ thisObject.container.frame.height ); - function getMaxRate() { - - try { - - if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> getMaxRate > Entering function."); } - - let maxValue = 0; - - let maxSequence = fileSequence.getFilesLoaded(); - - for (let j = 0; j < maxSequence; j++) { - - let file = fileSequence.getFile(j); - - for (let i = 0; i < file.length; i++) { - - let currentMax = file[i][1] + file[i][2]; // 1 = rates. - - if (maxValue < currentMax) { - maxValue = currentMax; - } - } - } - - return maxValue; - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> getMaxRate -> err = " + err); } - callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); - } - } - } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err); } diff --git a/TradingSimulation.js b/TradingSimulation.js index 8b307f952..989a6fd12 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -1,7 +1,6 @@ function newAAMastersPlottersTradingSimulationTradingSimulation() { const MODULE_NAME = "Simulation Plotter"; - const INFO_LOG = false; const ERROR_LOG = true; const INTENSIVE_LOG = false; const logger = newWebDebugLog(); @@ -71,8 +70,6 @@ function finalize() { try { - if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } - /* Stop listening to the necesary events. */ viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); @@ -114,8 +111,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - /* Store the information received. */ marketFiles = pStorage.marketFiles[0]; @@ -197,8 +192,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } - let container; /* First we check if this point is inside this space. */ @@ -224,8 +217,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } - let newMarketFile = marketFiles.getFile(timePeriod); if (newMarketFile !== undefined) { @@ -244,8 +235,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod !== pTimePeriod) { timePeriod = pTimePeriod; @@ -278,8 +267,6 @@ function setDatetime(pDatetime) { - if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } - datetime = pDatetime; } @@ -288,8 +275,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] onDailyFileLoaded -> Entering function."); } - if (event.currentValue === event.totalValue) { /* This happens only when all of the files in the cursor have been loaded. */ @@ -324,8 +309,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { recalculateUsingMarketFiles(); @@ -348,8 +331,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } - if (fileCursor === undefined) { records = []; return; @@ -483,8 +464,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingMarketFiles -> Entering function."); } - if (marketFile === undefined) { return; } // Initialization not complete yet. let daysOnSides = getSideDays(timePeriod); @@ -580,10 +559,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); } - - if (marketFile === undefined) { return; } // We need the market file to be loaded to make the calculation. - if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { @@ -593,10 +568,9 @@ let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(getMaxRate()) / 4 // TODO: This 4 is temporary + y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary }; - timeLineCoordinateSystem.initialize( minValue, maxValue, @@ -604,25 +578,6 @@ thisObject.container.frame.height ); - function getMaxRate() { - - if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> getMaxRate -> Entering function."); } - - let maxValue = 0; - - for (let i = 0; i < marketFile.length; i++) { - - let currentMax = 25000; // TODO Fix this, since when there are not records above 10k the scales is dissincronized with the scale of the candles. marketFile[i][3]; // 3 = rate. - - if (maxValue < currentMax) { - maxValue = currentMax; - } - } - - return maxValue; - - } - } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } From 7d958fb7070f9c5c669bfea03a38c2dfb41c771b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 29 Apr 2019 16:30:46 +0200 Subject: [PATCH 047/157] All new modues working and cleaned --- Conditions.js | 21 +- Project.njsproj | 6 + Strategies.js | 675 +++++++++++++++++++++++++++++++++++++++ Trades.js | 671 ++++++++++++++++++++++++++++++++++++++ TradingSimulation.js | 328 +------------------ this.plotter.config.json | 16 + 6 files changed, 1371 insertions(+), 346 deletions(-) create mode 100644 Strategies.js create mode 100644 Trades.js diff --git a/Conditions.js b/Conditions.js index 7aad536a4..232ef1059 100644 --- a/Conditions.js +++ b/Conditions.js @@ -460,7 +460,7 @@ let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(getMaxRate()) / 4 // TODO: This 4 is temporary + y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary }; @@ -471,25 +471,6 @@ thisObject.container.frame.height ); - function getMaxRate() { - - if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> getMaxRate -> Entering function."); } - - let maxValue = 0; - - for (let i = 0; i < marketFile.length; i++) { - - let currentMax = 25000; // TODO Fix this, since when there are not records above 10k the scales is dissincronized with the scale of the candles. marketFile[i][3]; // 3 = rate. - - if (maxValue < currentMax) { - maxValue = currentMax; - } - } - - return maxValue; - - } - } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } diff --git a/Project.njsproj b/Project.njsproj index f3ac2708b..13475abfd 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -26,6 +26,12 @@ Code + + Code + + + Code + diff --git a/Strategies.js b/Strategies.js new file mode 100644 index 000000000..8e2e663f9 --- /dev/null +++ b/Strategies.js @@ -0,0 +1,675 @@ +function newAAMastersPlottersTradingSimulationStrategies() { + + const MODULE_NAME = "Strategies Plotter"; + const INFO_LOG = false; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; + + let thisObject = { + + // Main functions and properties. + + initialize: initialize, + finalize: finalize, + container: undefined, + getContainer: getContainer, + setTimePeriod: setTimePeriod, + setDatetime: setDatetime, + draw: draw, + recalculateScale: recalculateScale, + + /* Events declared outside the plotter. */ + + onDailyFileLoaded: onDailyFileLoaded, + + // Secondary functions and properties. + + currentRecord: undefined + }; + + /* this is part of the module template */ + + let container = newContainer(); // Do not touch this 3 lines, they are just needed. + container.initialize(); + thisObject.container = container; + + let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + + let timePeriod; // This will hold the current Time Period the user is at. + let datetime; // This will hold the current Datetime the user is at. + + let marketFile; // This is the current Market File being plotted. + let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. + + let marketFiles; // This object will provide the different Market Files at different Time Periods. + let dailyFiles; // This object will provide the different File Cursors at different Time Periods. + + /* these are module specific variables: */ + + let strategies = []; + + let strategyImages = []; + + return thisObject; + + function finalize() { + try { + + if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } + + /* Stop listening to the necesary events. */ + + viewPort.eventHandler.stopListening("Zoom Changed", onZoomChanged); + viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); + canvas.eventHandler.stopListening("Drag Finished", onDragFinished); + thisObject.container.eventHandler.stopListening('Dimmensions Changed') + + /* Destroyd References */ + + marketFiles = undefined; + dailyFiles = undefined; + + datetime = undefined; + timePeriod = undefined; + + marketFile = undefined; + fileCursor = undefined; + + strategyImages = undefined; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } + } + } + + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + + /* Store the information received. */ + + marketFiles = pStorage.marketFiles[0]; + dailyFiles = pStorage.dailyFiles[0]; + + datetime = pDatetime; + timePeriod = pTimePeriod; + + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ + + marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. + + recalculateScale(); + + /* Now we set the right files according to current Period. */ + + marketFile = marketFiles.getFile(pTimePeriod); + fileCursor = dailyFiles.getFileCursor(pTimePeriod); + + /* Listen to the necesary events. */ + + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + + /* Get ready for plotting. */ + + recalculate(); + + /* Ready for when dimmension changes. */ + + thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + recalculateScale() + recalculate(); + }) + + for (let i = 1; i < 15; i++) { + let strategyImage = loadEmoji("Symbols/Emoji Symbols-" + (112 + i) + ".png"); + strategyImages.push(strategyImage); + } + + callBackFunction(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err.stack); } + } + } + + function getContainer(point) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } + + let container; + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err = " + err.stack); } + } + } + + function onFilesUpdated() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } + + let newMarketFile = marketFiles.getFile(timePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } + } + } + + function setTimePeriod(pTimePeriod) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } + + if (timePeriod !== pTimePeriod) { + + timePeriod = pTimePeriod; + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + let newMarketFile = marketFiles.getFile(pTimePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } else { + + let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + + fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. + recalculate(); + + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } + } + } + + function setDatetime(pDatetime) { + + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } + + datetime = pDatetime; + + } + + function onDailyFileLoaded(event) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onDailyFileLoaded -> Entering function."); } + + if (event.currentValue === event.totalValue) { + + /* This happens only when all of the files in the cursor have been loaded. */ + + recalculate(); + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err = " + err.stack); } + } + } + + function draw() { + + try { + + if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); } + + this.container.frame.draw(); + + plotChart(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err.stack); } + } + } + + function recalculate() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + recalculateUsingMarketFiles(); + + } else { + + recalculateUsingDailyFiles(); + + } + + thisObject.container.eventHandler.raiseEvent("Strategies Changed", strategies); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } + } + } + + function recalculateUsingDailyFiles() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } + + if (fileCursor === undefined) { + strategies = []; + return; + } // We need to wait + + if (fileCursor.files.size === 0) { + strategies = []; + return; + } // We need to wait until there are files in the cursor + + let daysOnSides = getSideDays(timePeriod); + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + + let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + + let currentDate = new Date(farLeftDate.valueOf()); + + strategies = []; + + + + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { + + let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); + + let dailyFile = fileCursor.files.get(stringDate); + + if (dailyFile !== undefined) { + + for (let i = 0; i < dailyFile.length; i++) { + + let record = { + begin: undefined, + end: undefined, + status: undefined, + number: undefined, + beginRate: undefined, + endRate: undefined + }; + + record.begin = dailyFile[i][0]; + record.end = dailyFile[i][1]; + record.status = dailyFile[i][2]; + record.number = dailyFile[i][3]; + record.beginRate = dailyFile[i][4]; + record.endRate = dailyFile[i][5]; + + if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + + strategies.push(record); + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Strategy Changed", thisObject.currentRecord); + + } + } + } + } + + currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS); + } + + /* Lests check if all the visible screen is going to be covered by strategies. */ + + let lowerEnd = leftDate.valueOf(); + let upperEnd = rightDate.valueOf(); + + if (strategies.length > 0) { + + if (strategies[0].begin > lowerEnd || strategies[strategies.length - 1].end < upperEnd) { + + setTimeout(recalculate, 2000); + + //console.log("File missing while calculating strategies, scheduling a recalculation in 2 seconds."); + + } + } + + //console.log("Olivia > recalculateUsingDailyFiles > total strategies generated : " + strategies.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err = " + err.stack); } + } + } + + function recalculateUsingMarketFiles() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingMarketFiles -> Entering function."); } + + if (marketFile === undefined) { return; } // Initialization not complete yet. + + let daysOnSides = getSideDays(timePeriod); + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + + leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + + strategies = []; + + for (let i = 0; i < marketFile.length; i++) { + + let record = { + begin: undefined, + end: undefined, + status: undefined, + number: undefined, + beginRate: undefined, + endRate: undefined + }; + + record.begin = marketFile[i][0]; + record.end = marketFile[i][1]; + record.status = marketFile[i][2]; + record.number = marketFile[i][3]; + record.beginRate = marketFile[i][4]; + record.endRate = marketFile[i][5]; + + if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { + + strategies.push(record); + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Strategy Changed", thisObject.currentRecord); + + } + } + } + + //console.log("Olivia > recalculateUsingMarketFiles > total strategies generated : " + strategies.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err = " + err.stack); } + } + } + + function recalculateScale() { + + try { + + if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + + let minValue = { + x: MIN_PLOTABLE_DATE.valueOf(), + y: 0 + }; + + let maxValue = { + x: MAX_PLOTABLE_DATE.valueOf(), + y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + }; + + + timeLineCoordinateSystem.initialize( + minValue, + maxValue, + thisObject.container.frame.width, + thisObject.container.frame.height + ); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } + } + } + + function plotChart() { + + try { + + let userPosition = getUserPosition() + let userPositionDate = userPosition.point.x + + thisObject.container.eventHandler.raiseEvent("Current Strategy Record Changed", undefined); + + let record; + + for (let i = 0; i < strategies.length; i++) { + + record = strategies[i]; + + let recordPoint1 = { + x: record.begin, + y: record.beginRate + }; + + let recordPoint2 = { + x: record.end, + y: record.endRate + }; + + let recordPoint3 = { + x: record.begin, + y: record.beginRate + }; + + let recordPoint4 = { + x: record.end, + y: record.endRate + }; + + recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); + recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); + recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); + recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); + + recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); + recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); + recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); + recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); + + if (recordPoint2.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { + continue; + } + + recordPoint3.y = recordPoint1.y + 2000; + recordPoint4.y = recordPoint1.y + 2000; + + recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); + recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); + recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); + recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); + + let imageSize = 20; + let imageToDraw = strategyImages[record.number]; + + if (record.status === 1) { + /* Draw the line that represents the duration of closed strategy */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint3.x + imageSize / 2, recordPoint3.y); + browserCanvasContext.lineTo(recordPoint4.x - imageSize / 2, recordPoint4.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; + browserCanvasContext.lineWidth = 1 + + browserCanvasContext.stroke() + } + + + drawStick(recordPoint1, recordPoint3); + drawStick(recordPoint2, recordPoint4); + + if (imageToDraw.isLoaded === true) { + browserCanvasContext.drawImage(imageToDraw, recordPoint3.x - imageSize / 2, recordPoint3.y - imageSize / 2, imageSize, imageSize); + if (record.status === 1) { + browserCanvasContext.drawImage(imageToDraw, recordPoint4.x - imageSize / 2, recordPoint4.y - imageSize / 2, imageSize, imageSize); + } + } + + /* Send the current record to the panel */ + + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + + let currentRecord = { + }; + thisObject.container.eventHandler.raiseEvent("Current Strategy Record Changed", currentRecord); + } + + function drawStick(point1, point2) { + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.25)'; + + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time + } + + browserCanvasContext.setLineDash([4, 3]) + browserCanvasContext.lineWidth = 0.2 + browserCanvasContext.stroke() + browserCanvasContext.setLineDash([0, 0]) + + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } + } + } + + + function onZoomChanged(event) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } + } + } + + function onOffsetChanged() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + + if (Math.random() * 100 > 95) { + + recalculate() + }; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } + } + } + + function onDragFinished() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onDragFinished -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err = " + err.stack); } + } + } +} + + + + + + + + + + + + + + + + + + + diff --git a/Trades.js b/Trades.js new file mode 100644 index 000000000..fc51c9229 --- /dev/null +++ b/Trades.js @@ -0,0 +1,671 @@ +function newAAMastersPlottersTradingSimulationTrades() { + + const MODULE_NAME = "Trades Plotter"; + const INFO_LOG = false; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; + + let thisObject = { + + // Main functions and properties. + + initialize: initialize, + finalize: finalize, + container: undefined, + getContainer: getContainer, + setTimePeriod: setTimePeriod, + setDatetime: setDatetime, + draw: draw, + recalculateScale: recalculateScale, + + /* Events declared outside the plotter. */ + + onDailyFileLoaded: onDailyFileLoaded, + + // Secondary functions and properties. + + currentRecord: undefined + }; + + /* this is part of the module template */ + + let container = newContainer(); // Do not touch this 3 lines, they are just needed. + container.initialize(); + thisObject.container = container; + + let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + + let timePeriod; // This will hold the current Time Period the user is at. + let datetime; // This will hold the current Datetime the user is at. + + let marketFile; // This is the current Market File being plotted. + let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. + + let marketFiles; // This object will provide the different Market Files at different Time Periods. + let dailyFiles; // This object will provide the different File Cursors at different Time Periods. + + /* these are module specific variables: */ + + let trades = []; + let headers; + + return thisObject; + + function finalize() { + try { + + if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } + + /* Stop listening to the necesary events. */ + + viewPort.eventHandler.stopListening("Zoom Changed", onZoomChanged); + viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); + canvas.eventHandler.stopListening("Drag Finished", onDragFinished); + thisObject.container.eventHandler.stopListening('Dimmensions Changed') + + /* Destroyd References */ + + marketFiles = undefined; + dailyFiles = undefined; + + datetime = undefined; + timePeriod = undefined; + + marketFile = undefined; + fileCursor = undefined; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } + } + } + + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + + /* Store the information received. */ + + marketFiles = pStorage.marketFiles[0]; + dailyFiles = pStorage.dailyFiles[0]; + + datetime = pDatetime; + timePeriod = pTimePeriod; + + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ + + marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. + + recalculateScale(); + + /* Now we set the right files according to current Period. */ + + marketFile = marketFiles.getFile(pTimePeriod); + fileCursor = dailyFiles.getFileCursor(pTimePeriod); + + /* Listen to the necesary events. */ + + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + + /* Get ready for plotting. */ + + recalculate(); + + /* Ready for when dimmension changes. */ + + thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + recalculateScale() + recalculate(); + }) + + callBackFunction(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err.stack); } + } + } + + function getContainer(point) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } + + let container; + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err = " + err.stack); } + } + } + + function onFilesUpdated() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } + + let newMarketFile = marketFiles.getFile(timePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } + } + } + + function setTimePeriod(pTimePeriod) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } + + if (timePeriod !== pTimePeriod) { + + timePeriod = pTimePeriod; + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + let newMarketFile = marketFiles.getFile(pTimePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } else { + + let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + + fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. + recalculate(); + + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } + } + } + + function setDatetime(pDatetime) { + + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } + + datetime = pDatetime; + + } + + function onDailyFileLoaded(event) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onDailyFileLoaded -> Entering function."); } + + if (event.currentValue === event.totalValue) { + + /* This happens only when all of the files in the cursor have been loaded. */ + + recalculate(); + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err = " + err.stack); } + } + } + + function draw() { + + try { + + if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); } + + this.container.frame.draw(); + + plotChart(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err.stack); } + } + } + + function recalculate() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + recalculateUsingMarketFiles(); + + } else { + + recalculateUsingDailyFiles(); + + } + + thisObject.container.eventHandler.raiseEvent("Trades Changed", trades); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } + } + } + + function recalculateUsingDailyFiles() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } + + if (fileCursor === undefined) { + trades = []; + return; + } // We need to wait + + if (fileCursor.files.size === 0) { + trades = []; + return; + } // We need to wait until there are files in the cursor + + let daysOnSides = getSideDays(timePeriod); + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + + let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + + let currentDate = new Date(farLeftDate.valueOf()); + + trades = []; + + + + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { + + let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); + + let dailyFile = fileCursor.files.get(stringDate); + + if (dailyFile !== undefined) { + + for (let i = 0; i < dailyFile.length; i++) { + + let record = {}; + + record.begin = dailyFile[i][0]; + record.end = dailyFile[i][1]; + record.status = dailyFile[i][2]; + record.lastProfitPercent = dailyFile[i][3]; + record.beginRate = dailyFile[i][4]; + record.endRate = dailyFile[i][5]; + record.exitType = dailyFile[i][6]; + record.stopRate = dailyFile[i][7]; + + if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + + trades.push(record); + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Trade Changed", thisObject.currentRecord); + + } + } + } + } + + currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS); + } + + /* Lests check if all the visible screen is going to be covered by trades. */ + + let lowerEnd = leftDate.valueOf(); + let upperEnd = rightDate.valueOf(); + + if (trades.length > 0) { + + if (trades[0].begin > lowerEnd || trades[trades.length - 1].end < upperEnd) { + + setTimeout(recalculate, 2000); + + //console.log("File missing while calculating trades, scheduling a recalculation in 2 seconds."); + + } + } + + //console.log("Olivia > recalculateUsingDailyFiles > total trades generated : " + trades.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err = " + err.stack); } + } + } + + function recalculateUsingMarketFiles() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingMarketFiles -> Entering function."); } + + if (marketFile === undefined) { return; } // Initialization not complete yet. + + let daysOnSides = getSideDays(timePeriod); + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + + leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + + trades = []; + + for (let i = 0; i < marketFile.length; i++) { + + let record = {}; + + record.begin = marketFile[i][0]; + record.end = marketFile[i][1]; + record.status = marketFile[i][2]; + record.lastProfitPercent = marketFile[i][3]; + record.beginRate = marketFile[i][4]; + record.endRate = marketFile[i][5]; + record.exitType = marketFile[i][6]; + record.stopRate = marketFile[i][7]; + + if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { + + trades.push(record); + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Trade Changed", thisObject.currentRecord); + + } + } + } + + //console.log("Olivia > recalculateUsingMarketFiles > total trades generated : " + trades.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err = " + err.stack); } + } + } + + function recalculateScale() { + + try { + + if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + + let minValue = { + x: MIN_PLOTABLE_DATE.valueOf(), + y: 0 + }; + + let maxValue = { + x: MAX_PLOTABLE_DATE.valueOf(), + y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + }; + + + timeLineCoordinateSystem.initialize( + minValue, + maxValue, + thisObject.container.frame.width, + thisObject.container.frame.height + ); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } + } + } + + function plotChart() { + + try { + + let userPosition = getUserPosition() + let userPositionDate = userPosition.point.x + + thisObject.container.eventHandler.raiseEvent("Current Trade Record Changed", undefined); + + let record; + + for (let i = 0; i < trades.length; i++) { + + record = trades[i]; + + /* Send the current record to the panel */ + + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + + let currentRecord = { + }; + thisObject.container.eventHandler.raiseEvent("Current Trade Record Changed", currentRecord); + } + + let recordPoint1 = { + x: record.begin, + y: record.beginRate + }; + + let recordPoint2 = { + x: record.end, + y: record.beginRate + }; + + let recordPoint3 = { + x: record.end, + y: record.endRate + }; + + let recordPoint4 = { + x: record.end, + y: record.stopRate + }; + + recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); + recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); + recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); + recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); + + recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); + recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); + recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); + recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); + + if (recordPoint2.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { + continue; + } + + recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); + recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); + recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); + recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); + + let line1 = ''; + let line2 = ''; + + switch (record.exitType) { + case 1: { + line1 = 'STOP'; + break; + } + case 2: { + line1 = 'TP'; + break; + } + } + + if (record.lastProfitPercent < 0) { + + line2 = (record.lastProfitPercent).toFixed(2) + ' %'; + + } else { + + line2 = (record.lastProfitPercent).toFixed(2) + ' %'; + } + + /* Draw the triangle that represents the trade. */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); + browserCanvasContext.lineTo(recordPoint2.x, recordPoint2.y); + browserCanvasContext.lineTo(recordPoint3.x, recordPoint3.y); + + browserCanvasContext.closePath(); + + let opacity = '0.25'; + + if (record.lastProfitPercent > 0) { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')'; + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; + } + + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; + } + + browserCanvasContext.fill(); + + browserCanvasContext.lineWidth = 1; + browserCanvasContext.stroke(); + + if ( + recordPoint4.x < viewPort.visibleArea.topLeft.x + 250 + || + recordPoint4.x > viewPort.visibleArea.bottomRight.x - 250 + || + recordPoint4.y > viewPort.visibleArea.bottomRight.y - 100 + || + recordPoint4.y < viewPort.visibleArea.topLeft.y + 100 + ) { + // we do not write any text + } else { + + + printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint4.y - 30, '0.50', 12); + printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint4.y - 15, '0.50', 12); + + + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } + } + } + + + function onZoomChanged(event) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } + } + } + + function onOffsetChanged() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + + if (Math.random() * 100 > 95) { + + recalculate() + }; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } + } + } + + function onDragFinished() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onDragFinished -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err = " + err.stack); } + } + } +} + + + + + + + + + + + + + + + + + + + diff --git a/TradingSimulation.js b/TradingSimulation.js index 989a6fd12..f6b6c2a61 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -49,13 +49,6 @@ let records = []; // Here we keep the records to be ploted every time the Draw() function is called by the AAWebPlatform. - let smileyHappy; - let smileySad; - let strategyImages = []; - let smileyMonkeyEyes; - let smileyMonkeyEars; - let imageStrategy; - let imageStrategyPhase; let imageStopLossPhase; let imageBuyOrderPhase; @@ -80,13 +73,6 @@ /* icons */ - smileyHappy = undefined; - smileySad = undefined; - strategyImages = undefined; - smileyMonkeyEyes = undefined; - smileyMonkeyEars = undefined; - imageStrategy = undefined; - imageStrategyPhase = undefined; imageStopLossPhase = undefined; imageBuyOrderPhase = undefined; @@ -150,36 +136,9 @@ /* Loading a few icons */ - smileyHappy = loadEmoji("Smiley/Emoji Smiley-51.png"); - smileySad = loadEmoji("Smiley/Emoji Smiley-26.png"); - smileyMonkeyEyes = loadEmoji("Smiley/Emoji Smiley-85.png"); - smileyMonkeyEars = loadEmoji("Smiley/Emoji Smiley-86.png"); - imageStrategy = loadEmoji("Places/Emoji Orte-90.png"); - imageStrategyPhase = loadEmoji("Places/Emoji Orte-91.png"); imageStopLossPhase = loadEmoji("stop.png"); imageBuyOrderPhase = loadEmoji("Nature/Emoji Natur-67.png"); - for (let i = 1; i < 15; i++) { - let strategyImage = loadEmoji("Symbols/Emoji Symbols-" + (112 + i) + ".png"); - strategyImages.push(strategyImage); - } - - function loadEmoji(pPath) { - - let newImage; - - newImage = new Image(); - newImage.onload = onImageLoaded; - - function onImageLoaded() { - newImage.isLoaded = true; - } - - newImage.src = window.canvasApp.urlPrefix + "Images/Emoji/" + pPath; - - return newImage; - } - callBackFunction(); } catch (err) { @@ -591,44 +550,17 @@ let userPosition = getUserPosition() let userPositionDate = userPosition.point.x - let directionShort; - let directionLong; - let record; - let strategy = { - begin: undefined, - end: undefined, - image: undefined, - entryPoint: undefined - } - - let trade = { - begin: undefined, - end: undefined, - image: undefined, - entryPoint: undefined - } - /* Now we calculate and plot the records */ for (let i = 1; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 record = records[i]; - directionShort = 0; - let strategyNumber; - let strategyPhase = 0; + let stopLossPhase = 0; let buyOrderPhase = 0; - if (record.strategy !== records[i - 1].strategy) { // When a change in the strategy field is detected, it is time to plot it. - strategyNumber = record.strategy; - } - - if (record.strategyPhase !== records[i - 1].strategyPhase) { - strategyPhase = record.strategyPhase; - } - if (record.stopLossPhase !== records[i - 1].stopLossPhase) { stopLossPhase = record.stopLossPhase; } @@ -637,41 +569,6 @@ buyOrderPhase = record.buyOrderPhase; } - if (record.type === 'Buy@BuyOrder') { directionShort = +1; } - if (record.type === 'Buy@StopLoss') { directionShort = +1; } - if (record.type === 'Sell') { directionShort = +1; } - - if (strategyPhase > 0) { - if (strategyPhase % 2 !== 0) { //Depending if the phase is oddd or even goes above or below. - directionLong = 1; - } else { - directionLong = -1; - } - } - - if (strategyNumber === 0) { - directionLong = -1; - } - - if (strategyNumber > 0) { - directionLong = -1; - } - - let recordPoint1 = { - x: record.begin + (record.end - record.begin) / 2, - y: record.rate - }; - - let recordPoint2 = { // Long Stick Head - x: record.begin + (record.end - record.begin) / 2, - y: 0 - }; - - let recordPoint3 = { // Short Stick Head - x: record.end, - y: 0 - }; - let recordPoint4 = { x: record.begin, y: record.stopLoss @@ -720,9 +617,6 @@ recordPoint9.x = 0; } - recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); - recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); - recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); recordPoint5 = timeLineCoordinateSystem.transformThisPoint(recordPoint5); recordPoint6 = timeLineCoordinateSystem.transformThisPoint(recordPoint6); @@ -730,9 +624,6 @@ recordPoint8 = timeLineCoordinateSystem.transformThisPoint(recordPoint8); recordPoint9 = timeLineCoordinateSystem.transformThisPoint(recordPoint9); - recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); - recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); - recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); recordPoint5 = transformThisPoint(recordPoint5, thisObject.container); recordPoint6 = transformThisPoint(recordPoint6, thisObject.container); @@ -740,16 +631,10 @@ recordPoint8 = transformThisPoint(recordPoint8, thisObject.container); recordPoint9 = transformThisPoint(recordPoint9, thisObject.container); - if (recordPoint1.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { + if (recordPoint4.x < viewPort.visibleArea.bottomLeft.x || recordPoint4.x > viewPort.visibleArea.bottomRight.x) { continue; } - recordPoint2.y = recordPoint1.y - 2000 * directionLong; - recordPoint3.y = recordPoint1.y - 0 * directionShort; - - recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); - recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); - recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); recordPoint5 = viewPort.fitIntoVisibleArea(recordPoint5); recordPoint6 = viewPort.fitIntoVisibleArea(recordPoint6); @@ -843,190 +728,6 @@ printLabel(buyOrderPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.9', 8); } - if ( - record.type !== '' - ) { - - /* Next we are drawing the SHORT stick */ - - drawStick(recordPoint3); - - } - - function drawStick(headPoint) { - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(recordPoint1.x, recordPoint1.y); - browserCanvasContext.lineTo(headPoint.x, headPoint.y); - - browserCanvasContext.closePath(); - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.25)'; - - if (userPositionDate >= record.begin && userPositionDate <= record.end) { - - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } - - browserCanvasContext.setLineDash([4, 3]) - browserCanvasContext.lineWidth = 0.2 - browserCanvasContext.stroke() - browserCanvasContext.setLineDash([0, 0]) - - } - - //browserCanvasContext.beginPath(); - - let line1; - let line2; - - drawStrategy(); - drawTrade(); - - function drawStrategy() { - - if (strategyNumber < 15 && strategyNumber > 0) { - strategy.image = strategyImages[strategyNumber - 1]; - strategy.entryPoint = recordPoint2; - strategy.begin = record.begin - strategy.end = record.end - - imageToDraw = strategy.image; - - } - - if (strategyNumber === 0) { - - if (strategy.entryPoint !== undefined) { - /* Draw the line that represents the duration of closed strategy */ - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(strategy.entryPoint.x + imageSize / 2, strategy.entryPoint.y); - browserCanvasContext.lineTo(recordPoint2.x - imageSize / 2, recordPoint2.y); - - browserCanvasContext.closePath(); - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; - browserCanvasContext.lineWidth = 1 - - browserCanvasContext.stroke() - } - - imageToDraw = strategy.image; - } - - if (imageToDraw !== undefined) { - - if (strategyNumber !== undefined) { - - drawStick(recordPoint2); - - } - - if (imageToDraw.isLoaded === true) { - browserCanvasContext.drawImage(imageToDraw, recordPoint2.x - imageSize / 2, recordPoint2.y - imageSize / 2, imageSize, imageSize); - imageToDraw = undefined; - } - } - - if (strategyNumber === 0) { - strategy = { - begin: undefined, - end: undefined, - image: undefined, - entryPoint: undefined - } - } - } - - function drawTrade() { - - if (record.type === 'Buy@StopLoss' || record.type === 'Buy@BuyOrder') { - - if (record.type === 'Buy@StopLoss') { - - line1 = 'STOP'; - - } else { - - line1 = 'TP'; - } - - if (record.lastProfit < 0) { - - line2 = (record.lastProfitPercent).toFixed(2) + ' %'; - imageToDraw = smileySad; - - } else { - - line2 = (record.lastProfitPercent).toFixed(2) + ' %'; - imageToDraw = smileyHappy; - } - - if (trade.entryPoint !== undefined) { - /* Draw the triangle that represents the trade. */ - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(trade.entryPoint.x, trade.entryPoint.y); - browserCanvasContext.lineTo(recordPoint3.x, recordPoint3.y); - browserCanvasContext.lineTo(recordPoint3.x, trade.entryPoint.y); - - browserCanvasContext.closePath(); - - let opacity = '0.25'; - - if (recordPoint3.y > trade.entryPoint.y) { - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')'; - } else { - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; - } - - browserCanvasContext.fill(); - - browserCanvasContext.lineWidth = 1; - browserCanvasContext.stroke(); - } - - if ( - recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 - || - recordPoint3.x > viewPort.visibleArea.bottomRight.x - 250 - || - recordPoint3.y > viewPort.visibleArea.bottomRight.y - 100 - || - recordPoint3.y < viewPort.visibleArea.topLeft.y + 100 - ) { - // we do not write any text - } else { - if (line1 !== undefined && trade.entryPoint !== undefined) { - - printLabel(line1, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint4.y - 30, '0.50', 12); - printLabel(line2, recordPoint3.x - (recordPoint3.x - trade.entryPoint.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint4.y - 15, '0.50', 12); - - } - } - - } - - if (record.type === 'Sell') { - - line1 = ''; - line2 = ''; - - imageToDraw = smileyHappy; - - trade.begin = record.begin; - trade.end = record.end; - trade.entryPoint = recordPoint3; - } - } - /* Send the current record to the panel */ if (userPositionDate >= record.begin && userPositionDate <= record.end) { @@ -1036,25 +737,6 @@ }; thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); } - - /* This is how we write the text */ - - function printLabel(labelToPrint, x, y, opacity, fontSize) { - - let labelPoint; - - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; - - let label = '' + labelToPrint; - - let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; - browserCanvasContext.fillText(label, x, y); - - } - - } @@ -1069,8 +751,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } - recalculate(); } catch (err) { @@ -1083,8 +763,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } - if (Math.random() * 100 > 95) { recalculate() @@ -1100,8 +778,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] onDragFinished -> Entering function."); } - recalculate(); } catch (err) { diff --git a/this.plotter.config.json b/this.plotter.config.json index 38e54024c..d8ea7453e 100644 --- a/this.plotter.config.json +++ b/this.plotter.config.json @@ -29,6 +29,22 @@ } ] }, + { + "codeName": "Strategies", + "moduleName": "Strategies", + "description": "Plots Strategies.", + "profilePicture": "Strategies.png", + "panels": [ + ] + }, + { + "codeName": "Trades", + "moduleName": "Trades", + "description": "Plots Trades.", + "profilePicture": "Trades.png", + "panels": [ + ] + }, { "codeName": "SimulationExecution", "moduleName": "SimulationExecution", From f7122825293513b1dd995353103a49fba4e79772 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 30 Apr 2019 13:36:03 +0200 Subject: [PATCH 048/157] Balance Controls Implemented --- TradingSimulation.js | 19 +-- TradingSimulationPanel.js | 296 ++++++++++++++++++++++++++++++++++---- 2 files changed, 278 insertions(+), 37 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index f6b6c2a61..e61f1d813 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -557,6 +557,16 @@ for (let i = 1; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 record = records[i]; + + /* Send the current record to the panel */ + + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + + let currentRecord = { + innerRecord: record + }; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); + } let stopLossPhase = 0; let buyOrderPhase = 0; @@ -728,15 +738,6 @@ printLabel(buyOrderPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.9', 8); } - /* Send the current record to the panel */ - - if (userPositionDate >= record.begin && userPositionDate <= record.end) { - - let currentRecord = { - innerRecord: record - }; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); - } } diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 307922662..0d1bd24f1 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -1,7 +1,7 @@  -function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulationPanel () { +function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulationPanel() { - var thisObject = { + let thisObject = { onEventRaised: onEventRaised, container: undefined, draw: draw, @@ -9,7 +9,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation initialize: initialize }; - var container = newContainer(); + let container = newContainer(); container.initialize(); thisObject.container = container; @@ -18,6 +18,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let currentRecord; let panelTabButton + let controlHandler return thisObject; @@ -33,6 +34,9 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation panelTabButton.parentContainer = thisObject.container panelTabButton.container.frame.parentFrame = thisObject.container.frame panelTabButton.initialize() + + controlHandler = canvas.bottomSpace.createNewControl('Over The Line', drawAssetBalanceUI, 'Global') + } function getContainer(point) { @@ -94,86 +98,76 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let y = 0; let increment = 0.025; - y = y + increment; - printLabel('Balance A', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); - y = y + increment; - printLabel(currentRecord.innerRecord.balanceA, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); - - y = y + increment; - printLabel('Balance B', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); - y = y + increment; - printLabel(currentRecord.innerRecord.balanceB, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); - y = y + increment; printLabel('Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Last Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.lastProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.lastProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Last Profit %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.buyOrder, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.buyOrder, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); + printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); y = y + increment; printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50',16); - + printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + function printLabel(labelToPrint, x, y, opacity, fontSize) { let labelPoint; @@ -202,8 +196,254 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation browserCanvasContext.closePath(); browserCanvasContext.fill(); + /* Parameters */ + let params + let paramsArray = [] + + params = {} + params.VALUE = currentRecord.innerRecord.balanceA; + params.MIN_VALUE = 0.5 + params.MAX_VALUE = 1 + params.ASSET_LABEL = 'Asset A' + params.ASSET_NAME = DEFAULT_MARKET.assetB + ' ' + params.LEFT_OFFSET = 100 + + paramsArray.push(params) + + params = {} + params.VALUE = currentRecord.innerRecord.balanceB; + params.MIN_VALUE = 0 + params.MAX_VALUE = 6000 + params.ASSET_LABEL = 'Asset B' + params.ASSET_NAME = DEFAULT_MARKET.assetA + ' ' + params.LEFT_OFFSET = 220 + + paramsArray.push(params) + + let control = canvas.bottomSpace.getControl(controlHandler, 'Global') + control.paramsArray = paramsArray + } + function drawAssetBalanceUI(paramsArray) { + drawAssetCircle(paramsArray[0]) + drawAssetCircle(paramsArray[1]) + + let fontSize + let label + let xOffset + let yOffset + + const OPACITY = 1; + + /* We put the params.VALUE in the middle */ + + fontSize = 15; + + browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.WHITE + ' Saira'; + + label = 'ASSET BALANCES' + + + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + yOffset = -40 + + labelPoint = { + x: viewPort.visibleArea.bottomLeft.x - xOffset + (paramsArray[1].LEFT_OFFSET - paramsArray[0].LEFT_OFFSET) / 2 + paramsArray[0].LEFT_OFFSET - 20, + y: viewPort.visibleArea.bottomLeft.y - yOffset + }; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + } + + function drawAssetCircle(params) { + + /* We draw the circle container */ + + const RED_LINE_HIGHT = 5; + const RADIOUS = 50; + const OPACITY = 1; + + let centerPoint = { + x: viewPort.visibleArea.bottomLeft.x + params.LEFT_OFFSET, + y: viewPort.visibleArea.bottomLeft.y + } + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, RADIOUS + RED_LINE_HIGHT, 0.9 * Math.PI, 2.1 * Math.PI) + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + OPACITY + ')' + browserCanvasContext.fill() + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, RADIOUS, 0.0 * Math.PI, 2.0 * Math.PI) + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + OPACITY + ')' + browserCanvasContext.fill() + + + /* We draw the circle bar */ + + const DEFAULT_THICKNESS = 2; + const VALUE_THICKNESS = 4; + const BAR_RADIOUS = RADIOUS * 0.9; + const BAR_START_ANGLE = 0.9 * Math.PI; + const BAR_END_ANGLE = 2.1 * Math.PI; + const CURRENT_VALUE_ANGLE = params.VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE + const MIN_VALUE_ANGLE = params.MIN_VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE + let PROFIT_VALUE_ANGLE = (params.VALUE - params.MAX_VALUE) * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE + + if (PROFIT_VALUE_ANGLE > BAR_END_ANGLE) { PROFIT_VALUE_ANGLE = BAR_END_ANGLE } + + browserCanvasContext.setLineDash([0, 0]) + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, MIN_VALUE_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = DEFAULT_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, MIN_VALUE_ANGLE, BAR_END_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = DEFAULT_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + if (params.VALUE > 0 && params.VALUE <= params.MAX_VALUE) { + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, MIN_VALUE_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = VALUE_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, MIN_VALUE_ANGLE, CURRENT_VALUE_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = VALUE_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, CURRENT_VALUE_ANGLE, BAR_END_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = DEFAULT_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + } + + if (params.VALUE > params.MAX_VALUE) { + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, BAR_END_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = DEFAULT_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, PROFIT_VALUE_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = VALUE_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + } + + /* Common Variables */ + + let fontSize + let label + let xOffset + let yOffset + + /* We put the params.VALUE in the middle */ + + fontSize = 25; + + browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.WHITE + ' Saira'; + + label = params.VALUE; + if (isNaN(label) === false) { + label = Number(label); + label = label.toLocaleString(); + } + + label = label.substring(0, 5); + + + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + + labelPoint = { + x: centerPoint.x - xOffset, + y: centerPoint.y + }; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + + /* We put the top label */ + + fontSize = 15; + + browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.WHITE + ' Saira'; + + label = params.ASSET_LABEL; + + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + yOffset = 22 + + labelPoint = { + x: centerPoint.x - xOffset, + y: centerPoint.y - yOffset + }; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + + /* We put the bottom label */ + + fontSize = 15; + + browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.WHITE + ' Saira'; + + label = params.ASSET_NAME; + + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + yOffset = - 15 + + labelPoint = { + x: centerPoint.x - xOffset, + y: centerPoint.y - yOffset + }; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + + } } + + + + + + + + + From 5fff4f93f985a983f434c5e37babebe29f015810 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 3 May 2019 10:19:30 +0200 Subject: [PATCH 049/157] Adjustments to doble the value --- TradingSimulation.js | 75 ++++----------------- TradingSimulationPanel.js | 134 +++++++++++++++++++++++--------------- 2 files changed, 96 insertions(+), 113 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index e61f1d813..2b6a9aec2 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -324,33 +324,7 @@ for (let i = 0; i < dailyFile.length; i++) { - let record = { - begin: undefined, - end: undefined, - type: undefined, - rate: undefined, - amount: undefined, - balanceA: undefined, - balanceB: undefined, - profit: undefined, - lastProfit: undefined, - stopLoss: undefined, - roundtrips: undefined, - hits: undefined, - fails: undefined, - hitRatio: undefined, - ROI: undefined, - periods: undefined, - days: undefined, - anualizedRateOfReturn: undefined, - sellRate: undefined, - lastProfitPercent: undefined, - strategy: undefined, - strategyPhase: undefined, - buyOrder: undefined, - stopLossPhase: undefined, - buyOrderPhase: undefined - }; + let record = {}; record.begin = dailyFile[i][0]; record.end = dailyFile[i][1]; @@ -377,6 +351,7 @@ record.buyOrder = dailyFile[i][22]; record.stopLossPhase = dailyFile[i][23]; record.buyOrderPhase = dailyFile[i][24]; + record.sellAmount = dailyFile[i][26]; // 25 is the message for the executor if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -439,33 +414,7 @@ for (let i = 0; i < marketFile.length; i++) { - let record = { - begin: undefined, - end: undefined, - type: undefined, - rate: undefined, - amount: undefined, - balanceA: undefined, - balanceB: undefined, - profit: undefined, - lastProfit: undefined, - stopLoss: undefined, - roundtrips: undefined, - hits: undefined, - fails: undefined, - hitRatio: undefined, - ROI: undefined, - periods: undefined, - days: undefined, - anualizedRateOfReturn: undefined, - sellRate: undefined, - lastProfitPercent: undefined, - strategy: undefined, - strategyPhase: undefined, - buyOrder: undefined, - stopLossPhase: undefined, - buyOrderPhase: undefined - }; + let record = {}; record.begin = marketFile[i][0]; record.end = marketFile[i][1]; @@ -492,6 +441,7 @@ record.buyOrder = marketFile[i][22]; record.stopLossPhase = marketFile[i][23]; record.buyOrderPhase = marketFile[i][24]; + record.sellAmount = marketFile[i][26]; // 25 is the message for the executor if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -554,7 +504,7 @@ /* Now we calculate and plot the records */ - for (let i = 1; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 + for (let i = 0; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 record = records[i]; @@ -567,16 +517,18 @@ }; thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); } - + let stopLossPhase = 0; let buyOrderPhase = 0; - if (record.stopLossPhase !== records[i - 1].stopLossPhase) { - stopLossPhase = record.stopLossPhase; - } + if (i > 0) { + if (record.stopLossPhase !== records[i - 1].stopLossPhase) { + stopLossPhase = record.stopLossPhase; + } - if (record.buyOrderPhase !== records[i - 1].buyOrderPhase) { - buyOrderPhase = record.buyOrderPhase; + if (record.buyOrderPhase !== records[i - 1].buyOrderPhase) { + buyOrderPhase = record.buyOrderPhase; + } } let recordPoint4 = { @@ -811,5 +763,6 @@ + diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 0d1bd24f1..a6fffcdf8 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -6,7 +6,8 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation container: undefined, draw: draw, getContainer: getContainer, - initialize: initialize + initialize: initialize, + finalize: finalize }; let container = newContainer(); @@ -39,6 +40,13 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation } + function finalize() { + + canvas.bottomSpace.destroyControl(controlHandler) + controlHandler = undefined + + } + function getContainer(point) { var container; @@ -202,8 +210,9 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation params = {} params.VALUE = currentRecord.innerRecord.balanceA; + params.INIT_VALUE = 1 params.MIN_VALUE = 0.5 - params.MAX_VALUE = 1 + params.MAX_VALUE = 2 params.ASSET_LABEL = 'Asset A' params.ASSET_NAME = DEFAULT_MARKET.assetB + ' ' params.LEFT_OFFSET = 100 @@ -213,7 +222,8 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation params = {} params.VALUE = currentRecord.innerRecord.balanceB; params.MIN_VALUE = 0 - params.MAX_VALUE = 6000 + params.INIT_VALUE = currentRecord.innerRecord.rate * currentRecord.innerRecord.sellAmount; + params.MAX_VALUE = params.INIT_VALUE * 2; params.ASSET_LABEL = 'Asset B' params.ASSET_NAME = DEFAULT_MARKET.assetA + ' ' params.LEFT_OFFSET = 220 @@ -241,7 +251,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation fontSize = 15; - browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.WHITE + ' Saira'; + browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY label = 'ASSET BALANCES' @@ -290,34 +300,58 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation const DEFAULT_THICKNESS = 2; const VALUE_THICKNESS = 4; + const VALUE_BG_THICKNESS = 1; const BAR_RADIOUS = RADIOUS * 0.9; - const BAR_START_ANGLE = 0.9 * Math.PI; - const BAR_END_ANGLE = 2.1 * Math.PI; - const CURRENT_VALUE_ANGLE = params.VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE - const MIN_VALUE_ANGLE = params.MIN_VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE - let PROFIT_VALUE_ANGLE = (params.VALUE - params.MAX_VALUE) * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE - if (PROFIT_VALUE_ANGLE > BAR_END_ANGLE) { PROFIT_VALUE_ANGLE = BAR_END_ANGLE } + let BAR_START_ANGLE = 0.9 * Math.PI; + let BAR_END_ANGLE = 2.1 * Math.PI; + let CURRENT_VALUE_ANGLE = params.VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE + let MIN_VALUE_ANGLE = params.MIN_VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE + let INIT_VALUE_ANGLE = params.INIT_VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE + let PROFIT_VALUE_ANGLE = CURRENT_VALUE_ANGLE - browserCanvasContext.setLineDash([0, 0]) + if (CURRENT_VALUE_ANGLE > INIT_VALUE_ANGLE) { CURRENT_VALUE_ANGLE = INIT_VALUE_ANGLE } - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, MIN_VALUE_ANGLE) + if (params.VALUE > 0) { - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = DEFAULT_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); + browserCanvasContext.setLineDash([0, 0]) - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, MIN_VALUE_ANGLE, BAR_END_ANGLE) + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, MIN_VALUE_ANGLE) - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = DEFAULT_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = VALUE_BG_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); - if (params.VALUE > 0 && params.VALUE <= params.MAX_VALUE) { + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, MIN_VALUE_ANGLE, CURRENT_VALUE_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = VALUE_BG_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, CURRENT_VALUE_ANGLE, INIT_VALUE_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = VALUE_BG_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + + if (PROFIT_VALUE_ANGLE > INIT_VALUE_ANGLE) { + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, INIT_VALUE_ANGLE, PROFIT_VALUE_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = VALUE_BG_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + } + + browserCanvasContext.setLineDash([2, 3]) browserCanvasContext.beginPath(); browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, MIN_VALUE_ANGLE) @@ -336,33 +370,23 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation browserCanvasContext.closePath(); browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, CURRENT_VALUE_ANGLE, BAR_END_ANGLE) + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, CURRENT_VALUE_ANGLE, INIT_VALUE_ANGLE) browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = DEFAULT_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - - } - - if (params.VALUE > params.MAX_VALUE) { - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, BAR_END_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = DEFAULT_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, PROFIT_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + OPACITY + ')' browserCanvasContext.lineWidth = VALUE_THICKNESS browserCanvasContext.stroke() browserCanvasContext.closePath(); + if (PROFIT_VALUE_ANGLE > INIT_VALUE_ANGLE) { + + browserCanvasContext.beginPath(); + browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, INIT_VALUE_ANGLE, PROFIT_VALUE_ANGLE) + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + OPACITY + ')' + browserCanvasContext.lineWidth = VALUE_THICKNESS + browserCanvasContext.stroke() + browserCanvasContext.closePath(); + } } /* Common Variables */ @@ -376,18 +400,18 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation fontSize = 25; - browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.WHITE + ' Saira'; + browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY label = params.VALUE; if (isNaN(label) === false) { label = Number(label); - label = label.toLocaleString(); + if (label === 0) { label = label.toFixed(2) } else { label = label.toLocaleString() } } label = label.substring(0, 5); - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 10; labelPoint = { x: centerPoint.x - xOffset, @@ -401,11 +425,11 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation fontSize = 15; - browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.WHITE + ' Saira'; + browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY label = params.ASSET_LABEL; - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 7; yOffset = 22 labelPoint = { @@ -420,11 +444,11 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation fontSize = 15; - browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.WHITE + ' Saira'; + browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY label = params.ASSET_NAME; - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 5; yOffset = - 15 labelPoint = { @@ -447,3 +471,9 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + + + + + + From f49b61288d1ae626ae1c683a12d161be79487e2e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 3 May 2019 10:45:23 +0200 Subject: [PATCH 050/157] Adjusting look and feel --- TradingSimulationPanel.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index a6fffcdf8..eefa746a1 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -299,9 +299,9 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation /* We draw the circle bar */ const DEFAULT_THICKNESS = 2; - const VALUE_THICKNESS = 4; + const VALUE_THICKNESS = 8; const VALUE_BG_THICKNESS = 1; - const BAR_RADIOUS = RADIOUS * 0.9; + const BAR_RADIOUS = RADIOUS * 0.85; let BAR_START_ANGLE = 0.9 * Math.PI; let BAR_END_ANGLE = 2.1 * Math.PI; @@ -398,7 +398,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation /* We put the params.VALUE in the middle */ - fontSize = 25; + fontSize = 22; browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY @@ -411,7 +411,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation label = label.substring(0, 5); - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 10; + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 7; labelPoint = { x: centerPoint.x - xOffset, @@ -423,13 +423,13 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation /* We put the top label */ - fontSize = 15; + fontSize = 12; browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY label = params.ASSET_LABEL; - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 7; + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 3; yOffset = 22 labelPoint = { @@ -442,13 +442,13 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation /* We put the bottom label */ - fontSize = 15; + fontSize = 12; browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY label = params.ASSET_NAME; - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 5; + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 3; yOffset = - 15 labelPoint = { @@ -477,3 +477,4 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + From 68954a6d4edc750b8b7c1fbc297dd80cb7e44226 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 12 May 2019 10:12:39 +0200 Subject: [PATCH 051/157] fitFunction --- ConditionsPanel.js | 27 ++++++++++--------- TradingSimulationPanel.js | 57 ++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index bbd491bed..cacd35d2f 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -2,6 +2,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { var thisObject = { + fitFunction: undefined, onEventRaised: onEventRaised, container: undefined, draw: draw, @@ -13,7 +14,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { container.initialize(); thisObject.container = container; - container.displacement.containerName = "Conditions Panel"; + container.displacement.containerName = "Conditions"; container.frame.containerName = "Conditions Panel"; let currentRecord; @@ -32,29 +33,30 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { panelTabButton = newPanelTabButton() panelTabButton.parentContainer = thisObject.container panelTabButton.container.frame.parentFrame = thisObject.container.frame + panelTabButton.fitFunction = thisObject.fitFunction panelTabButton.initialize() } function getContainer(point) { - var container; + let container; container = panelTabButton.getContainer(point) if (container !== undefined) { return container } - /* First we check if this point is inside this space. */ + if (thisObject.container.frame.isThisPointHere(point, true) === true) { - if (this.container.frame.isThisPointHere(point, true) === true) { + let checkPoint = { + x: point.x, + y: point.y + } - return this.container; + checkPoint = thisObject.fitFunction(checkPoint) - } else { - - /* This point does not belong to this space. */ - - return undefined; + if (point.x === checkPoint.x && point.y === checkPoint.y) { + return thisObject.container; + } } - } @@ -67,7 +69,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { function draw() { - this.container.frame.draw(false, false, true); + thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); plotCurrentRecordInfo(); @@ -236,6 +238,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { }; labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); + labelPoint = thisObject.fitFunction(labelPoint) browserCanvasContext.fillStyle = 'rgba(' + color + ', ' + opacity + ')'; browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index eefa746a1..067a29576 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -2,6 +2,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulationPanel() { let thisObject = { + fitFunction: undefined, onEventRaised: onEventRaised, container: undefined, draw: draw, @@ -14,8 +15,8 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation container.initialize(); thisObject.container = container; - container.displacement.containerName = "Simulated Records Panel"; - container.frame.containerName = "Simulated Records Panel"; + container.displacement.containerName = "Simulation"; + container.frame.containerName = "Simulation"; let currentRecord; let panelTabButton @@ -34,6 +35,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation panelTabButton = newPanelTabButton() panelTabButton.parentContainer = thisObject.container panelTabButton.container.frame.parentFrame = thisObject.container.frame + panelTabButton.fitFunction = thisObject.fitFunction panelTabButton.initialize() controlHandler = canvas.bottomSpace.createNewControl('Over The Line', drawAssetBalanceUI, 'Global') @@ -49,24 +51,24 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function getContainer(point) { - var container; + let container; container = panelTabButton.getContainer(point) if (container !== undefined) { return container } - /* First we check if this point is inside this space. */ + if (thisObject.container.frame.isThisPointHere(point, true) === true) { - if (this.container.frame.isThisPointHere(point, true) === true) { + let checkPoint = { + x: point.x, + y: point.y + } - return this.container; + checkPoint = thisObject.fitFunction(checkPoint) - } else { - - /* This point does not belong to this space. */ - - return undefined; + if (point.x === checkPoint.x && point.y === checkPoint.y) { + return thisObject.container; + } } - } @@ -79,7 +81,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function draw() { - this.container.frame.draw(false, false, true); + thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); plotCurrentRecordInfo(); @@ -109,72 +111,72 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel('Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Last Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.lastProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.lastProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Last Profit %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.buyOrder, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.buyOrder, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 16); + printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); function printLabel(labelToPrint, x, y, opacity, fontSize) { @@ -195,6 +197,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation }; labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); + labelPoint = thisObject.fitFunction(labelPoint) browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); From 975892ac4d8e8a7fec89fe07ffb31e0ece2650e6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 12 May 2019 11:37:43 +0200 Subject: [PATCH 052/157] Trying to avoid anoying moving effect --- TradingSimulationPanel.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 067a29576..0427a9c10 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -263,8 +263,8 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation yOffset = -40 labelPoint = { - x: viewPort.visibleArea.bottomLeft.x - xOffset + (paramsArray[1].LEFT_OFFSET - paramsArray[0].LEFT_OFFSET) / 2 + paramsArray[0].LEFT_OFFSET - 20, - y: viewPort.visibleArea.bottomLeft.y - yOffset + x: 0 - xOffset + (paramsArray[1].LEFT_OFFSET - paramsArray[0].LEFT_OFFSET) / 2 + paramsArray[0].LEFT_OFFSET - 20, + y: BOTTOM_SPACE_POSITION - BOTTOM_SPACE_HEIGHT/ 2 - yOffset }; browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; @@ -280,8 +280,8 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation const OPACITY = 1; let centerPoint = { - x: viewPort.visibleArea.bottomLeft.x + params.LEFT_OFFSET, - y: viewPort.visibleArea.bottomLeft.y + x: params.LEFT_OFFSET, + y: BOTTOM_SPACE_POSITION - BOTTOM_SPACE_HEIGHT / 2 } browserCanvasContext.beginPath(); From 8f89dc78923d7285104efcea736a28b410e177b5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 16 May 2019 19:15:04 +0200 Subject: [PATCH 053/157] Integration with new icons --- Strategies.js | 4 +- TradingSimulation.js | 11 +- TradingSimulationPanel.js | 238 +------------------------------------- 3 files changed, 11 insertions(+), 242 deletions(-) diff --git a/Strategies.js b/Strategies.js index 8e2e663f9..de5e91ce3 100644 --- a/Strategies.js +++ b/Strategies.js @@ -130,7 +130,7 @@ }) for (let i = 1; i < 15; i++) { - let strategyImage = loadEmoji("Symbols/Emoji Symbols-" + (112 + i) + ".png"); + let strategyImage = canvas.strategySpace.iconByPartType.get('Strategy'); strategyImages.push(strategyImage); } @@ -561,7 +561,7 @@ drawStick(recordPoint1, recordPoint3); drawStick(recordPoint2, recordPoint4); - if (imageToDraw.isLoaded === true) { + if (imageToDraw.canDrawIcon === true) { browserCanvasContext.drawImage(imageToDraw, recordPoint3.x - imageSize / 2, recordPoint3.y - imageSize / 2, imageSize, imageSize); if (record.status === 1) { browserCanvasContext.drawImage(imageToDraw, recordPoint4.x - imageSize / 2, recordPoint4.y - imageSize / 2, imageSize, imageSize); diff --git a/TradingSimulation.js b/TradingSimulation.js index 2b6a9aec2..60030a0dc 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -136,8 +136,8 @@ /* Loading a few icons */ - imageStopLossPhase = loadEmoji("stop.png"); - imageBuyOrderPhase = loadEmoji("Nature/Emoji Natur-67.png"); + imageStopLossPhase = canvas.strategySpace.iconByPartType.get('Stop'); + imageBuyOrderPhase = canvas.strategySpace.iconByPartType.get('Phase'); callBackFunction(); @@ -657,9 +657,9 @@ browserCanvasContext.stroke() - if (imageStopLossPhase.isLoaded === true && stopLossPhase > 0) { + if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > 0) { browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize * 1.25, imageSize, imageSize); - printLabel(stopLossPhase, recordPoint5.x - imageSize / 2, recordPoint5.y - imageSize * 1.5, '0.9', 8); + printLabel(stopLossPhase, recordPoint5.x - imageSize / 2 - 3, recordPoint5.y - imageSize * 1.5, '0.9', 8); } /* Next we are drawing the Buy Order */ @@ -685,7 +685,7 @@ browserCanvasContext.lineWidth = 5 browserCanvasContext.stroke() - if (imageBuyOrderPhase.isLoaded === true && buyOrderPhase > 0) { + if (imageBuyOrderPhase.canDrawIcon === true && buyOrderPhase > 0) { browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4, imageSize, imageSize); printLabel(buyOrderPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.9', 8); } @@ -764,5 +764,6 @@ + diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 0427a9c10..d40ab75e0 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -20,7 +20,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let currentRecord; let panelTabButton - let controlHandler + return thisObject; @@ -38,15 +38,10 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation panelTabButton.fitFunction = thisObject.fitFunction panelTabButton.initialize() - controlHandler = canvas.bottomSpace.createNewControl('Over The Line', drawAssetBalanceUI, 'Global') - } function finalize() { - canvas.bottomSpace.destroyControl(controlHandler) - controlHandler = undefined - } function getContainer(point) { @@ -233,235 +228,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation paramsArray.push(params) - let control = canvas.bottomSpace.getControl(controlHandler, 'Global') - control.paramsArray = paramsArray - - } - - function drawAssetBalanceUI(paramsArray) { - - drawAssetCircle(paramsArray[0]) - drawAssetCircle(paramsArray[1]) - - let fontSize - let label - let xOffset - let yOffset - - const OPACITY = 1; - - /* We put the params.VALUE in the middle */ - - fontSize = 15; - - browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY - - label = 'ASSET BALANCES' - - - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; - yOffset = -40 - - labelPoint = { - x: 0 - xOffset + (paramsArray[1].LEFT_OFFSET - paramsArray[0].LEFT_OFFSET) / 2 + paramsArray[0].LEFT_OFFSET - 20, - y: BOTTOM_SPACE_POSITION - BOTTOM_SPACE_HEIGHT/ 2 - yOffset - }; - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - } - - function drawAssetCircle(params) { - - /* We draw the circle container */ - - const RED_LINE_HIGHT = 5; - const RADIOUS = 50; - const OPACITY = 1; - - let centerPoint = { - x: params.LEFT_OFFSET, - y: BOTTOM_SPACE_POSITION - BOTTOM_SPACE_HEIGHT / 2 - } - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, RADIOUS + RED_LINE_HIGHT, 0.9 * Math.PI, 2.1 * Math.PI) - browserCanvasContext.closePath(); - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + OPACITY + ')' - browserCanvasContext.fill() - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, RADIOUS, 0.0 * Math.PI, 2.0 * Math.PI) - browserCanvasContext.closePath(); - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + OPACITY + ')' - browserCanvasContext.fill() - - - /* We draw the circle bar */ - - const DEFAULT_THICKNESS = 2; - const VALUE_THICKNESS = 8; - const VALUE_BG_THICKNESS = 1; - const BAR_RADIOUS = RADIOUS * 0.85; - - let BAR_START_ANGLE = 0.9 * Math.PI; - let BAR_END_ANGLE = 2.1 * Math.PI; - let CURRENT_VALUE_ANGLE = params.VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE - let MIN_VALUE_ANGLE = params.MIN_VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE - let INIT_VALUE_ANGLE = params.INIT_VALUE * (BAR_END_ANGLE - BAR_START_ANGLE) / params.MAX_VALUE + BAR_START_ANGLE - let PROFIT_VALUE_ANGLE = CURRENT_VALUE_ANGLE - - if (CURRENT_VALUE_ANGLE > INIT_VALUE_ANGLE) { CURRENT_VALUE_ANGLE = INIT_VALUE_ANGLE } - - if (params.VALUE > 0) { - - browserCanvasContext.setLineDash([0, 0]) - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, MIN_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = VALUE_BG_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, MIN_VALUE_ANGLE, CURRENT_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = VALUE_BG_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, CURRENT_VALUE_ANGLE, INIT_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = VALUE_BG_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - - if (PROFIT_VALUE_ANGLE > INIT_VALUE_ANGLE) { - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, INIT_VALUE_ANGLE, PROFIT_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = VALUE_BG_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - } - - browserCanvasContext.setLineDash([2, 3]) - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, BAR_START_ANGLE, MIN_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = VALUE_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, MIN_VALUE_ANGLE, CURRENT_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = VALUE_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, CURRENT_VALUE_ANGLE, INIT_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = VALUE_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - - if (PROFIT_VALUE_ANGLE > INIT_VALUE_ANGLE) { - - browserCanvasContext.beginPath(); - browserCanvasContext.arc(centerPoint.x, centerPoint.y, BAR_RADIOUS, INIT_VALUE_ANGLE, PROFIT_VALUE_ANGLE) - - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = VALUE_THICKNESS - browserCanvasContext.stroke() - browserCanvasContext.closePath(); - } - } - - /* Common Variables */ - - let fontSize - let label - let xOffset - let yOffset - - /* We put the params.VALUE in the middle */ - - fontSize = 22; - - browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY - - label = params.VALUE; - if (isNaN(label) === false) { - label = Number(label); - if (label === 0) { label = label.toFixed(2) } else { label = label.toLocaleString() } - } - - label = label.substring(0, 5); - - - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 7; - - labelPoint = { - x: centerPoint.x - xOffset, - y: centerPoint.y - }; - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - - /* We put the top label */ - - fontSize = 12; - - browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY - - label = params.ASSET_LABEL; - - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 3; - yOffset = 22 - - labelPoint = { - x: centerPoint.x - xOffset, - y: centerPoint.y - yOffset - }; - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - - /* We put the bottom label */ - - fontSize = 12; - - browserCanvasContext.font = "bold " + fontSize + 'px ' + UI_FONT.PRIMARY - - label = params.ASSET_NAME; - - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 3; - yOffset = - 15 - - labelPoint = { - x: centerPoint.x - xOffset, - y: centerPoint.y - yOffset - }; - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')'; - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - + canvas.cockpitSpace.assetBalances.setParamsArray(paramsArray) } } @@ -481,3 +248,4 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + From d253404dcf4ba7db5e50e534410cbf90f0b4ca93 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 18 May 2019 17:05:10 +0200 Subject: [PATCH 054/157] Record Images --- TradingSimulation.js | 64 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 60030a0dc..c2e883d18 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -51,6 +51,7 @@ let imageStopLossPhase; let imageBuyOrderPhase; + let imageRecord; let zoomChangedEventSubscriptionId let offsetChangedEventSubscriptionId @@ -75,6 +76,7 @@ imageStopLossPhase = undefined; imageBuyOrderPhase = undefined; + imageRecord = undefined; /* Destroy References */ @@ -138,6 +140,7 @@ imageStopLossPhase = canvas.strategySpace.iconByPartType.get('Stop'); imageBuyOrderPhase = canvas.strategySpace.iconByPartType.get('Phase'); + imageRecord = canvas.strategySpace.iconByPartType.get('Trading System'); callBackFunction(); @@ -531,6 +534,21 @@ } } + let recordPoint1 = { + x: record.begin + timePeriod / 7 * 1.5, + y: thisObject.container.frame.height + }; + + let recordPoint2 = { + x: record.end + timePeriod / 7 * 5.5, + y: thisObject.container.frame.height + }; + + let recordPoint3 = { + x: recordPoint1.x + (recordPoint2.x - recordPoint1.x) / 2, + y: thisObject.container.frame.height + }; + let recordPoint4 = { x: record.begin, y: record.stopLoss @@ -579,6 +597,9 @@ recordPoint9.x = 0; } + recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); + recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); + recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); recordPoint5 = timeLineCoordinateSystem.transformThisPoint(recordPoint5); recordPoint6 = timeLineCoordinateSystem.transformThisPoint(recordPoint6); @@ -586,6 +607,9 @@ recordPoint8 = timeLineCoordinateSystem.transformThisPoint(recordPoint8); recordPoint9 = timeLineCoordinateSystem.transformThisPoint(recordPoint9); + recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); + recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); + recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); recordPoint5 = transformThisPoint(recordPoint5, thisObject.container); recordPoint6 = transformThisPoint(recordPoint6, thisObject.container); @@ -593,10 +617,9 @@ recordPoint8 = transformThisPoint(recordPoint8, thisObject.container); recordPoint9 = transformThisPoint(recordPoint9, thisObject.container); - if (recordPoint4.x < viewPort.visibleArea.bottomLeft.x || recordPoint4.x > viewPort.visibleArea.bottomRight.x) { - continue; - } - + recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); + recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); + recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); recordPoint5 = viewPort.fitIntoVisibleArea(recordPoint5); recordPoint6 = viewPort.fitIntoVisibleArea(recordPoint6); @@ -604,6 +627,36 @@ recordPoint8 = viewPort.fitIntoVisibleArea(recordPoint8); recordPoint9 = viewPort.fitIntoVisibleArea(recordPoint9); + /* Image representing a Record */ + + let imageOffset = { + x: 0, + y: 15 + } + let imageSize = (recordPoint2.x - recordPoint1.x) / 2; + let recordLabel = record.periods.toString() + if (imageSize < 8) { + if (recordLabel[recordLabel.length - 1] !== '0' || imageSize < 4) + recordLabel = '' + } + let labelOffset = { + x: 0 - imageSize / 2 + 3 + imageOffset.x, + y: -2 + imageOffset.y + } + + if (imageRecord.canDrawIcon === true) { + browserCanvasContext.drawImage(imageRecord, recordPoint1.x + imageOffset.x, recordPoint1.y + imageOffset.y, imageSize, imageSize); + browserCanvasContext.save(); + browserCanvasContext.translate(recordPoint3.x + labelOffset.x, recordPoint3.y + labelOffset.y); + browserCanvasContext.rotate(-Math.PI / 2); + printLabel(recordLabel, 0, 0, '0.9', 8); + browserCanvasContext.restore(); + } + + if (recordPoint4.x < viewPort.visibleArea.bottomLeft.x || recordPoint4.x > viewPort.visibleArea.bottomRight.x) { + continue; + } + /* Next we are drawing the sellRate */ browserCanvasContext.beginPath(); @@ -628,7 +681,7 @@ browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) - let imageSize = 20; + imageSize = 20; let imageToDraw; /* Next we are drawing the stopLoss floor / ceilling */ @@ -765,5 +818,6 @@ + From 970c2e96cc71143a5330d85492151b8884370654 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 19 May 2019 16:53:34 +0200 Subject: [PATCH 055/157] Cleaning Records when time Period changes --- Conditions.js | 14 ++++---------- Strategies.js | 12 +++--------- Trades.js | 12 +++--------- TradingSimulation.js | 46 +++++++++++++++----------------------------- 4 files changed, 26 insertions(+), 58 deletions(-) diff --git a/Conditions.js b/Conditions.js index 232ef1059..650401534 100644 --- a/Conditions.js +++ b/Conditions.js @@ -185,21 +185,15 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod !== pTimePeriod) { timePeriod = pTimePeriod; if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimePeriod); - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; - recalculate(); - } + recalculate(); } else { @@ -207,7 +201,7 @@ fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. recalculate(); - + } } @@ -265,7 +259,7 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + records = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { diff --git a/Strategies.js b/Strategies.js index de5e91ce3..de045c4bb 100644 --- a/Strategies.js +++ b/Strategies.js @@ -193,21 +193,15 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod !== pTimePeriod) { timePeriod = pTimePeriod; if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimePeriod); - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; - recalculate(); - } + recalculate(); } else { @@ -273,7 +267,7 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + records = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { diff --git a/Trades.js b/Trades.js index fc51c9229..0fd53b3c9 100644 --- a/Trades.js +++ b/Trades.js @@ -185,21 +185,15 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod !== pTimePeriod) { timePeriod = pTimePeriod; if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimePeriod); - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; - recalculate(); - } + recalculate(); } else { @@ -265,7 +259,7 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + records = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { diff --git a/TradingSimulation.js b/TradingSimulation.js index c2e883d18..5eb0cb6bd 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -151,27 +151,13 @@ } function getContainer(point) { - - try { - - let container; - - /* First we check if this point is inside this space. */ - - if (this.container.frame.isThisPointHere(point) === true) { - - return this.container; - - } else { - - /* This point does not belong to this space. */ - - return undefined; - } - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err = " + err.stack); } + let container; + /* First we check if this point is inside this space. */ + if (this.container.frame.isThisPointHere(point) === true) { + return this.container; + } else { + /* This point does not belong to this space. */ + return undefined; } } @@ -203,14 +189,10 @@ if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = marketFiles.getFile(pTimePeriod); - - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; - recalculate(); - } + marketFile = marketFiles.getFile(pTimePeriod); + recalculate(); + } else { let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); @@ -271,6 +253,8 @@ try { + records = [] + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { recalculateUsingMarketFiles(); @@ -631,10 +615,10 @@ let imageOffset = { x: 0, - y: 15 + y: 30 } let imageSize = (recordPoint2.x - recordPoint1.x) / 2; - let recordLabel = record.periods.toString() + let recordLabel = record.periods.toLocaleString() if (imageSize < 8) { if (recordLabel[recordLabel.length - 1] !== '0' || imageSize < 4) recordLabel = '' @@ -818,6 +802,8 @@ + + From a2e09937827d1eb310ee5dea6aac90fcb5fa567d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 19 May 2019 17:00:36 +0200 Subject: [PATCH 056/157] Bad Array Names --- Conditions.js | 2 +- Strategies.js | 2 +- Trades.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Conditions.js b/Conditions.js index 650401534..0e3e135d7 100644 --- a/Conditions.js +++ b/Conditions.js @@ -259,7 +259,7 @@ try { - records = [] + conditions = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { diff --git a/Strategies.js b/Strategies.js index de045c4bb..1f52a9890 100644 --- a/Strategies.js +++ b/Strategies.js @@ -267,7 +267,7 @@ try { - records = [] + strategies = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { diff --git a/Trades.js b/Trades.js index 0fd53b3c9..b048272af 100644 --- a/Trades.js +++ b/Trades.js @@ -259,7 +259,7 @@ try { - records = [] + trades = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { From 36631358583c4412e85ba862afa267bc5a54f524 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 20 May 2019 01:46:17 +0200 Subject: [PATCH 057/157] isExecuting working on phases also --- ConditionsPanel.js | 147 ++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 108 deletions(-) diff --git a/ConditionsPanel.js b/ConditionsPanel.js index cacd35d2f..b2a38f947 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -69,11 +69,10 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { function draw() { - thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); plotCurrentRecordInfo(); - panelTabButton.draw() + } @@ -81,19 +80,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { if (currentRecord === undefined) { return; } if (currentRecord.conditionsNames === undefined) { return; } - - const frameBodyHeight = thisObject.container.frame.getBodyHeight(); - const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; - - const X_AXIS = thisObject.container.frame.width * 1 / 10; - const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; - - let y = 0; - let increment = 0.02; - let opacity; - let label; - let indent = 5; - let showLabel; + if (canvas.strategySpace.workspace === undefined) { return; } browserCanvasContext.beginPath(); @@ -104,146 +91,86 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let strategy = simulationLogic.strategies[j]; - showLabel = true; - - if (currentRecord.strategyNumber > 0 && currentRecord.strategyNumber - 1 !== j) { showLabel = false; } - - if (showLabel) { y = y + increment; } - opacity = '1.00'; - label = 'Strategy: ' + strategy.name; - printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); - - if (showLabel) { y = y + increment; } - opacity = '0.50'; - label = 'Entry Points'; - printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + if (currentRecord.strategyNumber - 1 === j) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = false + } for (let k = 0; k < strategy.entryPoint.situations.length; k++) { let situation = strategy.entryPoint.situations[k]; - processSituation(situation); + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].entryPoint.situations[k]); } - if (showLabel) { y = y + increment; } - opacity = '0.50'; - label = 'Exit Points'; - printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); - for (let k = 0; k < strategy.exitPoint.situations.length; k++) { let situation = strategy.exitPoint.situations[k]; - processSituation(situation); + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].exitPoint.situations[k]); } - if (currentRecord.strategyNumber - 1 !== j) { showLabel = false; } - - if (showLabel) { y = y + increment; } - opacity = '0.50'; - label = 'Sell Points'; - printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); - for (let k = 0; k < strategy.sellPoint.situations.length; k++) { let situation = strategy.sellPoint.situations[k]; - processSituation(situation); + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].sellPoint.situations[k]); } - if (showLabel) { y = y + increment; } - opacity = '0.50'; - label = 'Stop Loss Management'; - printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); - for (let p = 0; p < strategy.stopLoss.phases.length; p++) { - let phase = strategy.stopLoss.phases[p]; + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].payload.uiObject.isExecuting = false + } - if (showLabel) { y = y + increment; } - opacity = '0.50'; - label = 'Phase: ' + phase.name; - printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + let phase = strategy.stopLoss.phases[p]; for (let k = 0; k < phase.situations.length; k++) { let situation = phase.situations[k]; - processSituation(situation); + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].situations[k]); } } - if (showLabel) { y = y + increment; } - opacity = '0.50'; - label = 'Buy Order Management'; - printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); - for (let p = 0; p < strategy.buyOrder.phases.length; p++) { - let phase = strategy.buyOrder.phases[p]; + if (currentRecord.strategyNumber - 1 === j && currentRecord.buyOrderPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].payload.uiObject.isExecuting = false + } - if (showLabel) { y = y + increment; } - opacity = '0.50'; - label = 'Phase: ' + phase.name; - printLabel(label, X_AXIS + indent * 1, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + let phase = strategy.buyOrder.phases[p]; for (let k = 0; k < phase.situations.length; k++) { let situation = phase.situations[k]; - processSituation(situation); + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].situations[k]); } } } - function processSituation(situation) { + function processSituation(situation, node) { - if (showLabel) { y = y + increment; } - opacity = '0.50'; - label = 'Situation: ' + situation.name; - printLabel(label, X_AXIS + indent * 2, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + let highlightSituation = true for (let m = 0; m < situation.conditions.length; m++) { - - let condition = situation.conditions[m]; - let color; - - if (showLabel) { y = y + increment; } if (currentRecord.conditionsValues[conditionIndex] === 1) { - opacity = '0.50' - color = UI_COLOR.PATINATED_TURQUOISE; + node.conditions[m].payload.uiObject.highlight() } else { - opacity = '0.50'; - color = UI_COLOR.RUSTED_RED; + node.conditions[m].payload.uiObject.unHighlight() + highlightSituation = false } conditionIndex++; - label = condition.name; - printLabel(label, X_AXIS + indent * 3, frameTitleHeight + frameBodyHeight * y, opacity, color); + } + + if (highlightSituation === true) { + node.payload.uiObject.highlight() + } else { + node.payload.uiObject.unHighlight() } } - function printLabel(labelToPrint, x, y, opacity, color) { - - if (showLabel === false) { return; } - - let labelPoint; - let fontSize = 10; - - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; - - let label = '' + labelToPrint; - if (isNaN(label) === false) { - label = Number(label).toLocaleString(); - } - let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; - - labelPoint = { - x: x, - y: y - }; - - labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); - labelPoint = thisObject.fitFunction(labelPoint) - - browserCanvasContext.fillStyle = 'rgba(' + color + ', ' + opacity + ')'; - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - - } browserCanvasContext.closePath(); browserCanvasContext.fill(); @@ -259,3 +186,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { + + + + From 68599d1f0ba0af42cadcd517093d533ebe4bf994 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 20 May 2019 13:02:58 +0200 Subject: [PATCH 058/157] Bug Fix: nor recalculation --- Conditions.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/Conditions.js b/Conditions.js index 0e3e135d7..4104026de 100644 --- a/Conditions.js +++ b/Conditions.js @@ -441,9 +441,6 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); } - - if (marketFile === undefined) { return; } // We need the market file to be loaded to make the calculation. if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. From 95b32c60e11b5231cd0828beccc0dd42a9e4374e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 20 May 2019 13:17:33 +0200 Subject: [PATCH 059/157] Conditions Panel removed --- Conditions.js | 105 ++++++++++++++++++++- ConditionsPanel.js | 192 --------------------------------------- Project.njsproj | 3 - this.plotter.config.json | 8 +- 4 files changed, 105 insertions(+), 203 deletions(-) delete mode 100644 ConditionsPanel.js diff --git a/Conditions.js b/Conditions.js index 4104026de..bb3ef5da1 100644 --- a/Conditions.js +++ b/Conditions.js @@ -495,7 +495,8 @@ buyOrderPhase: conditionRecord.buyOrderPhase, conditionsValues: conditionRecord.conditions }; - thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", currentRecord); + + sendRecordInfoToStrategySpace(currentRecord) } } @@ -505,6 +506,108 @@ } } + function sendRecordInfoToStrategySpace(currentRecord) { + + if (currentRecord === undefined) { return; } + if (currentRecord.conditionsNames === undefined) { return; } + if (canvas.strategySpace.workspace === undefined) { return; } + + browserCanvasContext.beginPath(); + + let simulationLogic = currentRecord.conditionsNames; + let conditionIndex = 0; + + for (let j = 0; j < simulationLogic.strategies.length; j++) { + + let strategy = simulationLogic.strategies[j]; + + if (currentRecord.strategyNumber - 1 === j) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = false + } + + for (let k = 0; k < strategy.entryPoint.situations.length; k++) { + + let situation = strategy.entryPoint.situations[k]; + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].entryPoint.situations[k]); + } + + for (let k = 0; k < strategy.exitPoint.situations.length; k++) { + + let situation = strategy.exitPoint.situations[k]; + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].exitPoint.situations[k]); + } + + for (let k = 0; k < strategy.sellPoint.situations.length; k++) { + + let situation = strategy.sellPoint.situations[k]; + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].sellPoint.situations[k]); + } + + for (let p = 0; p < strategy.stopLoss.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].payload.uiObject.isExecuting = false + } + + let phase = strategy.stopLoss.phases[p]; + + for (let k = 0; k < phase.situations.length; k++) { + + let situation = phase.situations[k]; + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].situations[k]); + } + } + + for (let p = 0; p < strategy.buyOrder.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.buyOrderPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].payload.uiObject.isExecuting = false + } + + let phase = strategy.buyOrder.phases[p]; + + for (let k = 0; k < phase.situations.length; k++) { + + let situation = phase.situations[k]; + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].situations[k]); + } + } + } + + function processSituation(situation, node) { + + let highlightSituation = true + + for (let m = 0; m < situation.conditions.length; m++) { + if (currentRecord.conditionsValues[conditionIndex] === 1) { + node.conditions[m].payload.uiObject.highlight() + } else { + node.conditions[m].payload.uiObject.unHighlight() + highlightSituation = false + } + conditionIndex++; + } + + if (highlightSituation === true) { + node.payload.uiObject.highlight() + } else { + node.payload.uiObject.unHighlight() + } + } + + + browserCanvasContext.closePath(); + browserCanvasContext.fill(); + + } + + function onZoomChanged(event) { diff --git a/ConditionsPanel.js b/ConditionsPanel.js deleted file mode 100644 index b2a38f947..000000000 --- a/ConditionsPanel.js +++ /dev/null @@ -1,192 +0,0 @@ - -function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { - - var thisObject = { - fitFunction: undefined, - onEventRaised: onEventRaised, - container: undefined, - draw: draw, - getContainer: getContainer, - initialize: initialize - }; - - var container = newContainer(); - container.initialize(); - thisObject.container = container; - - container.displacement.containerName = "Conditions"; - container.frame.containerName = "Conditions Panel"; - - let currentRecord; - let panelTabButton - - return thisObject; - - function initialize() { - - thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 2; - thisObject.container.frame.height = viewPort.visibleArea.bottomLeft.y - viewPort.visibleArea.topLeft.y; - - thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - UI_PANEL.WIDTH.NORMAL * 3; - thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; - - panelTabButton = newPanelTabButton() - panelTabButton.parentContainer = thisObject.container - panelTabButton.container.frame.parentFrame = thisObject.container.frame - panelTabButton.fitFunction = thisObject.fitFunction - panelTabButton.initialize() - } - - function getContainer(point) { - - let container; - - container = panelTabButton.getContainer(point) - if (container !== undefined) { return container } - - if (thisObject.container.frame.isThisPointHere(point, true) === true) { - - let checkPoint = { - x: point.x, - y: point.y - } - - checkPoint = thisObject.fitFunction(checkPoint) - - if (point.x === checkPoint.x && point.y === checkPoint.y) { - return thisObject.container; - } - } - } - - - function onEventRaised(lastCurrentRecord) { - - currentRecord = lastCurrentRecord; - - } - - - function draw() { - - - plotCurrentRecordInfo(); - - - } - - - function plotCurrentRecordInfo() { - - if (currentRecord === undefined) { return; } - if (currentRecord.conditionsNames === undefined) { return; } - if (canvas.strategySpace.workspace === undefined) { return; } - - browserCanvasContext.beginPath(); - - let simulationLogic = currentRecord.conditionsNames; - let conditionIndex = 0; - - for (let j = 0; j < simulationLogic.strategies.length; j++) { - - let strategy = simulationLogic.strategies[j]; - - if (currentRecord.strategyNumber - 1 === j) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = false - } - - for (let k = 0; k < strategy.entryPoint.situations.length; k++) { - - let situation = strategy.entryPoint.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].entryPoint.situations[k]); - } - - for (let k = 0; k < strategy.exitPoint.situations.length; k++) { - - let situation = strategy.exitPoint.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].exitPoint.situations[k]); - } - - for (let k = 0; k < strategy.sellPoint.situations.length; k++) { - - let situation = strategy.sellPoint.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].sellPoint.situations[k]); - } - - for (let p = 0; p < strategy.stopLoss.phases.length; p++) { - - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].payload.uiObject.isExecuting = false - } - - let phase = strategy.stopLoss.phases[p]; - - for (let k = 0; k < phase.situations.length; k++) { - - let situation = phase.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].situations[k]); - } - } - - for (let p = 0; p < strategy.buyOrder.phases.length; p++) { - - if (currentRecord.strategyNumber - 1 === j && currentRecord.buyOrderPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].payload.uiObject.isExecuting = false - } - - let phase = strategy.buyOrder.phases[p]; - - for (let k = 0; k < phase.situations.length; k++) { - - let situation = phase.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].situations[k]); - } - } - } - - function processSituation(situation, node) { - - let highlightSituation = true - - for (let m = 0; m < situation.conditions.length; m++) { - if (currentRecord.conditionsValues[conditionIndex] === 1) { - node.conditions[m].payload.uiObject.highlight() - } else { - node.conditions[m].payload.uiObject.unHighlight() - highlightSituation = false - } - conditionIndex++; - } - - if (highlightSituation === true) { - node.payload.uiObject.highlight() - } else { - node.payload.uiObject.unHighlight() - } - } - - - browserCanvasContext.closePath(); - browserCanvasContext.fill(); - - } - - -} - - - - - - - - - - - diff --git a/Project.njsproj b/Project.njsproj index 13475abfd..15b8f293a 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -20,9 +20,6 @@ Code - - Code - Code diff --git a/this.plotter.config.json b/this.plotter.config.json index d8ea7453e..19447d29e 100644 --- a/this.plotter.config.json +++ b/this.plotter.config.json @@ -21,13 +21,7 @@ "moduleName": "Conditions", "description": "Plots Simulation Conditions.", "profilePicture": "Conditions.png", - "panels": [ - { - "codeName": "ConditionsPanel", - "moduleName": "ConditionsPanel", - "event": "Current Condition Record Changed" - } - ] + "panels": [] }, { "codeName": "Strategies", From 27f266275e1692257f2f1531a220120c777cc43f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 26 May 2019 10:05:20 +0200 Subject: [PATCH 060/157] Bug Fixed: showing at Designer area --- TradingSimulation.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/TradingSimulation.js b/TradingSimulation.js index 5eb0cb6bd..5ff1d1f65 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -611,6 +611,16 @@ recordPoint8 = viewPort.fitIntoVisibleArea(recordPoint8); recordPoint9 = viewPort.fitIntoVisibleArea(recordPoint9); + recordPoint1 = thisObject.fitFunction(recordPoint1); + recordPoint2 = thisObject.fitFunction(recordPoint2); + recordPoint3 = thisObject.fitFunction(recordPoint3); + recordPoint4 = thisObject.fitFunction(recordPoint4); + recordPoint5 = thisObject.fitFunction(recordPoint5); + recordPoint6 = thisObject.fitFunction(recordPoint6); + recordPoint7 = thisObject.fitFunction(recordPoint7); + recordPoint8 = thisObject.fitFunction(recordPoint8); + recordPoint9 = thisObject.fitFunction(recordPoint9); + /* Image representing a Record */ let imageOffset = { From 6ea5ad985cfb300ec8eb107bff865c4019bfdeec Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 26 May 2019 10:52:39 +0200 Subject: [PATCH 061/157] Bug Fixed, images leaking into strategy space --- TradingSimulation.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 5ff1d1f65..7ed739670 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -638,8 +638,15 @@ y: -2 + imageOffset.y } + let imagePosition = { + x: recordPoint1.x + imageOffset.x, + y: recordPoint1.y + imageOffset.y + } + + imagePosition = thisObject.fitFunction(imagePosition) + if (imageRecord.canDrawIcon === true) { - browserCanvasContext.drawImage(imageRecord, recordPoint1.x + imageOffset.x, recordPoint1.y + imageOffset.y, imageSize, imageSize); + browserCanvasContext.drawImage(imageRecord, imagePosition.x, imagePosition.y, imageSize, imageSize); browserCanvasContext.save(); browserCanvasContext.translate(recordPoint3.x + labelOffset.x, recordPoint3.y + labelOffset.y); browserCanvasContext.rotate(-Math.PI / 2); From 45b0c5a6ab6e15cbc3be54651c57d30809ff2994 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Jun 2019 09:24:40 +0200 Subject: [PATCH 062/157] Upgrade to Protocol v.0.1 --- Conditions.js | 174 +++++++++++++++++++++++++++++--------- TradingSimulation.js | 24 +++--- TradingSimulationPanel.js | 2 +- 3 files changed, 149 insertions(+), 51 deletions(-) diff --git a/Conditions.js b/Conditions.js index bb3ef5da1..ef237a4b6 100644 --- a/Conditions.js +++ b/Conditions.js @@ -334,7 +334,7 @@ record.strategyNumber = dailyFile[2][i][2]; record.strategyPhase = dailyFile[2][i][3]; record.stopLossPhase = dailyFile[2][i][4]; - record.buyOrderPhase = dailyFile[2][i][5]; + record.takeProfitPhase = dailyFile[2][i][5]; record.conditions = dailyFile[2][i][6]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -413,7 +413,7 @@ record.strategyNumber = marketFile[2][i][2]; record.strategyPhase = marketFile[2][i][3]; record.stopLossPhase = marketFile[2][i][4]; - record.buyOrderPhase = marketFile[2][i][5]; + record.takeProfitPhase = marketFile[2][i][5]; record.conditions = marketFile[2][i][6]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -492,7 +492,7 @@ strategyNumber: conditionRecord.strategyNumber, strategyPhase: conditionRecord.strategyPhase, stopLossPhase: conditionRecord.stopLossPhase, - buyOrderPhase: conditionRecord.buyOrderPhase, + takeProfitPhase: conditionRecord.takeProfitPhase, conditionsValues: conditionRecord.conditions }; @@ -514,12 +514,12 @@ browserCanvasContext.beginPath(); - let simulationLogic = currentRecord.conditionsNames; + let tradingSystem = currentRecord.conditionsNames; let conditionIndex = 0; - for (let j = 0; j < simulationLogic.strategies.length; j++) { + for (let j = 0; j < tradingSystem.strategies.length; j++) { - let strategy = simulationLogic.strategies[j]; + let strategy = tradingSystem.strategies[j]; if (currentRecord.strategyNumber - 1 === j) { canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = true @@ -527,55 +527,153 @@ canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = false } - for (let k = 0; k < strategy.entryPoint.situations.length; k++) { + let triggerStage = strategy.triggerStage - let situation = strategy.entryPoint.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].entryPoint.situations[k]); - } + if (triggerStage !== undefined) { - for (let k = 0; k < strategy.exitPoint.situations.length; k++) { + if (triggerStage.triggerOn !== undefined) { - let situation = strategy.exitPoint.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].exitPoint.situations[k]); - } + for (let k = 0; k < triggerStage.triggerOn.situations.length; k++) { - for (let k = 0; k < strategy.sellPoint.situations.length; k++) { + let situation = triggerStage.triggerOn.situations[k]; - let situation = strategy.sellPoint.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].sellPoint.situations[k]); - } - - for (let p = 0; p < strategy.stopLoss.phases.length; p++) { - - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].payload.uiObject.isExecuting = false + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k]); + } } - let phase = strategy.stopLoss.phases[p]; + if (triggerStage.triggerOff !== undefined) { - for (let k = 0; k < phase.situations.length; k++) { + for (let k = 0; k < triggerStage.triggerOff.situations.length; k++) { - let situation = phase.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].stopLoss.phases[p].situations[k]); + let situation = triggerStage.triggerOff.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k]); + } + } + + if (triggerStage.takePosition !== undefined) { + + for (let k = 0; k < triggerStage.takePosition.situations.length; k++) { + + let situation = triggerStage.takePosition.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.takePosition.situations[k]); + } } } - for (let p = 0; p < strategy.buyOrder.phases.length; p++) { + let openStage = strategy.openStage - if (currentRecord.strategyNumber - 1 === j && currentRecord.buyOrderPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].payload.uiObject.isExecuting = false + if (openStage !== undefined) { + + let initialDefinition = openStage.initialDefinition + + if (initialDefinition !== undefined) { + + if (initialDefinition.stopLoss !== undefined) { + + for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false + } + + let phase = initialDefinition.stopLoss.phases[p]; + + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { + + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + + let situation = nextPhaseEvent.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.situations[k]); + } + } + } + } + + if (initialDefinition.takeProfit !== undefined) { + + for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false + } + + let phase = initialDefinition.takeProfit.phases[p]; + + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { + + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + + let situation = nextPhaseEvent.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.situations[k]); + } + } + } + } + } + } + + let manageStage = strategy.manageStage + + if (manageStage !== undefined) { + + if (manageStage.stopLoss !== undefined) { + + for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 2 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false + } + + let phase = manageStage.stopLoss.phases[p]; + + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { + + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + + let situation = nextPhaseEvent.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.situations[k]); + } + } + } } - let phase = strategy.buyOrder.phases[p]; + if (manageStage.takeProfit !== undefined) { - for (let k = 0; k < phase.situations.length; k++) { + for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { - let situation = phase.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].buyOrder.phases[p].situations[k]); + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 2 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false + } + + let phase = manageStage.takeProfit.phases[p]; + + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { + + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + + let situation = nextPhaseEvent.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.situations[k]); + } + } + } } } } diff --git a/TradingSimulation.js b/TradingSimulation.js index 7ed739670..51160ee26 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -335,9 +335,9 @@ record.lastProfitPercent = dailyFile[i][19]; record.strategy = dailyFile[i][20]; record.strategyPhase = dailyFile[i][21]; - record.buyOrder = dailyFile[i][22]; + record.takeProfit = dailyFile[i][22]; record.stopLossPhase = dailyFile[i][23]; - record.buyOrderPhase = dailyFile[i][24]; + record.takeProfitPhase = dailyFile[i][24]; record.sellAmount = dailyFile[i][26]; // 25 is the message for the executor if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -425,9 +425,9 @@ record.lastProfitPercent = marketFile[i][19]; record.strategy = marketFile[i][20]; record.strategyPhase = marketFile[i][21]; - record.buyOrder = marketFile[i][22]; + record.takeProfit = marketFile[i][22]; record.stopLossPhase = marketFile[i][23]; - record.buyOrderPhase = marketFile[i][24]; + record.takeProfitPhase = marketFile[i][24]; record.sellAmount = marketFile[i][26]; // 25 is the message for the executor if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -506,15 +506,15 @@ } let stopLossPhase = 0; - let buyOrderPhase = 0; + let takeProfitPhase = 0; if (i > 0) { if (record.stopLossPhase !== records[i - 1].stopLossPhase) { stopLossPhase = record.stopLossPhase; } - if (record.buyOrderPhase !== records[i - 1].buyOrderPhase) { - buyOrderPhase = record.buyOrderPhase; + if (record.takeProfitPhase !== records[i - 1].takeProfitPhase) { + takeProfitPhase = record.takeProfitPhase; } } @@ -567,15 +567,15 @@ let recordPoint8 = { x: record.begin, - y: record.buyOrder + y: record.takeProfit }; let recordPoint9 = { x: record.end, - y: record.buyOrder + y: record.takeProfit }; - if (record.buyOrder === 0) { // Put these points out of range if buyOrder is zero. + if (record.takeProfit === 0) { // Put these points out of range if takeProfit is zero. recordPoint8.x = 0; recordPoint9.x = 0; @@ -739,9 +739,9 @@ browserCanvasContext.lineWidth = 5 browserCanvasContext.stroke() - if (imageBuyOrderPhase.canDrawIcon === true && buyOrderPhase > 0) { + if (imageBuyOrderPhase.canDrawIcon === true && takeProfitPhase > 0) { browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4, imageSize, imageSize); - printLabel(buyOrderPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.9', 8); + printLabel(takeProfitPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.9', 8); } } diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index d40ab75e0..3d433b574 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -131,7 +131,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.buyOrder, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); From 488767e0eaeedb69031ed9a5cbc38c3813ef421e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 8 Jun 2019 12:15:12 +0200 Subject: [PATCH 063/157] Error Messages --- Conditions.js | 398 +++++++++++++++++++++++++++----------------------- 1 file changed, 214 insertions(+), 184 deletions(-) diff --git a/Conditions.js b/Conditions.js index ef237a4b6..3e09c92ec 100644 --- a/Conditions.js +++ b/Conditions.js @@ -308,8 +308,8 @@ let currentDate = new Date(farLeftDate.valueOf()); conditions = []; - - + + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { @@ -479,12 +479,12 @@ let conditionRecord; - for (let i = 0; i < conditions.length; i++) { + for (let i = 0; i < conditions.length; i++) { conditionRecord = conditions[i]; /* Send the current record to the panel */ - + if (userPositionDate >= conditionRecord.begin && userPositionDate <= conditionRecord.end) { let currentRecord = { @@ -495,7 +495,7 @@ takeProfitPhase: conditionRecord.takeProfitPhase, conditionsValues: conditionRecord.conditions }; - + sendRecordInfoToStrategySpace(currentRecord) } } @@ -512,197 +512,226 @@ if (currentRecord.conditionsNames === undefined) { return; } if (canvas.strategySpace.workspace === undefined) { return; } - browserCanvasContext.beginPath(); + try { - let tradingSystem = currentRecord.conditionsNames; - let conditionIndex = 0; + browserCanvasContext.beginPath(); - for (let j = 0; j < tradingSystem.strategies.length; j++) { + let tradingSystem = currentRecord.conditionsNames; + let conditionIndex = 0; - let strategy = tradingSystem.strategies[j]; + canvas.strategySpace.workspace.tradingSystem.payload.uiObject.setErrorMessage(tradingSystem.error) - if (currentRecord.strategyNumber - 1 === j) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = false - } + for (let j = 0; j < tradingSystem.strategies.length; j++) { - let triggerStage = strategy.triggerStage + let strategy = tradingSystem.strategies[j]; + canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.setErrorMessage(strategy.error) - if (triggerStage !== undefined) { - - if (triggerStage.triggerOn !== undefined) { - - for (let k = 0; k < triggerStage.triggerOn.situations.length; k++) { - - let situation = triggerStage.triggerOn.situations[k]; - - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k]); - } - } - - if (triggerStage.triggerOff !== undefined) { - - for (let k = 0; k < triggerStage.triggerOff.situations.length; k++) { - - let situation = triggerStage.triggerOff.situations[k]; - - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k]); - } - } - - if (triggerStage.takePosition !== undefined) { - - for (let k = 0; k < triggerStage.takePosition.situations.length; k++) { - - let situation = triggerStage.takePosition.situations[k]; - - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.takePosition.situations[k]); - } - } - } - - let openStage = strategy.openStage - - if (openStage !== undefined) { - - let initialDefinition = openStage.initialDefinition - - if (initialDefinition !== undefined) { - - if (initialDefinition.stopLoss !== undefined) { - - for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { - - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false - } - - let phase = initialDefinition.stopLoss.phases[p]; - - let nextPhaseEvent = phase.nextPhaseEvent; - if (nextPhaseEvent !== undefined) { - - for (let k = 0; k < nextPhaseEvent.situations.length; k++) { - - let situation = nextPhaseEvent.situations[k]; - - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.situations[k]); - } - } - } - } - - if (initialDefinition.takeProfit !== undefined) { - - for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { - - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false - } - - let phase = initialDefinition.takeProfit.phases[p]; - - let nextPhaseEvent = phase.nextPhaseEvent; - if (nextPhaseEvent !== undefined) { - - for (let k = 0; k < nextPhaseEvent.situations.length; k++) { - - let situation = nextPhaseEvent.situations[k]; - - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.situations[k]); - } - } - } - } - } - } - - let manageStage = strategy.manageStage - - if (manageStage !== undefined) { - - if (manageStage.stopLoss !== undefined) { - - for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { - - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 2 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false - } - - let phase = manageStage.stopLoss.phases[p]; - - let nextPhaseEvent = phase.nextPhaseEvent; - if (nextPhaseEvent !== undefined) { - - for (let k = 0; k < nextPhaseEvent.situations.length; k++) { - - let situation = nextPhaseEvent.situations[k]; - - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.situations[k]); - } - } - } - } - - if (manageStage.takeProfit !== undefined) { - - for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { - - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 2 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true - } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false - } - - let phase = manageStage.takeProfit.phases[p]; - - let nextPhaseEvent = phase.nextPhaseEvent; - if (nextPhaseEvent !== undefined) { - - for (let k = 0; k < nextPhaseEvent.situations.length; k++) { - - let situation = nextPhaseEvent.situations[k]; - - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.situations[k]); - } - } - } - } - } - } - - function processSituation(situation, node) { - - let highlightSituation = true - - for (let m = 0; m < situation.conditions.length; m++) { - if (currentRecord.conditionsValues[conditionIndex] === 1) { - node.conditions[m].payload.uiObject.highlight() + if (currentRecord.strategyNumber - 1 === j) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = true } else { - node.conditions[m].payload.uiObject.unHighlight() - highlightSituation = false + canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = false + } + + let triggerStage = strategy.triggerStage + + if (triggerStage !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.payload.uiObject.setErrorMessage(triggerStage.error) + + if (triggerStage.triggerOn !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOn.payload.uiObject.setErrorMessage(triggerStage.triggerOn.error) + + for (let k = 0; k < triggerStage.triggerOn.situations.length; k++) { + + let situation = triggerStage.triggerOn.situations[k]; + canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOn.situations[k].error) + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k]); + } + } + + if (triggerStage.triggerOff !== undefined) { + + for (let k = 0; k < triggerStage.triggerOff.situations.length; k++) { + + let situation = triggerStage.triggerOff.situations[k]; + canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOff.situations[k].error) + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k]); + } + } + + if (triggerStage.takePosition !== undefined) { + + for (let k = 0; k < triggerStage.takePosition.situations.length; k++) { + + let situation = triggerStage.takePosition.situations[k]; + canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.takePosition.situations[k].payload.uiObject.setErrorMessage(triggerStage.takePosition.situations[k].error) + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.takePosition.situations[k]); + } + } + } + + let openStage = strategy.openStage + + if (openStage !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.payload.uiObject.setErrorMessage(openStage.error) + + let initialDefinition = openStage.initialDefinition + + if (initialDefinition !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.payload.uiObject.setErrorMessage(openStage.initialDefinition.error) + + if (initialDefinition.stopLoss !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.error) + + for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false + } + + let phase = initialDefinition.stopLoss.phases[p]; + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].error) + + + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.error) + + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + + let situation = nextPhaseEvent.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.situations[k]); + } + } + } + } + + if (initialDefinition.takeProfit !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.error) + + for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false + } + + let phase = initialDefinition.takeProfit.phases[p]; + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].error) + + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.error) + + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + + let situation = nextPhaseEvent.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.situations[k]); + } + } + } + } + } + } + + let manageStage = strategy.manageStage + + if (manageStage !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.payload.uiObject.setErrorMessage(manageStage.error) + + if (manageStage.stopLoss !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.payload.uiObject.setErrorMessage(manageStage.stopLoss.error) + + for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 2 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false + } + + let phase = manageStage.stopLoss.phases[p]; + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].error) + + + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].nextPhaseEvent.error) + + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + + let situation = nextPhaseEvent.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.situations[k]); + } + } + } + } + + if (manageStage.takeProfit !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.payload.uiObject.setErrorMessage(manageStage.takeProfit.error) + + for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { + + if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 2 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true + } else { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false + } + + let phase = manageStage.takeProfit.phases[p]; + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].error) + + let nextPhaseEvent = phase.nextPhaseEvent; + if (nextPhaseEvent !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].nextPhaseEvent.error) + + for (let k = 0; k < nextPhaseEvent.situations.length; k++) { + + let situation = nextPhaseEvent.situations[k]; + + processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.situations[k]); + } + } + } + } } - conditionIndex++; } - if (highlightSituation === true) { - node.payload.uiObject.highlight() - } else { - node.payload.uiObject.unHighlight() + function processSituation(situation, node) { + + node.payload.uiObject.setErrorMessage(situation.error) + + let highlightSituation = true + + for (let m = 0; m < situation.conditions.length; m++) { + + node.conditions[m].payload.uiObject.setErrorMessage(situation.conditions[m].error) + + if (currentRecord.conditionsValues[conditionIndex] === 1) { + node.conditions[m].payload.uiObject.highlight() + } else { + highlightSituation = false + } + conditionIndex++; + } + + if (highlightSituation === true) { + node.payload.uiObject.highlight() + } } + + + browserCanvasContext.closePath(); + browserCanvasContext.fill(); + + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] sendRecordInfoToStrategySpace -> err = " + err.stack); } } - - - browserCanvasContext.closePath(); - browserCanvasContext.fill(); - } @@ -769,3 +798,4 @@ + From 3651c615faa1687e0eb56f3db66111a3b65584bb Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 8 Jun 2019 15:20:10 +0200 Subject: [PATCH 064/157] errorMessage --- Conditions.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Conditions.js b/Conditions.js index 3e09c92ec..c9f83be94 100644 --- a/Conditions.js +++ b/Conditions.js @@ -521,6 +521,16 @@ canvas.strategySpace.workspace.tradingSystem.payload.uiObject.setErrorMessage(tradingSystem.error) + if (tradingSystem.parameters !== undefined) { + canvas.strategySpace.workspace.tradingSystem.parameters.payload.uiObject.setErrorMessage(tradingSystem.parameters.error) + if (tradingSystem.parameters.baseAsset !== undefined) { + canvas.strategySpace.workspace.tradingSystem.parameters.baseAsset.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.error) + if (tradingSystem.parameters.baseAsset.formula !== undefined) { + canvas.strategySpace.workspace.tradingSystem.parameters.baseAsset.formula.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.formula.error) + } + } + } + for (let j = 0; j < tradingSystem.strategies.length; j++) { let strategy = tradingSystem.strategies[j]; @@ -593,6 +603,9 @@ let phase = initialDefinition.stopLoss.phases[p]; canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].error) + if (phase.formula !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) + } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { @@ -622,6 +635,10 @@ let phase = initialDefinition.takeProfit.phases[p]; canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].error) + if (phase.formula !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) + } + let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.error) @@ -657,6 +674,9 @@ let phase = manageStage.stopLoss.phases[p]; canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].error) + if (phase.formula !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) + } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { @@ -686,6 +706,10 @@ let phase = manageStage.takeProfit.phases[p]; canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].error) + if (phase.formula !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) + } + let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].nextPhaseEvent.error) @@ -712,6 +736,10 @@ node.conditions[m].payload.uiObject.setErrorMessage(situation.conditions[m].error) + if (situation.conditions[m].code !== undefined) { + node.conditions[m].code.payload.uiObject.setErrorMessage(situation.conditions[m].code.error) + } + if (currentRecord.conditionsValues[conditionIndex] === 1) { node.conditions[m].payload.uiObject.highlight() } else { From c4355e77bf395721824d9277e21127004cd73baa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 8 Jun 2019 17:59:21 +0200 Subject: [PATCH 065/157] Working with error messages --- Conditions.js | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/Conditions.js b/Conditions.js index c9f83be94..8118ed5f2 100644 --- a/Conditions.js +++ b/Conditions.js @@ -336,6 +336,8 @@ record.stopLossPhase = dailyFile[2][i][4]; record.takeProfitPhase = dailyFile[2][i][5]; record.conditions = dailyFile[2][i][6]; + record.formulaErrors = dailyFile[2][i][7]; + record.formulaValues = dailyFile[2][i][8]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -415,6 +417,8 @@ record.stopLossPhase = marketFile[2][i][4]; record.takeProfitPhase = marketFile[2][i][5]; record.conditions = marketFile[2][i][6]; + record.formulaErrors = marketFile[2][i][7]; + record.formulaValues = marketFile[2][i][8]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -493,7 +497,9 @@ strategyPhase: conditionRecord.strategyPhase, stopLossPhase: conditionRecord.stopLossPhase, takeProfitPhase: conditionRecord.takeProfitPhase, - conditionsValues: conditionRecord.conditions + conditionsValues: conditionRecord.conditions, + formulaErrors: conditionRecord.formulaErrors, + formulaValues: conditionRecord.formulaValues }; sendRecordInfoToStrategySpace(currentRecord) @@ -518,6 +524,8 @@ let tradingSystem = currentRecord.conditionsNames; let conditionIndex = 0; + let formulaErrorsIndex = 0; + let formulaValuesIndex = 0; canvas.strategySpace.workspace.tradingSystem.payload.uiObject.setErrorMessage(tradingSystem.error) @@ -536,7 +544,7 @@ let strategy = tradingSystem.strategies[j]; canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.setErrorMessage(strategy.error) - if (currentRecord.strategyNumber - 1 === j) { + if (currentRecord.strategyNumber === j) { canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = true } else { canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = false @@ -594,7 +602,7 @@ for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -605,6 +613,13 @@ if (phase.formula !== undefined) { canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) + + if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + } + } + formulaErrorsIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; @@ -626,7 +641,7 @@ for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 1 === p) { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -637,6 +652,13 @@ if (phase.formula !== undefined) { canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) + + if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + } + } + formulaErrorsIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; @@ -665,7 +687,7 @@ for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 2 === p) { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -676,6 +698,13 @@ if (phase.formula !== undefined) { canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) + + if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + } + } + formulaErrorsIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; @@ -697,7 +726,7 @@ for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { - if (currentRecord.strategyNumber - 1 === j && currentRecord.stopLossPhase - 2 === p) { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -708,6 +737,13 @@ if (phase.formula !== undefined) { canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) + + if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + } + } + formulaErrorsIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; @@ -827,3 +863,5 @@ + + From 260eb9564b98c2798f6274e89157cf91def98ae5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Jun 2019 09:20:48 +0200 Subject: [PATCH 066/157] Formula Values Working --- Conditions.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Conditions.js b/Conditions.js index 8118ed5f2..328d72ccb 100644 --- a/Conditions.js +++ b/Conditions.js @@ -620,6 +620,11 @@ } } formulaErrorsIndex++ + + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + } + formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; @@ -659,6 +664,11 @@ } } formulaErrorsIndex++ + + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + } + formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; @@ -705,6 +715,10 @@ } } formulaErrorsIndex++ + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + } + formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; @@ -744,6 +758,11 @@ } } formulaErrorsIndex++ + + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + } + formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; @@ -864,4 +883,5 @@ + From 75bb5813e32fcc77088950bd522809e0ca67a19a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Jun 2019 16:21:43 +0200 Subject: [PATCH 067/157] maximunBalance --- TradingSimulation.js | 16 ++++++++++++++-- TradingSimulationPanel.js | 15 ++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 51160ee26..0bd7bb4f2 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -338,7 +338,13 @@ record.takeProfit = dailyFile[i][22]; record.stopLossPhase = dailyFile[i][23]; record.takeProfitPhase = dailyFile[i][24]; - record.sellAmount = dailyFile[i][26]; // 25 is the message for the executor + record.positionSize = dailyFile[i][26]; // 25 is the message for the executor + record.initialBalanceA = dailyFile[i][27]; + record.minimunBalanceA = dailyFile[i][28]; + record.maximunBalanceA = dailyFile[i][29]; + record.initialBalanceB = dailyFile[i][30]; + record.minimunBalanceB = dailyFile[i][31]; + record.maximunBalanceB = dailyFile[i][32]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -428,7 +434,13 @@ record.takeProfit = marketFile[i][22]; record.stopLossPhase = marketFile[i][23]; record.takeProfitPhase = marketFile[i][24]; - record.sellAmount = marketFile[i][26]; // 25 is the message for the executor + record.positionSize = marketFile[i][26]; // 25 is the message for the executor + record.initialBalanceA = marketFile[i][27]; + record.minimunBalanceA = marketFile[i][28]; + record.maximunBalanceA = marketFile[i][29]; + record.initialBalanceB = marketFile[i][30]; + record.minimunBalanceB = marketFile[i][31]; + record.maximunBalanceB = marketFile[i][32]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 3d433b574..87f1b3649 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -20,7 +20,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let currentRecord; let panelTabButton - + return thisObject; @@ -208,9 +208,9 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation params = {} params.VALUE = currentRecord.innerRecord.balanceA; - params.INIT_VALUE = 1 - params.MIN_VALUE = 0.5 - params.MAX_VALUE = 2 + params.INIT_VALUE = currentRecord.innerRecord.initialBalanceA + params.MIN_VALUE = currentRecord.innerRecord.minimunBalanceA + params.MAX_VALUE = currentRecord.innerRecord.maximunBalanceA params.ASSET_LABEL = 'Asset A' params.ASSET_NAME = DEFAULT_MARKET.assetB + ' ' params.LEFT_OFFSET = 100 @@ -219,9 +219,9 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation params = {} params.VALUE = currentRecord.innerRecord.balanceB; - params.MIN_VALUE = 0 - params.INIT_VALUE = currentRecord.innerRecord.rate * currentRecord.innerRecord.sellAmount; - params.MAX_VALUE = params.INIT_VALUE * 2; + params.MIN_VALUE = currentRecord.innerRecord.minimunBalanceB + params.INIT_VALUE = currentRecord.innerRecord.initialBalanceB + params.MAX_VALUE = currentRecord.innerRecord.maximunBalanceB params.ASSET_LABEL = 'Asset B' params.ASSET_NAME = DEFAULT_MARKET.assetA + ' ' params.LEFT_OFFSET = 220 @@ -249,3 +249,4 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + From 2c5c859ad28050024358223cf7d4a726f9527f1d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 25 Jun 2019 00:47:50 +0200 Subject: [PATCH 068/157] Improvement on positioning images of phases --- TradingSimulation.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 0bd7bb4f2..bfae38fd2 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -189,10 +189,10 @@ if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - marketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimePeriod); + + recalculate(); - recalculate(); - } else { let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); @@ -670,7 +670,7 @@ continue; } - /* Next we are drawing the sellRate */ + /* Next we are drawing the position Rate */ browserCanvasContext.beginPath(); @@ -697,8 +697,12 @@ imageSize = 20; let imageToDraw; - /* Next we are drawing the stopLoss floor / ceilling */ + /* Depending on what is on top, it is also the text and image of the take profit / stop loss */ + let yOffset = 0 + if (record.takeProfit > record.stopLoss) { yOffset = imageSize * 2 } + + /* Next we are drawing the stopLoss floor / ceilling */ browserCanvasContext.beginPath(); @@ -724,12 +728,11 @@ if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > 0) { - browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize * 1.25, imageSize, imageSize); - printLabel(stopLossPhase, recordPoint5.x - imageSize / 2 - 3, recordPoint5.y - imageSize * 1.5, '0.9', 8); + browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize * 1.25 + yOffset, imageSize, imageSize); + printLabel(stopLossPhase, recordPoint5.x - imageSize / 2 - 3, recordPoint5.y - imageSize * 1.5 + yOffset * 2, '0.9', 8); } - /* Next we are drawing the Buy Order */ - + /* Next we are drawing the Take Profit */ browserCanvasContext.beginPath(); @@ -752,8 +755,8 @@ browserCanvasContext.stroke() if (imageBuyOrderPhase.canDrawIcon === true && takeProfitPhase > 0) { - browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4, imageSize, imageSize); - printLabel(takeProfitPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9, '0.9', 8); + browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4 - yOffset, imageSize, imageSize); + printLabel(takeProfitPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9 - yOffset * 2, '0.9', 8); } } @@ -834,5 +837,6 @@ + From 87f1745391bbaa4eef83a84fcba73f17b469f648 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 25 Jun 2019 00:55:39 +0200 Subject: [PATCH 069/157] Icon for take profit equal to the one used at the designer --- TradingSimulation.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index bfae38fd2..11e24cdff 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -50,7 +50,7 @@ let records = []; // Here we keep the records to be ploted every time the Draw() function is called by the AAWebPlatform. let imageStopLossPhase; - let imageBuyOrderPhase; + let imageTakeProfitPhase; let imageRecord; let zoomChangedEventSubscriptionId @@ -75,7 +75,7 @@ /* icons */ imageStopLossPhase = undefined; - imageBuyOrderPhase = undefined; + imageTakeProfitPhase = undefined; imageRecord = undefined; /* Destroy References */ @@ -139,7 +139,7 @@ /* Loading a few icons */ imageStopLossPhase = canvas.strategySpace.iconByPartType.get('Stop'); - imageBuyOrderPhase = canvas.strategySpace.iconByPartType.get('Phase'); + imageTakeProfitPhase = canvas.strategySpace.iconByPartType.get('Take Profit'); imageRecord = canvas.strategySpace.iconByPartType.get('Trading System'); callBackFunction(); @@ -754,8 +754,8 @@ browserCanvasContext.lineWidth = 5 browserCanvasContext.stroke() - if (imageBuyOrderPhase.canDrawIcon === true && takeProfitPhase > 0) { - browserCanvasContext.drawImage(imageBuyOrderPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4 - yOffset, imageSize, imageSize); + if (imageTakeProfitPhase.canDrawIcon === true && takeProfitPhase > 0) { + browserCanvasContext.drawImage(imageTakeProfitPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4 - yOffset, imageSize, imageSize); printLabel(takeProfitPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9 - yOffset * 2, '0.9', 8); } From e6d09863ee6149dbb705bb58fb208e6105a3a079 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 27 Jun 2019 01:15:06 +0200 Subject: [PATCH 070/157] Usability improvements --- Strategies.js | 4 +++- Trades.js | 6 ++++-- TradingSimulation.js | 9 +++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Strategies.js b/Strategies.js index 1f52a9890..6658032b9 100644 --- a/Strategies.js +++ b/Strategies.js @@ -548,6 +548,7 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; browserCanvasContext.lineWidth = 1 + browserCanvasContext.setLineDash([0, 0]) browserCanvasContext.stroke() } @@ -589,7 +590,7 @@ } browserCanvasContext.setLineDash([4, 3]) - browserCanvasContext.lineWidth = 0.2 + browserCanvasContext.lineWidth = 0.5 browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) @@ -667,3 +668,4 @@ + diff --git a/Trades.js b/Trades.js index b048272af..b3254a036 100644 --- a/Trades.js +++ b/Trades.js @@ -570,6 +570,7 @@ browserCanvasContext.fill(); browserCanvasContext.lineWidth = 1; + browserCanvasContext.setLineDash([0, 0]) browserCanvasContext.stroke(); if ( @@ -585,8 +586,8 @@ } else { - printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint4.y - 30, '0.50', 12); - printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint4.y - 15, '0.50', 12); + printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint4.y - 30, '1', 12); + printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint4.y - 15, '1', 12); } @@ -663,3 +664,4 @@ + diff --git a/TradingSimulation.js b/TradingSimulation.js index 11e24cdff..939964faf 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -139,7 +139,7 @@ /* Loading a few icons */ imageStopLossPhase = canvas.strategySpace.iconByPartType.get('Stop'); - imageTakeProfitPhase = canvas.strategySpace.iconByPartType.get('Take Profit'); + imageTakeProfitPhase = canvas.strategySpace.iconByPartType.get('Phase'); imageRecord = canvas.strategySpace.iconByPartType.get('Trading System'); callBackFunction(); @@ -662,7 +662,7 @@ browserCanvasContext.save(); browserCanvasContext.translate(recordPoint3.x + labelOffset.x, recordPoint3.y + labelOffset.y); browserCanvasContext.rotate(-Math.PI / 2); - printLabel(recordLabel, 0, 0, '0.9', 8); + printLabel(recordLabel, 0, 0, '1', 8); browserCanvasContext.restore(); } @@ -729,7 +729,7 @@ if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > 0) { browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize * 1.25 + yOffset, imageSize, imageSize); - printLabel(stopLossPhase, recordPoint5.x - imageSize / 2 - 3, recordPoint5.y - imageSize * 1.5 + yOffset * 2, '0.9', 8); + printLabel(stopLossPhase - 1, recordPoint5.x - imageSize / 2 - 3, recordPoint5.y - imageSize * 1.5 + yOffset * 2, '1', 9); } /* Next we are drawing the Take Profit */ @@ -756,7 +756,7 @@ if (imageTakeProfitPhase.canDrawIcon === true && takeProfitPhase > 0) { browserCanvasContext.drawImage(imageTakeProfitPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4 - yOffset, imageSize, imageSize); - printLabel(takeProfitPhase, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9 - yOffset * 2, '0.9', 8); + printLabel(takeProfitPhase - 1, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9 - yOffset * 2, '1', 9); } } @@ -838,5 +838,6 @@ + From 0ad904d230ae9ea1d31e189c86861a8246bfb74b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 27 Jun 2019 17:25:09 +0200 Subject: [PATCH 071/157] BUG FIXED: When condition is undefined --- Conditions.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Conditions.js b/Conditions.js index 328d72ccb..8d9d01eef 100644 --- a/Conditions.js +++ b/Conditions.js @@ -789,18 +789,23 @@ for (let m = 0; m < situation.conditions.length; m++) { - node.conditions[m].payload.uiObject.setErrorMessage(situation.conditions[m].error) + let condition = node.conditions[m] + if (condition !== undefined) { + condition.payload.uiObject.setErrorMessage(situation.conditions[m].error) - if (situation.conditions[m].code !== undefined) { - node.conditions[m].code.payload.uiObject.setErrorMessage(situation.conditions[m].code.error) - } + if (situation.conditions[m].code !== undefined) { + if (condition.code !== undefined) { + condition.code.payload.uiObject.setErrorMessage(situation.conditions[m].code.error) + } + } - if (currentRecord.conditionsValues[conditionIndex] === 1) { - node.conditions[m].payload.uiObject.highlight() - } else { - highlightSituation = false - } - conditionIndex++; + if (currentRecord.conditionsValues[conditionIndex] === 1) { + condition.payload.uiObject.highlight() + } else { + highlightSituation = false + } + conditionIndex++; + } } if (highlightSituation === true) { From 9bc95ec0a969f64cdbd7fcb76fec8443f6a10127 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 28 Jun 2019 15:22:19 +0200 Subject: [PATCH 072/157] Multiple Improvements --- Trades.js | 12 +++--- TradingSimulation.js | 77 ++++++++++++++++++++++----------------- TradingSimulationPanel.js | 38 ++++++++++++++----- 3 files changed, 78 insertions(+), 49 deletions(-) diff --git a/Trades.js b/Trades.js index b3254a036..e65132540 100644 --- a/Trades.js +++ b/Trades.js @@ -326,7 +326,7 @@ record.begin = dailyFile[i][0]; record.end = dailyFile[i][1]; record.status = dailyFile[i][2]; - record.lastProfitPercent = dailyFile[i][3]; + record.lastTradeROI = dailyFile[i][3]; record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; record.exitType = dailyFile[i][6]; @@ -400,7 +400,7 @@ record.begin = marketFile[i][0]; record.end = marketFile[i][1]; record.status = marketFile[i][2]; - record.lastProfitPercent = marketFile[i][3]; + record.lastTradeROI = marketFile[i][3]; record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; record.exitType = marketFile[i][6]; @@ -534,13 +534,13 @@ } } - if (record.lastProfitPercent < 0) { + if (record.lastTradeROI < 0) { - line2 = (record.lastProfitPercent).toFixed(2) + ' %'; + line2 = (record.lastTradeROI).toFixed(2) + ' %'; } else { - line2 = (record.lastProfitPercent).toFixed(2) + ' %'; + line2 = (record.lastTradeROI).toFixed(2) + ' %'; } /* Draw the triangle that represents the trade. */ @@ -555,7 +555,7 @@ let opacity = '0.25'; - if (record.lastProfitPercent > 0) { + if (record.lastTradeROI > 0) { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')'; } else { diff --git a/TradingSimulation.js b/TradingSimulation.js index 939964faf..d38ff02c5 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -321,7 +321,7 @@ record.balanceA = dailyFile[i][5]; record.balanceB = dailyFile[i][6]; record.profit = dailyFile[i][7]; - record.lastProfit = dailyFile[i][8]; + record.lastTradeProfitLoss = dailyFile[i][8]; record.stopLoss = dailyFile[i][9]; record.roundtrips = dailyFile[i][10]; record.hits = dailyFile[i][11]; @@ -332,7 +332,7 @@ record.days = dailyFile[i][16]; record.anualizedRateOfReturn = dailyFile[i][17]; record.sellRate = dailyFile[i][18]; - record.lastProfitPercent = dailyFile[i][19]; + record.lastTradeROI = dailyFile[i][19]; record.strategy = dailyFile[i][20]; record.strategyPhase = dailyFile[i][21]; record.takeProfit = dailyFile[i][22]; @@ -417,7 +417,7 @@ record.balanceA = marketFile[i][5]; record.balanceB = marketFile[i][6]; record.profit = marketFile[i][7]; - record.lastProfit = marketFile[i][8]; + record.lastTradeProfitLoss = marketFile[i][8]; record.stopLoss = marketFile[i][9]; record.roundtrips = marketFile[i][10]; record.hits = marketFile[i][11]; @@ -428,7 +428,7 @@ record.days = marketFile[i][16]; record.anualizedRateOfReturn = marketFile[i][17]; record.sellRate = marketFile[i][18]; - record.lastProfitPercent = marketFile[i][19]; + record.lastTradeROI = marketFile[i][19]; record.strategy = marketFile[i][20]; record.strategyPhase = marketFile[i][21]; record.takeProfit = marketFile[i][22]; @@ -542,55 +542,60 @@ let recordPoint3 = { x: recordPoint1.x + (recordPoint2.x - recordPoint1.x) / 2, - y: thisObject.container.frame.height + y: 0 }; let recordPoint4 = { + x: record.begin + timePeriod / 7 * 1.5, + y: thisObject.container.frame.height * 3 + }; + + let recordPoint5 = { x: record.begin, y: record.stopLoss }; - let recordPoint5 = { + let recordPoint6 = { x: record.end, y: record.stopLoss }; if (record.stopLoss === 0) { // Put these points out of range if stopLoss is zero. - recordPoint4.x = 0; recordPoint5.x = 0; + recordPoint6.x = 0; } - let recordPoint6 = { + let recordPoint7 = { x: record.begin, y: record.sellRate }; - let recordPoint7 = { + let recordPoint8 = { x: record.end, y: record.sellRate }; if (record.sellRate === 0) { // Put these points out of range if sellRate is zero. - recordPoint6.x = 0; recordPoint7.x = 0; + recordPoint8.x = 0; } - let recordPoint8 = { + let recordPoint9 = { x: record.begin, y: record.takeProfit }; - let recordPoint9 = { + let recordPoint10 = { x: record.end, y: record.takeProfit }; if (record.takeProfit === 0) { // Put these points out of range if takeProfit is zero. - recordPoint8.x = 0; recordPoint9.x = 0; + recordPoint10.x = 0; } recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); @@ -602,6 +607,7 @@ recordPoint7 = timeLineCoordinateSystem.transformThisPoint(recordPoint7); recordPoint8 = timeLineCoordinateSystem.transformThisPoint(recordPoint8); recordPoint9 = timeLineCoordinateSystem.transformThisPoint(recordPoint9); + recordPoint10 = timeLineCoordinateSystem.transformThisPoint(recordPoint10); recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); @@ -612,6 +618,7 @@ recordPoint7 = transformThisPoint(recordPoint7, thisObject.container); recordPoint8 = transformThisPoint(recordPoint8, thisObject.container); recordPoint9 = transformThisPoint(recordPoint9, thisObject.container); + recordPoint10 = transformThisPoint(recordPoint10, thisObject.container); recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); @@ -622,6 +629,7 @@ recordPoint7 = viewPort.fitIntoVisibleArea(recordPoint7); recordPoint8 = viewPort.fitIntoVisibleArea(recordPoint8); recordPoint9 = viewPort.fitIntoVisibleArea(recordPoint9); + recordPoint10 = viewPort.fitIntoVisibleArea(recordPoint10); recordPoint1 = thisObject.fitFunction(recordPoint1); recordPoint2 = thisObject.fitFunction(recordPoint2); @@ -632,12 +640,13 @@ recordPoint7 = thisObject.fitFunction(recordPoint7); recordPoint8 = thisObject.fitFunction(recordPoint8); recordPoint9 = thisObject.fitFunction(recordPoint9); + recordPoint10 = thisObject.fitFunction(recordPoint10); /* Image representing a Record */ let imageOffset = { x: 0, - y: 30 + y: -30 } let imageSize = (recordPoint2.x - recordPoint1.x) / 2; let recordLabel = record.periods.toLocaleString() @@ -647,12 +656,12 @@ } let labelOffset = { x: 0 - imageSize / 2 + 3 + imageOffset.x, - y: -2 + imageOffset.y + y: -2 - imageOffset.y } let imagePosition = { - x: recordPoint1.x + imageOffset.x, - y: recordPoint1.y + imageOffset.y + x: recordPoint4.x + imageOffset.x, + y: recordPoint4.y + imageOffset.y } imagePosition = thisObject.fitFunction(imagePosition) @@ -666,7 +675,7 @@ browserCanvasContext.restore(); } - if (recordPoint4.x < viewPort.visibleArea.bottomLeft.x || recordPoint4.x > viewPort.visibleArea.bottomRight.x) { + if (recordPoint5.x < viewPort.visibleArea.bottomLeft.x || recordPoint5.x > viewPort.visibleArea.bottomRight.x) { continue; } @@ -674,8 +683,8 @@ browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint6.x, recordPoint6.y); - browserCanvasContext.lineTo(recordPoint7.x, recordPoint7.y); + browserCanvasContext.moveTo(recordPoint7.x, recordPoint7.y); + browserCanvasContext.lineTo(recordPoint8.x, recordPoint8.y); browserCanvasContext.closePath(); @@ -707,13 +716,13 @@ browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint4.x, recordPoint4.y); - browserCanvasContext.lineTo(recordPoint5.x, recordPoint5.y); + browserCanvasContext.moveTo(recordPoint5.x, recordPoint5.y); + browserCanvasContext.lineTo(recordPoint6.x, recordPoint6.y); browserCanvasContext.closePath(); - let opacity = 0.8 + let opacity = 1 browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ''; @@ -723,25 +732,25 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } - browserCanvasContext.lineWidth = 5 + browserCanvasContext.lineWidth = 1 browserCanvasContext.stroke() if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > 0) { - browserCanvasContext.drawImage(imageStopLossPhase, recordPoint5.x - imageSize, recordPoint5.y - imageSize * 1.25 + yOffset, imageSize, imageSize); - printLabel(stopLossPhase - 1, recordPoint5.x - imageSize / 2 - 3, recordPoint5.y - imageSize * 1.5 + yOffset * 2, '1', 9); + browserCanvasContext.drawImage(imageStopLossPhase, recordPoint6.x - imageSize, recordPoint6.y - imageSize * 1.25 + yOffset, imageSize, imageSize); + printLabel(stopLossPhase - 1, recordPoint6.x - imageSize / 2 - 3, recordPoint6.y - imageSize * 1.5 + yOffset * 2, '1', 9); } /* Next we are drawing the Take Profit */ browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint8.x, recordPoint8.y); - browserCanvasContext.lineTo(recordPoint9.x, recordPoint9.y); + browserCanvasContext.moveTo(recordPoint9.x, recordPoint9.y); + browserCanvasContext.lineTo(recordPoint10.x, recordPoint10.y); browserCanvasContext.closePath(); - opacity = 0.6 + opacity = 1 browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ''; @@ -751,17 +760,15 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } - browserCanvasContext.lineWidth = 5 + browserCanvasContext.lineWidth = 1 browserCanvasContext.stroke() if (imageTakeProfitPhase.canDrawIcon === true && takeProfitPhase > 0) { - browserCanvasContext.drawImage(imageTakeProfitPhase, recordPoint9.x - imageSize * 2 / 3, recordPoint9.y + imageSize / 4 - yOffset, imageSize, imageSize); - printLabel(takeProfitPhase - 1, recordPoint9.x - imageSize * 1 / 3, recordPoint9.y + imageSize * 1.9 - yOffset * 2, '1', 9); + browserCanvasContext.drawImage(imageTakeProfitPhase, recordPoint10.x - imageSize * 2 / 3, recordPoint10.y + imageSize / 4 - yOffset, imageSize, imageSize); + printLabel(takeProfitPhase - 1, recordPoint10.x - imageSize * 1 / 3, recordPoint10.y + imageSize * 1.9 - yOffset * 2, '1', 9); } - } - } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } @@ -838,6 +845,8 @@ + + diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 87f1b3649..dd3b53100 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -104,19 +104,13 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let increment = 0.025; y = y + increment; - printLabel('Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel('Current Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 12); y = y + increment; - printLabel('Last Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; - printLabel(currentRecord.innerRecord.lastProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); - - y = y + increment; - printLabel('Last Profit %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); - y = y + increment; - printLabel((currentRecord.innerRecord.lastProfitPercent).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); y = y + increment; printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); @@ -133,6 +127,31 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel(currentRecord.innerRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + + y = y + increment; + y = y + increment; + printLabel('Latest Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 12); + + y = y + increment; + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.lastTradeProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + + y = y + increment; + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel((currentRecord.innerRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + + + y = y + increment; + y = y + increment; + printLabel('Totals Accumulated', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 12); + + y = y + increment; + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + y = y + increment; + printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + y = y + increment; printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); y = y + increment; @@ -250,3 +269,4 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + From b2aea8bbcaf1ebe4e2f21ec7225e299ea9fd6ada Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 28 Jun 2019 15:58:55 +0200 Subject: [PATCH 073/157] New Format with Saira --- TradingSimulationPanel.js | 71 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index dd3b53100..549ba318f 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -101,103 +101,103 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation browserCanvasContext.beginPath(); let y = 0; - let increment = 0.025; + let increment = 0.027; y = y + increment; y = y + increment; - printLabel('Current Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 12); + printLabel('Current Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', 12); y = y + increment; - printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; y = y + increment; - printLabel('Latest Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 12); + printLabel('Latest Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', 12); y = y + increment; - printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.lastTradeProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.lastTradeProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.innerRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel((currentRecord.innerRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; y = y + increment; - printLabel('Totals Accumulated', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 12); + printLabel('Totals Accumulated', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', 12); y = y + increment; - printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1'); + printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.50', 10); + printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); function printLabel(labelToPrint, x, y, opacity, fontSize) { let labelPoint; if (fontSize === undefined) { fontSize = 10 }; - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY; let label = '' + labelToPrint; if (isNaN(label) === false) { @@ -269,4 +269,5 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + From 690acc2275e4d5dbc5363de3797795ae3d330f0a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 30 Jun 2019 11:56:49 +0200 Subject: [PATCH 074/157] sending base accet to speedometer --- TradingSimulation.js | 3 +++ TradingSimulationPanel.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index d38ff02c5..b87de89c5 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -345,6 +345,7 @@ record.initialBalanceB = dailyFile[i][30]; record.minimunBalanceB = dailyFile[i][31]; record.maximunBalanceB = dailyFile[i][32]; + record.baseAsset = dailyFile[i][33]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -441,6 +442,7 @@ record.initialBalanceB = marketFile[i][30]; record.minimunBalanceB = marketFile[i][31]; record.maximunBalanceB = marketFile[i][32]; + record.baseAsset = marketFile[i][33]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -848,5 +850,6 @@ + diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 549ba318f..5e8dd0835 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -224,6 +224,11 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation /* Parameters */ let params let paramsArray = [] + let positionTaken = false + + if (currentRecord.innerRecord.positionSize > 0) { + positionTaken = true + } params = {} params.VALUE = currentRecord.innerRecord.balanceA; @@ -231,8 +236,10 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation params.MIN_VALUE = currentRecord.innerRecord.minimunBalanceA params.MAX_VALUE = currentRecord.innerRecord.maximunBalanceA params.ASSET_LABEL = 'Asset A' - params.ASSET_NAME = DEFAULT_MARKET.assetB + ' ' + params.ASSET_NAME = DEFAULT_MARKET.assetB params.LEFT_OFFSET = 100 + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.innerRecord.baseAsset paramsArray.push(params) @@ -242,8 +249,10 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation params.INIT_VALUE = currentRecord.innerRecord.initialBalanceB params.MAX_VALUE = currentRecord.innerRecord.maximunBalanceB params.ASSET_LABEL = 'Asset B' - params.ASSET_NAME = DEFAULT_MARKET.assetA + ' ' + params.ASSET_NAME = DEFAULT_MARKET.assetA params.LEFT_OFFSET = 220 + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.innerRecord.baseAsset paramsArray.push(params) @@ -269,5 +278,6 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + From cdfed722f010188593686fdf0f0847f32291c74c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 30 Jun 2019 12:31:15 +0200 Subject: [PATCH 075/157] Supporting Decimals --- TradingSimulationPanel.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 5e8dd0835..b44a9760b 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -240,6 +240,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation params.LEFT_OFFSET = 100 params.POSITION_TAKEN = positionTaken params.BASE_ASSET = currentRecord.innerRecord.baseAsset + params.DECIMALS = 4 paramsArray.push(params) @@ -253,6 +254,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation params.LEFT_OFFSET = 220 params.POSITION_TAKEN = positionTaken params.BASE_ASSET = currentRecord.innerRecord.baseAsset + params.DECIMALS = 2 paramsArray.push(params) From cc1b64a5b5aec7784d4cf00b3e3ee2474a0f810d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 6 Jul 2019 11:13:39 +0200 Subject: [PATCH 076/157] Cleaning Execution Plotter --- Conditions.js | 14 ++- SimulationExecution.js | 249 ++++------------------------------------- 2 files changed, 33 insertions(+), 230 deletions(-) diff --git a/Conditions.js b/Conditions.js index 8d9d01eef..ae1ba53bf 100644 --- a/Conditions.js +++ b/Conditions.js @@ -51,6 +51,8 @@ let conditions = []; let headers; + let noTradingSystemOnFocusErrorDisplayed = false + return thisObject; function finalize() { @@ -517,6 +519,15 @@ if (currentRecord === undefined) { return; } if (currentRecord.conditionsNames === undefined) { return; } if (canvas.strategySpace.workspace === undefined) { return; } + if (canvas.strategySpace.workspace.tradingSystem === undefined) { + if (noTradingSystemOnFocusErrorDisplayed === false) { + if (ERROR_LOG === true) { logger.write("[WARN] sendRecordInfoToStrategySpace -> No Trading System with Execution Focus."); } + noTradingSystemOnFocusErrorDisplayed = true + } + return + } else { + noTradingSystemOnFocusErrorDisplayed = false + } try { @@ -805,7 +816,7 @@ highlightSituation = false } conditionIndex++; - } + } } if (highlightSituation === true) { @@ -888,5 +899,6 @@ + diff --git a/SimulationExecution.js b/SimulationExecution.js index f3cc3eb37..a0e3fb0ff 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -25,8 +25,7 @@ y: 0 }, visible: false - }, - notes: [] + } } }; @@ -46,12 +45,8 @@ let fileSequence; let plotElements = []; // This is where the elements to be plotted are stored before plotting. let plotLines = []; // Here we store the lines of open positions. - let notes = []; // Here we store the notes with messages from the bot. - - let notesChangedEventRaised = true; // This controls when to raise the event that notes changed. let previousNotesSetKey; - let currentNotesSetKey; let offsetChangedEventSubscriptionId let filesUpdatedEventSubscriptionId @@ -76,11 +71,9 @@ fileSequence = undefined; plotElements = undefined; plotLines = undefined; - notes = undefined; } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> finalize -> err = " + err.stack.stack); } } } @@ -93,8 +86,8 @@ fileSequence = pStorage.fileSequences[0]; - recalculate(callBackFunction); - recalculateScale(callBackFunction); + recalculate(); + recalculateScale(); filesUpdatedEventSubscriptionId = fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); @@ -102,100 +95,62 @@ /* Ready for when dimmension changes. */ dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { - recalculate(callBackFunction); - recalculateScale(callBackFunction); + recalculate(); + recalculateScale(); }) callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> initialize -> err = " + err.stack); } callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); } } function getContainer(point) { - try { - let container; - /* First we check if this point is inside this space. */ - if (this.container.frame.isThisPointHere(point) === true) { - return this.container; - } else { - /* This point does not belong to this space. */ - return undefined; } - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> initialize -> err = " + err.stack); } } } function onFilesUpdated() { - recalculate(); - } function setTimePeriod(pTimePeriod) { - - try { - - timePeriod = pTimePeriod; - - recalculate(); - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err); } - } + timePeriod = pTimePeriod; + recalculate(); } function setDatetime(newDatetime) { - - try { - - datetime = newDatetime; - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err); } - } + datetime = newDatetime; } function onOffsetChanged() { - if (Math.random() * 100 > 95) { - recalculate() - }; - + } } - function recalculate(callBackFunction) { - + function recalculate() { try { - if (fileSequence === undefined) { return; } - /* We are going to filter the records depending on the Time Period. We want that for a 1 min time peroid all the records appears on screen, but for higher periods, we will filter out some records, so that they do not overlap ever. */ - plotElements = []; plotLines = []; - notes = []; let lastSellRate; let lastSellDate; @@ -243,27 +198,9 @@ profitsAssetA: file[i][11], profitsAssetB: file[i][12], combinedProfitsA: file[i][13], - combinedProfitsB: file[i][14], - - messageRelevance: file[i][15], - messageTitle: file[i][16], - messageBody: file[i][17], - - mqServiceMessages: file[i][18] + combinedProfitsB: file[i][14] }; - /* - - Now we are going to inflate the mqService Messages in order to use them during the plotting. - - */ - - if (newHistoryRecord.mqServiceMessages !== undefined) { - for (let i = 0; i < newHistoryRecord.mqServiceMessages.length; i++) { - let mqMessage = mqServiceMessages[i]; - } - } - /* Finally we add this History Record to the Array */ history.push(newHistoryRecord); @@ -274,14 +211,11 @@ if (timePeriod <= 1 * 60 * 1000) { if (newHistoryRecord.lastSellRate > 0) { - lastSellRate = newHistoryRecord.lastSellRate; lastSellDate = newHistoryRecord.date; - } if (newHistoryRecord.sellExecRate > 0) { - let newLine = { type: "sell", x1: lastSellDate, @@ -289,20 +223,15 @@ x2: newHistoryRecord.date, y2: newHistoryRecord.sellExecRate }; - lines.push(newLine); - } if (newHistoryRecord.lastBuyRate > 0) { - lastBuyRate = newHistoryRecord.lastBuyRate; lastBuyDate = newHistoryRecord.date; - } if (newHistoryRecord.buyExecRate > 0) { - let newLine = { type: "buy", x1: lastBuyDate, @@ -310,12 +239,9 @@ x2: newHistoryRecord.date, y2: newHistoryRecord.buyExecRate }; - lines.push(newLine); - } } - } /* We allways want to put the last record of the file on the filterd dataset, so as to allways show the latest advance of the bot. */ @@ -342,13 +268,7 @@ profitsAssetA: file[i][11], profitsAssetB: file[i][12], combinedProfitsA: file[i][13], - combinedProfitsB: file[i][14], - - messageRelevance: file[i][15], - messageTitle: file[i][16], - messageBody: file[i][17], - - mqServiceMessages: file[i][18] + combinedProfitsB: file[i][14] }; history.push(newHistoryRecord); @@ -378,61 +298,26 @@ profitsAssetA: file[i][11], profitsAssetB: file[i][12], combinedProfitsA: file[i][13], - combinedProfitsB: file[i][14], - - messageRelevance: file[i][15], - messageTitle: file[i][16], - messageBody: file[i][17] + combinedProfitsB: file[i][14] }; - if (newHistoryRecord.messageTitle !== "" && newHistoryRecord.messageBody !== "") { - - if (newHistoryRecord.messageRelevance >= 0 && newHistoryRecord.messageRelevance <= 10) { - - let relevanceTimePeriod = (dailyFilePeriods[10 - newHistoryRecord.messageRelevance][0]); - - if (timePeriod <= relevanceTimePeriod) { - - let note = { - title: newHistoryRecord.messageTitle, - body: newHistoryRecord.messageBody, - date: newHistoryRecord.date, - rate: newHistoryRecord.marketRate, - position: { - x: 0, - y: 0 - }, - visible: false - }; - - notes.push(note); - } - } - } } - plotElements.push(history); plotLines.push(lines); - } - notesChangedEventRaised = false; - thisObject.container.eventHandler.raiseEvent("History Changed", history); } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err); } - callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> recalculate -> err = " + err.stack); } } } - function recalculateScale(callBackFunction) { + function recalculateScale() { try { if (fileSequence === undefined) { return; } // We need the market file to be loaded to make the calculation. - if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { @@ -453,32 +338,16 @@ ); } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err); } - callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> recalculateScale -> err = " + err.stack); } } } function draw() { - - try { - - if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); } - plotChart(); - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err); } - } } function plotChart() { - try { - - if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } - let point = { x: 0, y: 0 @@ -665,13 +534,10 @@ browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; browserCanvasContext.stroke(); - } /* Draw a red inverted triangle on sell */ - if (record.lastSellRate > 0) { - opacity = '0.5'; let point1 = { @@ -731,7 +597,6 @@ } /* Draw a green triangle on buy */ - if (record.lastBuyRate > 0) { opacity = '0.5'; @@ -791,15 +656,9 @@ browserCanvasContext.stroke(); } - - - /* Since there is at least some point plotted, then the profile should be visible. */ - - thisObject.payload.profile.visible = true; } /* Draw the lines connecting plot elements. */ - let lines = plotLines[j]; for (let i = 0; i < lines.length; i++) { @@ -834,83 +693,15 @@ browserCanvasContext.closePath(); if (line.type === "sell") { - browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, ' + opacity + ')'; - } else { - browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; - } - browserCanvasContext.stroke(); - } - - /* Now we calculate the anchor position of notes. */ - - currentNotesSetKey = ""; - - for (let i = 0; i < notes.length; i++) { - - let note = notes[i]; - - opacity = '0.2'; - - note.position = { - x: note.date, - y: note.rate - }; - - note.position = timeLineCoordinateSystem.transformThisPoint(note.position); - note.position = transformThisPoint(note.position, thisObject.container); - - if (note.position.x < (viewPort.visibleArea.bottomRight.x / 2) * (-1) || note.position.x > (viewPort.visibleArea.bottomRight.x) * (1.5)) { - note.visible = false; - currentNotesSetKey = currentNotesSetKey + "0"; - } else { - note.visible = true; - currentNotesSetKey = currentNotesSetKey + "1"; - } - } - - if (notesChangedEventRaised === false) { - - /* In this case the event is raised because we might have a different set of notes. */ - - thisObject.container.eventHandler.raiseEvent("Notes Changed", notes); - thisObject.payload.notes = notes; - - notesChangedEventRaised = true; - - } else { - - if (currentNotesSetKey !== previousNotesSetKey) { - - /* In this case the event is raised because the visibility of some of the notes changed. */ - - thisObject.container.eventHandler.raiseEvent("Notes Changed", notes); - thisObject.payload.notes = notes; - - previousNotesSetKey = currentNotesSetKey; - } - } - } - - /* - - We replace the coordinate of the profile point so that whoever has a reference to it, gets the new position. - We will use the last point plotted on screen as the profilePoint. - - */ - - thisObject.payload.profile.position.x = point.x; - thisObject.payload.profile.position.y = point.y; - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err); } + if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> plotChart -> err = " + err.stack); } } } } From 64a4ce7bdc2bef64a302513bb9f8784b8a4179d3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 14 Jul 2019 13:46:15 +0200 Subject: [PATCH 077/157] All kind of improvements on pannels, including extended simulation panel --- Project.njsproj | 3 + SimulationExecution.js | 673 +++++++++++++++++++----------------- SimulationExecutionPanel.js | 452 ++++++++++++++++++++++++ TradingSimulation.js | 10 +- TradingSimulationPanel.js | 150 +++++--- this.plotter.config.json | 5 + 6 files changed, 935 insertions(+), 358 deletions(-) create mode 100644 SimulationExecutionPanel.js diff --git a/Project.njsproj b/Project.njsproj index 15b8f293a..3551d717d 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -23,6 +23,9 @@ Code + + Code + Code diff --git a/SimulationExecution.js b/SimulationExecution.js index a0e3fb0ff..b21c05248 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -17,16 +17,7 @@ setTimePeriod: setTimePeriod, setDatetime: setDatetime, recalculateScale: recalculateScale, - draw: draw, - payload: { - profile: { - position: { - x: 0, - y: 0 - }, - visible: false - } - } + draw: draw }; /* this is part of the module template */ @@ -173,7 +164,7 @@ const ONE_MIN_IN_MILISECONDS = 60 * 1000; let step = timePeriod / ONE_MIN_IN_MILISECONDS; - step = 1; // For now we dont discard records depending on the zoom level. + step = 1; // For now we dont discard records depending on the zoom level. let i = 0; let lastRecordPushed = 0; @@ -198,7 +189,8 @@ profitsAssetA: file[i][11], profitsAssetB: file[i][12], combinedProfitsA: file[i][13], - combinedProfitsB: file[i][14] + combinedProfitsB: file[i][14], + datetime: file[i][0] }; /* Finally we add this History Record to the Array */ @@ -208,40 +200,40 @@ /* Here we build the lines. */ - if (timePeriod <= 1 * 60 * 1000) { + //if (timePeriod <= 1 * 60 * 1000) { - if (newHistoryRecord.lastSellRate > 0) { - lastSellRate = newHistoryRecord.lastSellRate; - lastSellDate = newHistoryRecord.date; - } - - if (newHistoryRecord.sellExecRate > 0) { - let newLine = { - type: "sell", - x1: lastSellDate, - y1: lastSellRate, - x2: newHistoryRecord.date, - y2: newHistoryRecord.sellExecRate - }; - lines.push(newLine); - } - - if (newHistoryRecord.lastBuyRate > 0) { - lastBuyRate = newHistoryRecord.lastBuyRate; - lastBuyDate = newHistoryRecord.date; - } - - if (newHistoryRecord.buyExecRate > 0) { - let newLine = { - type: "buy", - x1: lastBuyDate, - y1: lastBuyRate, - x2: newHistoryRecord.date, - y2: newHistoryRecord.buyExecRate - }; - lines.push(newLine); - } + if (newHistoryRecord.lastSellRate > 0) { + lastSellRate = newHistoryRecord.lastSellRate; + lastSellDate = newHistoryRecord.date; } + + if (newHistoryRecord.sellExecRate > 0) { + let newLine = { + type: "sell", + x1: lastSellDate, + y1: lastSellRate, + x2: newHistoryRecord.date, + y2: newHistoryRecord.sellExecRate + }; + lines.push(newLine); + } + + if (newHistoryRecord.lastBuyRate > 0) { + lastBuyRate = newHistoryRecord.lastBuyRate; + lastBuyDate = newHistoryRecord.date; + } + + if (newHistoryRecord.buyExecRate > 0) { + let newLine = { + type: "buy", + x1: lastBuyDate, + y1: lastBuyRate, + x2: newHistoryRecord.date, + y2: newHistoryRecord.buyExecRate + }; + lines.push(newLine); + } + //} } /* We allways want to put the last record of the file on the filterd dataset, so as to allways show the latest advance of the bot. */ @@ -276,8 +268,6 @@ } - /* Second we process the text */ - for (let i = 0; i < file.length; i++) { let newHistoryRecord = { @@ -343,11 +333,16 @@ } function draw() { - plotChart(); + plotChart(); } function plotChart() { try { + + let userPosition = getUserPosition() + let userPositionDate = userPosition.point.x + let currentRecord + let point = { x: 0, y: 0 @@ -362,8 +357,9 @@ for (let i = 0; i < history.length; i++) { record = history[i]; + currentRecord = record - let timestamp = Math.trunc(record.date / timePeriod) * timePeriod + timePeriod / 2; + let timestamp = record.date // Math.trunc(record.date / timePeriod) * timePeriod + timePeriod / 2; point = { x: timestamp, @@ -379,30 +375,323 @@ let isCurrentRecord = false; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.date - timePeriod / 2 && dateValue <= record.date + timePeriod / 2 - 1) { - isCurrentRecord = true; - } + if (userPositionDate >= record.date - 30000 && userPositionDate <= record.date + 30000 - 1) { + isCurrentRecord = true; } - let radius = 3; + let opacity = '1'; + let currentRadius = 10 - let opacity = '0.2'; + /* Draw a red inverted triangle on exec sell */ + if (record.sellExecRate > 0) { - browserCanvasContext.lineWidth = 1; + opacity = '1'; + + let normalSize = 5 + let extraSize = 0 + if (isCurrentRecord) { extraSize = 5 } + + let point1 = { + x: record.date, + y: record.sellExecRate + }; + + let point2 = { + x: record.date + timePeriod / 7 * (normalSize + extraSize), + y: record.sellExecRate + }; + + let point3 = { + x: record.date - timePeriod / 7 * (normalSize + extraSize), + y: record.sellExecRate + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = transformThisPoint(point3, thisObject.container); + point3 = viewPort.fitIntoVisibleArea(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y - diff; + point3.y = point3.y - diff; + + currentRecord.timePeriod = diff + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; + + if (isCurrentRecord === false) { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + + } + + /* Draw a green triangle on exec buy */ + if (record.buyExecRate > 0) { + + opacity = '1'; + + let normalSize = 5 + let extraSize = 0 + if (isCurrentRecord) { extraSize = 5 } + + let point1 = { + x: record.date, + y: record.buyExecRate + }; + + let point2 = { + x: record.date + timePeriod / 7 * (normalSize + extraSize), + y: record.buyExecRate + }; + + let point3 = { + x: record.date - timePeriod / 7 * (normalSize + extraSize), + y: record.buyExecRate + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = transformThisPoint(point3, thisObject.container); + point3 = viewPort.fitIntoVisibleArea(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y + diff; + point3.y = point3.y + diff; + + currentRecord.timePeriod = diff + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')'; + + if (isCurrentRecord === false) { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + } + + /* Draw a red inverted triangle on sell */ + if (record.lastSellRate > 0) { + opacity = '1'; + + let normalSize = 5 + let extraSize = 0 + if (isCurrentRecord) { extraSize = 5 } + + let point1 = { + x: record.date, + y: record.lastSellRate + }; + + let point2 = { + x: record.date + timePeriod / 7 * (normalSize + extraSize), + y: record.lastSellRate + }; + + let point3 = { + x: record.date - timePeriod / 7 * (normalSize + extraSize), + y: record.lastSellRate + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = transformThisPoint(point3, thisObject.container); + point3 = viewPort.fitIntoVisibleArea(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y - diff; + point3.y = point3.y - diff; + + currentRecord.timePeriod = diff + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + } + + /* Draw a green triangle on buy */ + if (record.lastBuyRate > 0) { + + opacity = '1'; + + let normalSize = 5 + let extraSize = 0 + if (isCurrentRecord) { extraSize = 5 } + + let point1 = { + x: record.date, + y: record.lastBuyRate + }; + + let point2 = { + x: record.date + timePeriod / 7 * (normalSize + extraSize), + y: record.lastBuyRate + }; + + let point3 = { + x: record.date - timePeriod / 7 * (normalSize + extraSize), + y: record.lastBuyRate + }; + + point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = transformThisPoint(point1, thisObject.container); + point1 = viewPort.fitIntoVisibleArea(point1); + + point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = transformThisPoint(point2, thisObject.container); + point2 = viewPort.fitIntoVisibleArea(point2); + + point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = transformThisPoint(point3, thisObject.container); + point3 = viewPort.fitIntoVisibleArea(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y + diff; + point3.y = point3.y + diff; + + currentRecord.timePeriod = diff + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + } + + /* Send the current record to the panel */ + + if (userPositionDate >= record.date - 30000 && userPositionDate < record.date + 30000) { + thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); + } + + /* Circles */ + + let radius = 2; + currentRadius = 10 + + browserCanvasContext.lineWidth = 0.25; /* Outer Circle */ + if (isCurrentRecord === true) { + + browserCanvasContext.beginPath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + + browserCanvasContext.arc(point.x, point.y, currentRadius, 0, Math.PI * 2, true); + browserCanvasContext.closePath(); + + if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + browserCanvasContext.fill(); + } + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + } + + /* Inner Circle */ + browserCanvasContext.beginPath(); - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; - if (isCurrentRecord === false) { - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.LIGHT + ', ' + opacity + ')'; - } else { - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ - } + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GOLDEN_ORANGE + ', ' + opacity + ')'; browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); @@ -410,252 +699,9 @@ if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } - + browserCanvasContext.setLineDash([0, 0]) browserCanvasContext.stroke(); - /* Draw a red inverted triangle on exec sell */ - - if (record.sellExecRate > 0) { - - opacity = '0.5'; - - let point1 = { - x: record.date, - y: record.sellExecRate - }; - - let point2 = { - x: record.date + timePeriod / 7 * 2, - y: record.sellExecRate - }; - - let point3 = { - x: record.date - timePeriod / 7 * 2, - y: record.sellExecRate - }; - - point1 = timeLineCoordinateSystem.transformThisPoint(point1); - point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); - - point2 = timeLineCoordinateSystem.transformThisPoint(point2); - point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); - - point3 = timeLineCoordinateSystem.transformThisPoint(point3); - point3 = transformThisPoint(point3, thisObject.container); - point3 = viewPort.fitIntoVisibleArea(point3); - - let diff = point2.x - point3.x; - point2.y = point2.y - diff; - point3.y = point3.y - diff; - - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(point1.x, point1.y); - browserCanvasContext.lineTo(point2.x, point2.y); - browserCanvasContext.lineTo(point3.x, point3.y); - browserCanvasContext.lineTo(point1.x, point1.y); - - browserCanvasContext.closePath(); - - if (isCurrentRecord === false) { - browserCanvasContext.fillStyle = 'rgba(219, 18, 18, ' + opacity + ')'; - } else { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ - } - - browserCanvasContext.fill(); - - browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, ' + opacity + ')'; - browserCanvasContext.stroke(); - - } - - /* Draw a green triangle on exec buy */ - - if (record.buyExecRate > 0) { - - opacity = '0.5'; - - let point1 = { - x: record.date, - y: record.buyExecRate - }; - - let point2 = { - x: record.date + timePeriod / 7 * 2, - y: record.buyExecRate - }; - - let point3 = { - x: record.date - timePeriod / 7 * 2, - y: record.buyExecRate - }; - - point1 = timeLineCoordinateSystem.transformThisPoint(point1); - point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); - - point2 = timeLineCoordinateSystem.transformThisPoint(point2); - point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); - - point3 = timeLineCoordinateSystem.transformThisPoint(point3); - point3 = transformThisPoint(point3, thisObject.container); - point3 = viewPort.fitIntoVisibleArea(point3); - - let diff = point2.x - point3.x; - point2.y = point2.y + diff; - point3.y = point3.y + diff; - - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(point1.x, point1.y); - browserCanvasContext.lineTo(point2.x, point2.y); - browserCanvasContext.lineTo(point3.x, point3.y); - browserCanvasContext.lineTo(point1.x, point1.y); - - browserCanvasContext.closePath(); - - if (isCurrentRecord === false) { - browserCanvasContext.fillStyle = 'rgba(64, 217, 26, ' + opacity + ')'; - } else { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ - } - - browserCanvasContext.fill(); - - browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; - browserCanvasContext.stroke(); - } - - /* Draw a red inverted triangle on sell */ - if (record.lastSellRate > 0) { - opacity = '0.5'; - - let point1 = { - x: record.date, - y: record.lastSellRate - }; - - let point2 = { - x: record.date + timePeriod / 7 * 2, - y: record.lastSellRate - }; - - let point3 = { - x: record.date - timePeriod / 7 * 2, - y: record.lastSellRate - }; - - point1 = timeLineCoordinateSystem.transformThisPoint(point1); - point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); - - point2 = timeLineCoordinateSystem.transformThisPoint(point2); - point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); - - point3 = timeLineCoordinateSystem.transformThisPoint(point3); - point3 = transformThisPoint(point3, thisObject.container); - point3 = viewPort.fitIntoVisibleArea(point3); - - let diff = point2.x - point3.x; - point2.y = point2.y - diff; - point3.y = point3.y - diff; - - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(point1.x, point1.y); - browserCanvasContext.lineTo(point2.x, point2.y); - browserCanvasContext.lineTo(point3.x, point3.y); - browserCanvasContext.lineTo(point1.x, point1.y); - - browserCanvasContext.closePath(); - - if (isCurrentRecord === false) { - browserCanvasContext.fillStyle = 'rgba(255, 255, 255, ' + opacity + ')'; - } else { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ - } - - browserCanvasContext.fill(); - - browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, ' + opacity + ')'; - browserCanvasContext.stroke(); - - } - - /* Draw a green triangle on buy */ - if (record.lastBuyRate > 0) { - - opacity = '0.5'; - - let point1 = { - x: record.date, - y: record.lastBuyRate - }; - - let point2 = { - x: record.date + timePeriod / 7 * 2, - y: record.lastBuyRate - }; - - let point3 = { - x: record.date - timePeriod / 7 * 2, - y: record.lastBuyRate - }; - - point1 = timeLineCoordinateSystem.transformThisPoint(point1); - point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); - - point2 = timeLineCoordinateSystem.transformThisPoint(point2); - point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); - - point3 = timeLineCoordinateSystem.transformThisPoint(point3); - point3 = transformThisPoint(point3, thisObject.container); - point3 = viewPort.fitIntoVisibleArea(point3); - - let diff = point2.x - point3.x; - point2.y = point2.y + diff; - point3.y = point3.y + diff; - - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); - - browserCanvasContext.beginPath(); - - browserCanvasContext.moveTo(point1.x, point1.y); - browserCanvasContext.lineTo(point2.x, point2.y); - browserCanvasContext.lineTo(point3.x, point3.y); - browserCanvasContext.lineTo(point1.x, point1.y); - - browserCanvasContext.closePath(); - - if (isCurrentRecord === false) { - browserCanvasContext.fillStyle = 'rgba(255, 255, 255, ' + opacity + ')'; - } else { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */ - } - - browserCanvasContext.fill(); - - browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; - browserCanvasContext.stroke(); - - } } /* Draw the lines connecting plot elements. */ @@ -665,7 +711,7 @@ let line = lines[i]; - opacity = '0.2'; + opacity = '1'; let point1 = { x: line.x1, @@ -693,12 +739,14 @@ browserCanvasContext.closePath(); if (line.type === "sell") { - browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, ' + opacity + ')'; + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; } else { - browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, ' + opacity + ')'; + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; } browserCanvasContext.stroke(); } + + } } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> plotChart -> err = " + err.stack); } @@ -706,3 +754,10 @@ } } + + + + + + + diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js new file mode 100644 index 000000000..8dd3cc1f1 --- /dev/null +++ b/SimulationExecutionPanel.js @@ -0,0 +1,452 @@ + +function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecutionPanel() { + + + let thisObject = { + fitFunction: undefined, + container: undefined, + onEventRaised: onEventRaised, + draw: draw, + getContainer: getContainer, + initialize: initialize + }; + + let container = newContainer(); + container.initialize(); + thisObject.container = container; + + container.displacement.containerName = "Trading Execution"; + container.frame.containerName = "Trading Execution"; + + let currentRecord; + let panelTabButton + + return thisObject; + + function initialize() { + + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2; + + thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 4; + thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; + + panelTabButton = newPanelTabButton() + panelTabButton.parentContainer = thisObject.container + panelTabButton.container.frame.parentFrame = thisObject.container.frame + panelTabButton.fitFunction = thisObject.fitFunction + panelTabButton.initialize() + } + + function getContainer(point) { + + let container; + + container = panelTabButton.getContainer(point) + if (container !== undefined) { return container } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + + let checkPoint = { + x: point.x, + y: point.y + } + + checkPoint = thisObject.fitFunction(checkPoint) + + if (point.x === checkPoint.x && point.y === checkPoint.y) { + return thisObject.container; + } + } + } + + + function onEventRaised(lastCurrentCandle) { + + currentRecord = lastCurrentCandle; + + } + + + function draw() { + + thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); + + plot(); + + panelTabButton.draw() + + } + + + function plot() { + + if (currentRecord === undefined) { return; } + + const frameBodyHeight = thisObject.container.frame.getBodyHeight(); + const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; + + const X_AXIS = thisObject.container.frame.width / 2; + const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; + + record = currentRecord + + point = { + x: X_AXIS, + y: Y_AXIS + }; + + point = thisObject.container.frame.frameThisPoint(point); + point = thisObject.fitFunction(point); + + let isCurrentRecord = true; + + let radius = 2; + let currentRadius = 10 + let opacity = '1'; + + /* Draw a red inverted triangle on exec sell */ + if (record.sellExecRate > 0) { + + opacity = '1'; + + let point1 = { + x: X_AXIS, + y: Y_AXIS + }; + + let point2 = { + x: X_AXIS + record.timePeriod / 4, + y: Y_AXIS + }; + + let point3 = { + x: X_AXIS - record.timePeriod / 4, + y: Y_AXIS + }; + + point1 = thisObject.container.frame.frameThisPoint(point1); + point1 = thisObject.fitFunction(point1); + + point2 = thisObject.container.frame.frameThisPoint(point2); + point2 = thisObject.fitFunction(point2); + + point3 = thisObject.container.frame.frameThisPoint(point3); + point3 = thisObject.fitFunction(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y - diff; + point3.y = point3.y - diff; + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; + + if (isCurrentRecord === false) { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + + } + + /* Draw a green triangle on exec buy */ + if (record.buyExecRate > 0) { + + opacity = '1'; + + let point1 = { + x: X_AXIS, + y: Y_AXIS + }; + + let point2 = { + x: X_AXIS + record.timePeriod / 4, + y: Y_AXIS + }; + + let point3 = { + x: X_AXIS - record.timePeriod / 4, + y: Y_AXIS + }; + + point1 = thisObject.container.frame.frameThisPoint(point1); + point1 = thisObject.fitFunction(point1); + + point2 = thisObject.container.frame.frameThisPoint(point2); + point2 = thisObject.fitFunction(point2); + + point3 = thisObject.container.frame.frameThisPoint(point3); + point3 = thisObject.fitFunction(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y + diff; + point3.y = point3.y + diff; + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')'; + + if (isCurrentRecord === false) { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; + } else { + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + } + + /* Draw a red inverted triangle on sell */ + if (record.lastSellRate > 0) { + opacity = '1'; + + let point1 = { + x: X_AXIS, + y: Y_AXIS + }; + + let point2 = { + x: X_AXIS + record.timePeriod / 4, + y: Y_AXIS + }; + + let point3 = { + x: X_AXIS - record.timePeriod / 4, + y: Y_AXIS + }; + + point1 = thisObject.container.frame.frameThisPoint(point1); + point1 = thisObject.fitFunction(point1); + + point2 = thisObject.container.frame.frameThisPoint(point2); + point2 = thisObject.fitFunction(point2); + + point3 = thisObject.container.frame.frameThisPoint(point3); + point3 = thisObject.fitFunction(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y - diff; + point3.y = point3.y - diff; + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + } + + /* Draw a green triangle on buy */ + if (record.lastBuyRate > 0) { + + opacity = '1'; + + let point1 = { + x: X_AXIS, + y: Y_AXIS + }; + + let point2 = { + x: X_AXIS + record.timePeriod / 4, + y: Y_AXIS + }; + + let point3 = { + x: X_AXIS - record.timePeriod / 4, + y: Y_AXIS + }; + + point1 = thisObject.container.frame.frameThisPoint(point1); + point1 = thisObject.fitFunction(point1); + + point2 = thisObject.container.frame.frameThisPoint(point2); + point2 = thisObject.fitFunction(point2); + + point3 = thisObject.container.frame.frameThisPoint(point3); + point3 = thisObject.fitFunction(point3); + + let diff = point2.x - point3.x; + point2.y = point2.y + diff; + point3.y = point3.y + diff; + + point2 = viewPort.fitIntoVisibleArea(point2); + point3 = viewPort.fitIntoVisibleArea(point3); + + browserCanvasContext.beginPath(); + + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point1.x, point1.y); + + browserCanvasContext.closePath(); + + if (isCurrentRecord === false) { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ')'; + } else { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + } + + browserCanvasContext.fill(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + } + + browserCanvasContext.lineWidth = 0.25; + + /* Outer Circle */ + + if (isCurrentRecord === true) { + + browserCanvasContext.beginPath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + opacity + ')'; /* highlight the current record */ + + browserCanvasContext.arc(point.x, point.y, currentRadius, 0, Math.PI * 2, true); + browserCanvasContext.closePath(); + + if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + browserCanvasContext.fill(); + } + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + } + + /* Inner Circle */ + + browserCanvasContext.beginPath(); + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'; + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GOLDEN_ORANGE + ', ' + opacity + ')'; + + browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true); + browserCanvasContext.closePath(); + + if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + browserCanvasContext.fill(); + } + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke(); + + /* put the labels */ + + browserCanvasContext.beginPath(); + + let y; + let recordDate = new Date(currentRecord.datetime) + + printLabel('Market Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.05 / 2, '1'); + printLabel(currentRecord.marketRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.10 / 2, '0.50'); + + printLabel('Sell Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.15 / 2, '1'); + printLabel(currentRecord.lastSellRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.20 / 2, '0.50'); + + printLabel('Sell Executed Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.25 / 2, '1'); + printLabel(currentRecord.sellExecRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.30 / 2, '0.50'); + + printLabel('Buy Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.35 / 2, '1'); + printLabel(currentRecord.lastBuyRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.40 / 2, '0.40'); + + printLabel('Buy Executed Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.45 / 2, '1'); + printLabel(currentRecord.buyExecRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.50 / 2, '0.50'); + + printLabel('ROI Asset A', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.25 / 2), '1'); + printLabel((currentRecord.combinedProfitsA).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.30 / 2), '0.50'); + + printLabel('ROI Asset B', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.15 / 2), '1'); + printLabel((currentRecord.combinedProfitsB).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.20 / 2), '0.50'); + + printLabel('Datetime', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.05 / 2), '1'); + printLabel(recordDate.toUTCString(), X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.1 / 2), '0.50'); + + + function printLabel(labelToPrint, x, y, opacity) { + + let labelPoint; + let fontSize = 10; + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'; + + let label = '' + labelToPrint; + if (isNaN(label) === false) { + label = Number(label).toLocaleString(); + } + let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + + labelPoint = { + x: x - xOffset, + y: y + }; + + labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); + labelPoint = thisObject.fitFunction(labelPoint) + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + + } + + browserCanvasContext.closePath(); + browserCanvasContext.fill(); + + } + + +} + + + + + + + diff --git a/TradingSimulation.js b/TradingSimulation.js index b87de89c5..3182189b1 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -513,10 +513,11 @@ if (userPositionDate >= record.begin && userPositionDate <= record.end) { - let currentRecord = { - innerRecord: record + let eventRecords = { + currentRecord: record, + lastRecord: records[records.length - 1] }; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); + thisObject.container.eventHandler.raiseEvent("Current Record Changed", eventRecords); } let stopLossPhase = 0; @@ -549,7 +550,7 @@ let recordPoint4 = { x: record.begin + timePeriod / 7 * 1.5, - y: thisObject.container.frame.height * 3 + y: thisObject.container.frame.height * 100 }; let recordPoint5 = { @@ -851,5 +852,6 @@ + diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index b44a9760b..1f3d5431e 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -15,10 +15,11 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation container.initialize(); thisObject.container = container; - container.displacement.containerName = "Simulation"; - container.frame.containerName = "Simulation"; + container.displacement.containerName = "Trading Simulation"; + container.frame.containerName = "Trading Simulation"; let currentRecord; + let lastRecord; let panelTabButton @@ -26,10 +27,10 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function initialize() { - thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 2; thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2; - thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1; + thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 1; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; panelTabButton = newPanelTabButton() @@ -67,9 +68,10 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation } - function onEventRaised(lastCurrentRecord) { + function onEventRaised(records) { - currentRecord = lastCurrentRecord; + currentRecord = records.currentRecord; + lastRecord = records.lastRecord } @@ -87,7 +89,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function plotCurrentRecordInfo() { if (currentRecord === undefined) { return; } - if (currentRecord.innerRecord === undefined) { return; } + if (lastRecord === undefined) { return; } const frameBodyHeight = thisObject.container.frame.getBodyHeight(); const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; @@ -105,92 +107,149 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; y = y + increment; - printLabel('Current Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', 12); + printLabel('Current Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); y = y + increment; printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; y = y + increment; - printLabel('Latest Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', 12); + printLabel('Latest Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.lastTradeProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.lastTradeProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.innerRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + + let bifurcationLevel = y + y = y + increment; + y = y + increment; + printLabel('Partial Results', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1', 14); + + y = y + increment; + printLabel('Profit / Loss', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.profit, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Trades', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.roundtrips, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Hits', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.hits, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Fails', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.fails, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Hit Ratio', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('ROI', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Periods', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.periods, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Days', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.days, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Anualized Rate of Return', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + + y = bifurcationLevel + y = y + increment; y = y + increment; - printLabel('Totals Accumulated', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', 12); + printLabel('Final Results', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1', 14); y = y + increment; - printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Profit / Loss', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(lastRecord.profit, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Trades', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(lastRecord.roundtrips, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Hits', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(lastRecord.hits, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Fails', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(lastRecord.fails, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Hit Ratio', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.innerRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((lastRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('ROI', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.innerRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((lastRecord.ROI * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Periods', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(lastRecord.periods, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Days', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.innerRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(lastRecord.days, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Anualized Rate of Return', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.innerRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((lastRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + function printLabel(labelToPrint, x, y, opacity, fontSize) { @@ -226,34 +285,34 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let paramsArray = [] let positionTaken = false - if (currentRecord.innerRecord.positionSize > 0) { + if (currentRecord.positionSize > 0) { positionTaken = true } params = {} - params.VALUE = currentRecord.innerRecord.balanceA; - params.INIT_VALUE = currentRecord.innerRecord.initialBalanceA - params.MIN_VALUE = currentRecord.innerRecord.minimunBalanceA - params.MAX_VALUE = currentRecord.innerRecord.maximunBalanceA + params.VALUE = currentRecord.balanceA; + params.INIT_VALUE = currentRecord.initialBalanceA + params.MIN_VALUE = currentRecord.minimunBalanceA + params.MAX_VALUE = currentRecord.maximunBalanceA params.ASSET_LABEL = 'Asset A' params.ASSET_NAME = DEFAULT_MARKET.assetB params.LEFT_OFFSET = 100 params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.innerRecord.baseAsset + params.BASE_ASSET = currentRecord.baseAsset params.DECIMALS = 4 paramsArray.push(params) params = {} - params.VALUE = currentRecord.innerRecord.balanceB; - params.MIN_VALUE = currentRecord.innerRecord.minimunBalanceB - params.INIT_VALUE = currentRecord.innerRecord.initialBalanceB - params.MAX_VALUE = currentRecord.innerRecord.maximunBalanceB + params.VALUE = currentRecord.balanceB; + params.MIN_VALUE = currentRecord.minimunBalanceB + params.INIT_VALUE = currentRecord.initialBalanceB + params.MAX_VALUE = currentRecord.maximunBalanceB params.ASSET_LABEL = 'Asset B' params.ASSET_NAME = DEFAULT_MARKET.assetA params.LEFT_OFFSET = 220 params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.innerRecord.baseAsset + params.BASE_ASSET = currentRecord.baseAsset params.DECIMALS = 2 paramsArray.push(params) @@ -281,5 +340,6 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + diff --git a/this.plotter.config.json b/this.plotter.config.json index 19447d29e..9505e5005 100644 --- a/this.plotter.config.json +++ b/this.plotter.config.json @@ -45,6 +45,11 @@ "description": "Plots Simulation Execution.", "profilePicture": "SimulationExecution.png", "panels": [ + { + "codeName": "SimulationExecutionPanel", + "moduleName": "SimulationExecutionPanel", + "event": "Current Record Changed" + } ] } ] From 638870526242e0ce86b6219aa466a1d423ec7614 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 15 Jul 2019 10:02:12 +0200 Subject: [PATCH 078/157] Asset A and B Inverted --- SimulationExecutionPanel.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index 8dd3cc1f1..e7d6ddff4 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -401,10 +401,10 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu printLabel(currentRecord.buyExecRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.50 / 2, '0.50'); printLabel('ROI Asset A', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.25 / 2), '1'); - printLabel((currentRecord.combinedProfitsA).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.30 / 2), '0.50'); + printLabel((currentRecord.combinedProfitsB).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.30 / 2), '0.50'); printLabel('ROI Asset B', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.15 / 2), '1'); - printLabel((currentRecord.combinedProfitsB).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.20 / 2), '0.50'); + printLabel((currentRecord.combinedProfitsA).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.20 / 2), '0.50'); printLabel('Datetime', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.05 / 2), '1'); printLabel(recordDate.toUTCString(), X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.1 / 2), '0.50'); @@ -450,3 +450,4 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu + From 54f9c8d6474b2adbacf0dbf8340ed2b40d3ab442 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 16 Jul 2019 22:40:43 +0200 Subject: [PATCH 079/157] Open y Close Execution Errors --- Conditions.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Conditions.js b/Conditions.js index ae1ba53bf..15adde0eb 100644 --- a/Conditions.js +++ b/Conditions.js @@ -696,6 +696,12 @@ } } } + + let openExecution = openStage.openExecution + + if (openExecution !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.openExecution.payload.uiObject.setErrorMessage(openStage.openExecution.error) + } } let manageStage = strategy.manageStage @@ -790,6 +796,19 @@ } } } + + + let closeStage = strategy.closeStage + + if (closeStage !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].closeStage.payload.uiObject.setErrorMessage(closeStage.error) + + let closeExecution = closeStage.closeExecution + + if (closeExecution !== undefined) { + canvas.strategySpace.workspace.tradingSystem.strategies[j].closeStage.closeExecution.payload.uiObject.setErrorMessage(closeStage.closeExecution.error) + } + } } function processSituation(situation, node) { From fce1da110d5fb90d2fdf21ae5e17bbe55cb42abe Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 30 Jul 2019 22:11:06 +0200 Subject: [PATCH 080/157] Definition introduced --- Conditions.js | 127 +++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/Conditions.js b/Conditions.js index 15adde0eb..9c691cd6f 100644 --- a/Conditions.js +++ b/Conditions.js @@ -51,7 +51,7 @@ let conditions = []; let headers; - let noTradingSystemOnFocusErrorDisplayed = false + let noDefinitionOnFocusErrorDisplayed = false return thisObject; @@ -519,15 +519,16 @@ if (currentRecord === undefined) { return; } if (currentRecord.conditionsNames === undefined) { return; } if (canvas.strategySpace.workspace === undefined) { return; } - if (canvas.strategySpace.workspace.tradingSystem === undefined) { - if (noTradingSystemOnFocusErrorDisplayed === false) { - if (ERROR_LOG === true) { logger.write("[WARN] sendRecordInfoToStrategySpace -> No Trading System with Execution Focus."); } - noTradingSystemOnFocusErrorDisplayed = true + if (canvas.strategySpace.workspace.definition === undefined) { + if (noDefinitionOnFocusErrorDisplayed === false) { + if (ERROR_LOG === true) { logger.write("[WARN] sendRecordInfoToStrategySpace -> No Definition with Execution Focus."); } + noDefinitionOnFocusErrorDisplayed = true } return } else { - noTradingSystemOnFocusErrorDisplayed = false + noDefinitionOnFocusErrorDisplayed = false } + if (canvas.strategySpace.workspace.definition.tradingSystem === undefined) { return; } try { @@ -538,14 +539,14 @@ let formulaErrorsIndex = 0; let formulaValuesIndex = 0; - canvas.strategySpace.workspace.tradingSystem.payload.uiObject.setErrorMessage(tradingSystem.error) + canvas.strategySpace.workspace.definition.tradingSystem.payload.uiObject.setErrorMessage(tradingSystem.error) if (tradingSystem.parameters !== undefined) { - canvas.strategySpace.workspace.tradingSystem.parameters.payload.uiObject.setErrorMessage(tradingSystem.parameters.error) + canvas.strategySpace.workspace.definition.tradingSystem.parameters.payload.uiObject.setErrorMessage(tradingSystem.parameters.error) if (tradingSystem.parameters.baseAsset !== undefined) { - canvas.strategySpace.workspace.tradingSystem.parameters.baseAsset.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.error) + canvas.strategySpace.workspace.definition.tradingSystem.parameters.baseAsset.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.error) if (tradingSystem.parameters.baseAsset.formula !== undefined) { - canvas.strategySpace.workspace.tradingSystem.parameters.baseAsset.formula.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.formula.error) + canvas.strategySpace.workspace.definition.tradingSystem.parameters.baseAsset.formula.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.formula.error) } } } @@ -553,27 +554,27 @@ for (let j = 0; j < tradingSystem.strategies.length; j++) { let strategy = tradingSystem.strategies[j]; - canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.setErrorMessage(strategy.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].payload.uiObject.setErrorMessage(strategy.error) if (currentRecord.strategyNumber === j) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = true + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].payload.uiObject.isExecuting = false + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].payload.uiObject.isExecuting = false } let triggerStage = strategy.triggerStage if (triggerStage !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.payload.uiObject.setErrorMessage(triggerStage.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.payload.uiObject.setErrorMessage(triggerStage.error) if (triggerStage.triggerOn !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOn.payload.uiObject.setErrorMessage(triggerStage.triggerOn.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOn.payload.uiObject.setErrorMessage(triggerStage.triggerOn.error) for (let k = 0; k < triggerStage.triggerOn.situations.length; k++) { let situation = triggerStage.triggerOn.situations[k]; - canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOn.situations[k].error) - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k]); + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOn.situations[k].error) + processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k]); } } @@ -582,8 +583,8 @@ for (let k = 0; k < triggerStage.triggerOff.situations.length; k++) { let situation = triggerStage.triggerOff.situations[k]; - canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOff.situations[k].error) - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k]); + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOff.situations[k].error) + processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k]); } } @@ -592,8 +593,8 @@ for (let k = 0; k < triggerStage.takePosition.situations.length; k++) { let situation = triggerStage.takePosition.situations[k]; - canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.takePosition.situations[k].payload.uiObject.setErrorMessage(triggerStage.takePosition.situations[k].error) - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].triggerStage.takePosition.situations[k]); + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.takePosition.situations[k].payload.uiObject.setErrorMessage(triggerStage.takePosition.situations[k].error) + processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.takePosition.situations[k]); } } } @@ -601,96 +602,96 @@ let openStage = strategy.openStage if (openStage !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.payload.uiObject.setErrorMessage(openStage.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.payload.uiObject.setErrorMessage(openStage.error) let initialDefinition = openStage.initialDefinition if (initialDefinition !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.payload.uiObject.setErrorMessage(openStage.initialDefinition.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.payload.uiObject.setErrorMessage(openStage.initialDefinition.error) if (initialDefinition.stopLoss !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.error) for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false } let phase = initialDefinition.stopLoss.phases[p]; - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].error) if (phase.formula !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.error) for (let k = 0; k < nextPhaseEvent.situations.length; k++) { let situation = nextPhaseEvent.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.situations[k]); + processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.situations[k]); } } } } if (initialDefinition.takeProfit !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.error) for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false } let phase = initialDefinition.takeProfit.phases[p]; - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].error) if (phase.formula !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.error) for (let k = 0; k < nextPhaseEvent.situations.length; k++) { let situation = nextPhaseEvent.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.situations[k]); + processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.situations[k]); } } } @@ -700,97 +701,97 @@ let openExecution = openStage.openExecution if (openExecution !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].openStage.openExecution.payload.uiObject.setErrorMessage(openStage.openExecution.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.openExecution.payload.uiObject.setErrorMessage(openStage.openExecution.error) } } let manageStage = strategy.manageStage if (manageStage !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.payload.uiObject.setErrorMessage(manageStage.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.payload.uiObject.setErrorMessage(manageStage.error) if (manageStage.stopLoss !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.payload.uiObject.setErrorMessage(manageStage.stopLoss.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.payload.uiObject.setErrorMessage(manageStage.stopLoss.error) for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false } let phase = manageStage.stopLoss.phases[p]; - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].error) if (phase.formula !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].nextPhaseEvent.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].nextPhaseEvent.error) for (let k = 0; k < nextPhaseEvent.situations.length; k++) { let situation = nextPhaseEvent.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.situations[k]); + processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.situations[k]); } } } } if (manageStage.takeProfit !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.payload.uiObject.setErrorMessage(manageStage.takeProfit.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.payload.uiObject.setErrorMessage(manageStage.takeProfit.error) for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false } let phase = manageStage.takeProfit.phases[p]; - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].error) if (phase.formula !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].nextPhaseEvent.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].nextPhaseEvent.error) for (let k = 0; k < nextPhaseEvent.situations.length; k++) { let situation = nextPhaseEvent.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.situations[k]); + processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.situations[k]); } } } @@ -801,12 +802,12 @@ let closeStage = strategy.closeStage if (closeStage !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].closeStage.payload.uiObject.setErrorMessage(closeStage.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].closeStage.payload.uiObject.setErrorMessage(closeStage.error) let closeExecution = closeStage.closeExecution if (closeExecution !== undefined) { - canvas.strategySpace.workspace.tradingSystem.strategies[j].closeStage.closeExecution.payload.uiObject.setErrorMessage(closeStage.closeExecution.error) + canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].closeStage.closeExecution.payload.uiObject.setErrorMessage(closeStage.closeExecution.error) } } } From 08334b0cbbcb3b5a11e4315f2b49cace1e406fbe Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 9 Aug 2019 01:35:10 +0200 Subject: [PATCH 081/157] Controlling Dashed Lines --- SimulationExecution.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/SimulationExecution.js b/SimulationExecution.js index b21c05248..de07b3888 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -447,6 +447,7 @@ browserCanvasContext.fill(); browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.lineWidth = 0.25; browserCanvasContext.stroke(); } @@ -516,6 +517,7 @@ browserCanvasContext.fill(); browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.lineWidth = 0.25; browserCanvasContext.stroke(); } @@ -581,7 +583,9 @@ browserCanvasContext.fill(); browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')'; + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.lineWidth = 0.25; browserCanvasContext.stroke(); } @@ -648,7 +652,9 @@ browserCanvasContext.fill(); browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.lineWidth = 0.25; browserCanvasContext.stroke(); } @@ -663,8 +669,6 @@ let radius = 2; currentRadius = 10 - browserCanvasContext.lineWidth = 0.25; - /* Outer Circle */ if (isCurrentRecord === true) { @@ -681,7 +685,9 @@ if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.lineWidth = 0.25; browserCanvasContext.stroke(); } @@ -699,7 +705,9 @@ if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.lineWidth = 0.25; browserCanvasContext.stroke(); } @@ -743,6 +751,9 @@ } else { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; } + + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.lineWidth = 0.25; browserCanvasContext.stroke(); } @@ -761,3 +772,4 @@ + From 4a112fe90cf856c00df6c4b7bcdbfdfb196dd82b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Aug 2019 12:25:05 +0200 Subject: [PATCH 082/157] New positionPeriods and PositionDays counters added --- SimulationExecutionPanel.js | 2 +- TradingSimulation.js | 4 ++++ TradingSimulationPanel.js | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index e7d6ddff4..e85d6d5e5 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -26,7 +26,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu function initialize() { thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 4; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; diff --git a/TradingSimulation.js b/TradingSimulation.js index 3182189b1..1e30b421d 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -346,6 +346,8 @@ record.minimunBalanceB = dailyFile[i][31]; record.maximunBalanceB = dailyFile[i][32]; record.baseAsset = dailyFile[i][33]; + record.positionPeriods = dailyFile[i][34]; + record.positionDays = dailyFile[i][35]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -443,6 +445,8 @@ record.minimunBalanceB = marketFile[i][31]; record.maximunBalanceB = marketFile[i][32]; record.baseAsset = marketFile[i][33]; + record.positionPeriods = marketFile[i][34]; + record.positionDays = marketFile[i][35]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 1f3d5431e..331233ad9 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -28,7 +28,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function initialize() { thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 2; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 1; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; @@ -107,7 +107,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; y = y + increment; - printLabel('Current Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); + printLabel('Current Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); y = y + increment; printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); @@ -132,7 +132,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; y = y + increment; - printLabel('Latest Trade', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); + printLabel('Latest Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); @@ -144,6 +144,15 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + y = y + increment; + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); From b8cade9f3f8d01834bb45cb44375982fc4e56609 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Aug 2019 12:34:33 +0200 Subject: [PATCH 083/157] Repositioning --- TradingSimulationPanel.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 331233ad9..efe315d77 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -129,6 +129,15 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + y = y + increment; + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; y = y + increment; @@ -144,16 +153,6 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - y = y + increment; - printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - let bifurcationLevel = y From 232b92a7d1e9daba722420a1a089c0af682a0ec3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Aug 2019 12:54:27 +0200 Subject: [PATCH 084/157] https://github.com/Superalgos/Releases/issues/3 --- SimulationExecution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimulationExecution.js b/SimulationExecution.js index de07b3888..566c409e4 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -752,7 +752,7 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; } - browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.setLineDash([4, 1]) browserCanvasContext.lineWidth = 0.25; browserCanvasContext.stroke(); } From e0c8960cbd97f607ee16b931301bf038a4e48bbf Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Aug 2019 16:18:02 +0200 Subject: [PATCH 085/157] Panel lenght fixed --- TradingSimulationPanel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index efe315d77..bff495f2b 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -103,7 +103,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation browserCanvasContext.beginPath(); let y = 0; - let increment = 0.027; + let increment = 0.024; y = y + increment; y = y + increment; From 76f5d6da79c062f35dee57ad67c3516885cc792f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 18 Aug 2019 16:13:18 +0200 Subject: [PATCH 086/157] Dealing with negative zero values --- TradingSimulationPanel.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index bff495f2b..0c685bc93 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -146,7 +146,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.lastTradeProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); @@ -269,6 +269,9 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let label = '' + labelToPrint; if (isNaN(label) === false) { label = Number(label).toLocaleString(); + if ((label === "-0" || label === "0") && (labelToPrint !== 0) && (labelToPrint !== "0.00")) { + label = Number(labelToPrint).toFixed(6); + } } let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; @@ -346,6 +349,10 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation + + + + From 7e55cbbe5c9cee8810349772b337411176c3c8d2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 20 Aug 2019 21:55:50 +0200 Subject: [PATCH 087/157] Auto refreshing plotters --- Conditions.js | 13 +- FinalResults.js | 348 +++++++++++++++++++++++++++++++++++++++++ FinalResultsPanel.js | 360 +++++++++++++++++++++++++++++++++++++++++++ Strategies.js | 13 +- Trades.js | 13 +- TradingSimulation.js | 13 +- 6 files changed, 712 insertions(+), 48 deletions(-) create mode 100644 FinalResults.js create mode 100644 FinalResultsPanel.js diff --git a/Conditions.js b/Conditions.js index 9c691cd6f..ae004c4ea 100644 --- a/Conditions.js +++ b/Conditions.js @@ -363,18 +363,7 @@ let lowerEnd = leftDate.valueOf(); let upperEnd = rightDate.valueOf(); - if (conditions.length > 0) { - - if (conditions[0].begin > lowerEnd || conditions[conditions.length - 1].end < upperEnd) { - - setTimeout(recalculate, 2000); - - //console.log("File missing while calculating conditions, scheduling a recalculation in 2 seconds."); - - } - } - - //console.log("Olivia > recalculateUsingDailyFiles > total conditions generated : " + conditions.length); + setTimeout(recalculate, 2000); } catch (err) { diff --git a/FinalResults.js b/FinalResults.js new file mode 100644 index 000000000..dcc9ce8d2 --- /dev/null +++ b/FinalResults.js @@ -0,0 +1,348 @@ +function newAAMastersPlottersTradingSimulationFinalResults() { + + const MODULE_NAME = "Final Results Plotter"; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; + + let thisObject = { + + // Main functions and properties. + + initialize: initialize, + finalize: finalize, + container: undefined, + getContainer: getContainer, + setTimePeriod: setTimePeriod, + setDatetime: setDatetime, + draw: draw, + recalculateScale: recalculateScale, + currentRecord: undefined + }; + + /* this is part of the module template */ + + let container = newContainer(); // Do not touch this 3 lines, they are just needed. + container.initialize(); + thisObject.container = container; + + let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + + let timePeriod; // This will hold the current Time Period the user is at. + let datetime; // This will hold the current Datetime the user is at. + + let dataFile; // This is the current Market File being plotted. + let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. + + let singleFile; // This object will provide the different Market Files at different Time Periods. + + /* these are module specific variables: */ + + let records = []; // Here we keep the records to be ploted every time the Draw() function is called by the AAWebPlatform. + + let imageStopLossPhase; + let imageTakeProfitPhase; + let imageRecord; + + let zoomChangedEventSubscriptionId + let offsetChangedEventSubscriptionId + let filesUpdatedEventSubscriptionId + let dragFinishedEventSubscriptionId + let dimmensionsChangedEventSubscriptionId + + return thisObject; + + function finalize() { + try { + + /* Stop listening to the necesary events. */ + + viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); + viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + singleFile.eventHandler.stopListening(filesUpdatedEventSubscriptionId); + canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); + thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) + + /* icons */ + + imageStopLossPhase = undefined; + imageTakeProfitPhase = undefined; + imageRecord = undefined; + + /* Destroy References */ + + singleFile = undefined; + + datetime = undefined; + timePeriod = undefined; + + dataFile = undefined; + fileCursor = undefined; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } + } + } + + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + + try { + + /* Store the information received. */ + + singleFile = pStorage.singleFile; + + datetime = pDatetime; + timePeriod = pTimePeriod; + + dataFile = singleFile.getFile(timePeriod); + + /* Listen to the necesary events. */ + + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + filesUpdatedEventSubscriptionId = singleFile.eventHandler.listenToEvent("Files Updated", onFilesUpdated); + dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + + /* Get ready for plotting. */ + + recalculate(); + + /* Ready for when dimmension changes. */ + + dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + recalculate(); + }) + + callBackFunction(); + + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err.stack); } + } + } + + function getContainer(point) { + let container; + /* First we check if this point is inside this space. */ + if (this.container.frame.isThisPointHere(point) === true) { + return this.container; + } else { + /* This point does not belong to this space. */ + return undefined; + } + } + + function onFilesUpdated() { + try { + dataFile = singleFile.getFile(timePeriod); + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } + } + } + + function setTimePeriod(pTimePeriod) { + try { + if (timePeriod !== pTimePeriod) { + timePeriod = pTimePeriod; + dataFile = singleFile.getFile(timePeriod); + recalculate(); + } + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } + } + } + + function setDatetime(pDatetime) { + datetime = pDatetime; + } + + function draw() { + try { + // Nothing to draw for now + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err.stack); } + } + } + + function recalculate() { + + try { + + records = [] + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + + recalculateUsingMarketFiles(); + + } else { + + recalculateUsingDailyFiles(); + + } + + thisObject.container.eventHandler.raiseEvent("Records Changed", records); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } + } + } + + function recalculate() { + + try { + + if (dataFile === undefined) { return; } // Initialization not complete yet. + + records = []; + + for (let i = 0; i < dataFile.length; i++) { + + let record = {}; + + record.begin = dataFile[i][0]; + record.end = dataFile[i][1]; + record.type = dataFile[i][2]; + record.rate = dataFile[i][3]; + record.amount = dataFile[i][4]; + record.balanceA = dataFile[i][5]; + record.balanceB = dataFile[i][6]; + record.profit = dataFile[i][7]; + record.lastTradeProfitLoss = dataFile[i][8]; + record.stopLoss = dataFile[i][9]; + record.roundtrips = dataFile[i][10]; + record.hits = dataFile[i][11]; + record.fails = dataFile[i][12]; + record.hitRatio = dataFile[i][13]; + record.ROI = dataFile[i][14]; + record.periods = dataFile[i][15]; + record.days = dataFile[i][16]; + record.anualizedRateOfReturn = dataFile[i][17]; + record.sellRate = dataFile[i][18]; + record.lastTradeROI = dataFile[i][19]; + record.strategy = dataFile[i][20]; + record.strategyPhase = dataFile[i][21]; + record.takeProfit = dataFile[i][22]; + record.stopLossPhase = dataFile[i][23]; + record.takeProfitPhase = dataFile[i][24]; + record.positionSize = dataFile[i][26]; // 25 is the message for the executor + record.initialBalanceA = dataFile[i][27]; + record.minimunBalanceA = dataFile[i][28]; + record.maximunBalanceA = dataFile[i][29]; + record.initialBalanceB = dataFile[i][30]; + record.minimunBalanceB = dataFile[i][31]; + record.maximunBalanceB = dataFile[i][32]; + record.baseAsset = dataFile[i][33]; + record.positionPeriods = dataFile[i][34]; + record.positionDays = dataFile[i][35]; + + thisObject.currentRecord = record; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", thisObject.currentRecord); + } + + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } + } + } + + function recalculateScale() { + try { + // No scale needed + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } + } + } + + function plotChart() { + try { + let userPosition = getUserPosition() + let userPositionDate = userPosition.point.x + + let record; + + /* Now we calculate and plot the records */ + for (let i = 0; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 + + record = records[i]; + + /* Send the current record to the panel */ + + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + + let eventRecords = { + currentRecord: record, + lastRecord: records[records.length - 1] + }; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", eventRecords); + } + } + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } + } + } + + function onZoomChanged(event) { + try { + recalculate(); + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } + } + } + + function onOffsetChanged() { + try { + if (Math.random() * 100 > 95) { + recalculate() + }; + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } + } + } + + function onDragFinished() { + try { + recalculate(); + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err = " + err.stack); } + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FinalResultsPanel.js b/FinalResultsPanel.js new file mode 100644 index 000000000..0907ae991 --- /dev/null +++ b/FinalResultsPanel.js @@ -0,0 +1,360 @@ + +function newAAMastersPlottersTradingSimulationTradingSimulationFinalResultsPanel() { + + let thisObject = { + fitFunction: undefined, + onEventRaised: onEventRaised, + container: undefined, + draw: draw, + getContainer: getContainer, + initialize: initialize, + finalize: finalize + }; + + let container = newContainer(); + container.initialize(); + thisObject.container = container; + + container.displacement.containerName = "Final Results"; + container.frame.containerName = "Final Results"; + + let currentRecord; + let lastRecord; + let panelTabButton + + + return thisObject; + + function initialize() { + + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 2; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; + + thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 1; + thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; + + panelTabButton = newPanelTabButton() + panelTabButton.parentContainer = thisObject.container + panelTabButton.container.frame.parentFrame = thisObject.container.frame + panelTabButton.fitFunction = thisObject.fitFunction + panelTabButton.initialize() + + } + + function finalize() { + + } + + function getContainer(point) { + + let container; + + container = panelTabButton.getContainer(point) + if (container !== undefined) { return container } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + + let checkPoint = { + x: point.x, + y: point.y + } + + checkPoint = thisObject.fitFunction(checkPoint) + + if (point.x === checkPoint.x && point.y === checkPoint.y) { + return thisObject.container; + } + } + } + + + function onEventRaised(records) { + + currentRecord = records.currentRecord; + lastRecord = records.lastRecord + + } + + + function draw() { + + thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); + + plotCurrentRecordInfo(); + + panelTabButton.draw() + } + + + function plotCurrentRecordInfo() { + + if (currentRecord === undefined) { return; } + if (lastRecord === undefined) { return; } + + const frameBodyHeight = thisObject.container.frame.getBodyHeight(); + const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; + + const X_AXIS = thisObject.container.frame.width / 2; + const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; + + + /* put the labels with the records values */ + + browserCanvasContext.beginPath(); + + let y = 0; + let increment = 0.024; + + y = y + increment; + y = y + increment; + printLabel('Current Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); + + y = y + increment; + printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + y = y + increment; + printLabel('Latest Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); + + y = y + increment; + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + + + let bifurcationLevel = y + y = y + increment; + y = y + increment; + printLabel('Partial Results', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1', 14); + + y = y + increment; + printLabel('Profit / Loss', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.profit, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Trades', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.roundtrips, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Hits', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.hits, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Fails', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.fails, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Hit Ratio', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('ROI', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Periods', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.periods, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Days', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.days, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Anualized Rate of Return', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + + y = bifurcationLevel + + y = y + increment; + y = y + increment; + printLabel('Final Results', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1', 14); + + y = y + increment; + printLabel('Profit / Loss', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(lastRecord.profit, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Trades', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(lastRecord.roundtrips, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Hits', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(lastRecord.hits, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Fails', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(lastRecord.fails, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Hit Ratio', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((lastRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('ROI', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((lastRecord.ROI * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Periods', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(lastRecord.periods, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Days', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(lastRecord.days, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Anualized Rate of Return', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((lastRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + + + function printLabel(labelToPrint, x, y, opacity, fontSize) { + + let labelPoint; + if (fontSize === undefined) { fontSize = 10 }; + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY; + + let label = '' + labelToPrint; + if (isNaN(label) === false) { + label = Number(label).toLocaleString(); + if ((label === "-0" || label === "0") && (labelToPrint !== 0) && (labelToPrint !== "0.00")) { + label = Number(labelToPrint).toFixed(6); + } + } + let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + + labelPoint = { + x: x - xOffset, + y: y + }; + + labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); + labelPoint = thisObject.fitFunction(labelPoint) + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + + } + + browserCanvasContext.closePath(); + browserCanvasContext.fill(); + + /* Parameters */ + let params + let paramsArray = [] + let positionTaken = false + + if (currentRecord.positionSize > 0) { + positionTaken = true + } + + params = {} + params.VALUE = currentRecord.balanceA; + params.INIT_VALUE = currentRecord.initialBalanceA + params.MIN_VALUE = currentRecord.minimunBalanceA + params.MAX_VALUE = currentRecord.maximunBalanceA + params.ASSET_LABEL = 'Asset A' + params.ASSET_NAME = DEFAULT_MARKET.assetB + params.LEFT_OFFSET = 100 + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 4 + + paramsArray.push(params) + + params = {} + params.VALUE = currentRecord.balanceB; + params.MIN_VALUE = currentRecord.minimunBalanceB + params.INIT_VALUE = currentRecord.initialBalanceB + params.MAX_VALUE = currentRecord.maximunBalanceB + params.ASSET_LABEL = 'Asset B' + params.ASSET_NAME = DEFAULT_MARKET.assetA + params.LEFT_OFFSET = 220 + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 2 + + paramsArray.push(params) + + canvas.cockpitSpace.assetBalances.setParamsArray(paramsArray) + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Strategies.js b/Strategies.js index 6658032b9..77c5185d9 100644 --- a/Strategies.js +++ b/Strategies.js @@ -367,18 +367,7 @@ let lowerEnd = leftDate.valueOf(); let upperEnd = rightDate.valueOf(); - if (strategies.length > 0) { - - if (strategies[0].begin > lowerEnd || strategies[strategies.length - 1].end < upperEnd) { - - setTimeout(recalculate, 2000); - - //console.log("File missing while calculating strategies, scheduling a recalculation in 2 seconds."); - - } - } - - //console.log("Olivia > recalculateUsingDailyFiles > total strategies generated : " + strategies.length); + setTimeout(recalculate, 2000); } catch (err) { diff --git a/Trades.js b/Trades.js index e65132540..424aabb1b 100644 --- a/Trades.js +++ b/Trades.js @@ -354,18 +354,7 @@ let lowerEnd = leftDate.valueOf(); let upperEnd = rightDate.valueOf(); - if (trades.length > 0) { - - if (trades[0].begin > lowerEnd || trades[trades.length - 1].end < upperEnd) { - - setTimeout(recalculate, 2000); - - //console.log("File missing while calculating trades, scheduling a recalculation in 2 seconds."); - - } - } - - //console.log("Olivia > recalculateUsingDailyFiles > total trades generated : " + trades.length); + setTimeout(recalculate, 2000); } catch (err) { diff --git a/TradingSimulation.js b/TradingSimulation.js index 1e30b421d..6884ca2d5 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -371,18 +371,7 @@ let lowerEnd = leftDate.valueOf(); let upperEnd = rightDate.valueOf(); - if (records.length > 0) { - - if (records[0].begin > lowerEnd || records[records.length - 1].end < upperEnd) { - - setTimeout(recalculate, 2000); - - //console.log("File missing while calculating records, scheduling a recalculation in 2 seconds."); - - } - } - - //console.log("Olivia > recalculateUsingDailyFiles > total records generated : " + records.length); + setTimeout(recalculate, 2000); } catch (err) { From cdb47c22bb6d9dd2741328ead38f67162ee0314d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 24 Aug 2019 09:47:41 +0200 Subject: [PATCH 088/157] Removing last reults --- TradingSimulation.js | 3 +- TradingSimulationPanel.js | 99 +++++++++------------------------------ 2 files changed, 22 insertions(+), 80 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 6884ca2d5..eaf31f481 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -507,8 +507,7 @@ if (userPositionDate >= record.begin && userPositionDate <= record.end) { let eventRecords = { - currentRecord: record, - lastRecord: records[records.length - 1] + currentRecord: record }; thisObject.container.eventHandler.raiseEvent("Current Record Changed", eventRecords); } diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 0c685bc93..e93d16e0f 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -27,10 +27,10 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function initialize() { - thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 2; + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; - thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 1; + thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 3; thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; panelTabButton = newPanelTabButton() @@ -89,7 +89,6 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function plotCurrentRecordInfo() { if (currentRecord === undefined) { return; } - if (lastRecord === undefined) { return; } const frameBodyHeight = thisObject.container.frame.getBodyHeight(); const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; @@ -153,110 +152,54 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation y = y + increment; printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - - let bifurcationLevel = y y = y + increment; y = y + increment; - printLabel('Partial Results', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1', 14); + printLabel('Partial Results', X_AXIS , frameTitleHeight + frameBodyHeight * y, '1', 14); y = y + increment; - printLabel('Profit / Loss', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Profit / Loss', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.profit, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.profit, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Trades', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Trades', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.roundtrips, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.roundtrips, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Hits', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Hits', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.hits, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.hits, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Fails', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Fails', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.fails, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.fails, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Hit Ratio', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Hit Ratio', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('ROI', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('ROI', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Periods', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Periods', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.periods, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.periods, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Days', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Days', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel(currentRecord.days, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.days, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); y = y + increment; - printLabel('Anualized Rate of Return', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Anualized Rate of Return', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); y = y + increment; - printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - - y = bifurcationLevel - - y = y + increment; - y = y + increment; - printLabel('Final Results', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1', 14); - - y = y + increment; - printLabel('Profit / Loss', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.profit, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Trades', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.roundtrips, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Hits', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.hits, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Fails', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.fails, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Hit Ratio', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((lastRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('ROI', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((lastRecord.ROI * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Periods', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.periods, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Days', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.days, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Anualized Rate of Return', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((lastRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - + printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); function printLabel(labelToPrint, x, y, opacity, fontSize) { From fd2a28b59fc8760c361482889f9a6d44e781a669 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 24 Aug 2019 14:54:47 +0200 Subject: [PATCH 089/157] Parameters Slitted in 5 and details on trades --- Conditions.js | 12 +++++++++--- Trades.js | 41 +++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/Conditions.js b/Conditions.js index ae004c4ea..19330e420 100644 --- a/Conditions.js +++ b/Conditions.js @@ -534,9 +534,15 @@ canvas.strategySpace.workspace.definition.tradingSystem.parameters.payload.uiObject.setErrorMessage(tradingSystem.parameters.error) if (tradingSystem.parameters.baseAsset !== undefined) { canvas.strategySpace.workspace.definition.tradingSystem.parameters.baseAsset.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.error) - if (tradingSystem.parameters.baseAsset.formula !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.parameters.baseAsset.formula.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.formula.error) - } + } + if (tradingSystem.parameters.timeRange !== undefined) { + canvas.strategySpace.workspace.definition.tradingSystem.parameters.timeRange.payload.uiObject.setErrorMessage(tradingSystem.parameters.timeRange.error) + } + if (tradingSystem.parameters.slippage !== undefined) { + canvas.strategySpace.workspace.definition.tradingSystem.parameters.slippage.payload.uiObject.setErrorMessage(tradingSystem.parameters.slippage.error) + } + if (tradingSystem.parameters.feeStructure !== undefined) { + canvas.strategySpace.workspace.definition.tradingSystem.parameters.feeStructure.payload.uiObject.setErrorMessage(tradingSystem.parameters.feeStructure.error) } } diff --git a/Trades.js b/Trades.js index 424aabb1b..bf4220182 100644 --- a/Trades.js +++ b/Trades.js @@ -330,7 +330,6 @@ record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; record.exitType = dailyFile[i][6]; - record.stopRate = dailyFile[i][7]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -393,7 +392,6 @@ record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; record.exitType = marketFile[i][6]; - record.stopRate = marketFile[i][7]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -485,20 +483,13 @@ y: record.endRate }; - let recordPoint4 = { - x: record.end, - y: record.stopRate - }; - recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); - recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); - recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); if (recordPoint2.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { continue; @@ -507,29 +498,28 @@ recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); - recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); let line1 = ''; let line2 = ''; switch (record.exitType) { case 1: { - line1 = 'STOP'; + line1 = 'Exit: STOP'; break; } case 2: { - line1 = 'TP'; + line1 = 'Exit: TP'; break; } } if (record.lastTradeROI < 0) { - line2 = (record.lastTradeROI).toFixed(2) + ' %'; + line2 = 'ROI:' + (record.lastTradeROI).toFixed(2) + ' %'; } else { - line2 = (record.lastTradeROI).toFixed(2) + ' %'; + line2 = 'ROI:' + (record.lastTradeROI).toFixed(2) + ' %'; } /* Draw the triangle that represents the trade. */ @@ -562,21 +552,31 @@ browserCanvasContext.setLineDash([0, 0]) browserCanvasContext.stroke(); + let point = {} + + if (record.beginRate > record.endRate) { + point.x = recordPoint3.x + point.y = recordPoint3.y + 100 + } else { + point.x = recordPoint3.x + point.y = recordPoint3.y - 100 + } + if ( - recordPoint4.x < viewPort.visibleArea.topLeft.x + 250 + recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 || - recordPoint4.x > viewPort.visibleArea.bottomRight.x - 250 + recordPoint3.x > viewPort.visibleArea.bottomRight.x - 250 || - recordPoint4.y > viewPort.visibleArea.bottomRight.y - 100 + recordPoint3.y > viewPort.visibleArea.bottomRight.y - 150 || - recordPoint4.y < viewPort.visibleArea.topLeft.y + 100 + recordPoint3.y < viewPort.visibleArea.topLeft.y + 150 ) { // we do not write any text } else { - printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, recordPoint4.y - 30, '1', 12); - printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, recordPoint4.y - 15, '1', 12); + printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y, '1', 12); + printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, point.y + 15, '1', 12); } @@ -653,4 +653,5 @@ + From e65a2f0f537bd64254e6c3f771f3a854073eb39e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 22 Sep 2019 11:28:42 +0200 Subject: [PATCH 090/157] Daily Files Updated Events now Handled --- Conditions.js | 51 +++++++++++++++++++++++++++---------------- Strategies.js | 52 +++++++++++++++++++++++++++----------------- Trades.js | 51 +++++++++++++++++++++++++++---------------- TradingSimulation.js | 29 +++++++++++++++--------- 4 files changed, 115 insertions(+), 68 deletions(-) diff --git a/Conditions.js b/Conditions.js index 19330e420..959587c73 100644 --- a/Conditions.js +++ b/Conditions.js @@ -53,6 +53,13 @@ let noDefinitionOnFocusErrorDisplayed = false + let zoomChangedEventSubscriptionId + let offsetChangedEventSubscriptionId + let dragFinishedEventSubscriptionId + let dimmensionsChangedEventSubscriptionId + let marketFilesUpdatedEventSubscriptionId + let dailyFilesUpdatedEventSubscriptionId + return thisObject; function finalize() { @@ -62,11 +69,12 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening("Zoom Changed", onZoomChanged); - viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); - canvas.eventHandler.stopListening("Drag Finished", onDragFinished); - thisObject.container.eventHandler.stopListening('Dimmensions Changed') + viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); + viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); + thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) + marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); + dailyFiles.eventHandler.stopListening(dailyFilesUpdatedEventSubscriptionId); /* Destroyd References */ @@ -112,10 +120,11 @@ /* Listen to the necesary events. */ - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); + dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); /* Get ready for plotting. */ @@ -123,7 +132,7 @@ /* Ready for when dimmension changes. */ - thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { recalculateScale() recalculate(); }) @@ -163,23 +172,27 @@ } } - function onFilesUpdated() { - + function onMarketFilesUpdated() { try { - - if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } - let newMarketFile = marketFiles.getFile(timePeriod); - if (newMarketFile !== undefined) { - marketFile = newMarketFile; recalculate(); } - } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onMarketFilesUpdated -> err = " + err.stack); } + } + } - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } + function onDailyFilesUpdated() { + try { + let newFileCursor = dailyFiles.getFileCursor(timePeriod); + if (newFileCursor !== undefined) { + fileCursor = newFileCursor; + recalculate(); + } + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFilesUpdated -> err = " + err.stack); } } } diff --git a/Strategies.js b/Strategies.js index 77c5185d9..b868979bf 100644 --- a/Strategies.js +++ b/Strategies.js @@ -49,9 +49,15 @@ /* these are module specific variables: */ let strategies = []; - let strategyImages = []; + let zoomChangedEventSubscriptionId + let offsetChangedEventSubscriptionId + let dragFinishedEventSubscriptionId + let dimmensionsChangedEventSubscriptionId + let marketFilesUpdatedEventSubscriptionId + let dailyFilesUpdatedEventSubscriptionId + return thisObject; function finalize() { @@ -61,11 +67,12 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening("Zoom Changed", onZoomChanged); - viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); - canvas.eventHandler.stopListening("Drag Finished", onDragFinished); - thisObject.container.eventHandler.stopListening('Dimmensions Changed') + viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); + viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); + thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) + marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); + dailyFiles.eventHandler.stopListening(dailyFilesUpdatedEventSubscriptionId); /* Destroyd References */ @@ -113,10 +120,11 @@ /* Listen to the necesary events. */ - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); + dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); /* Get ready for plotting. */ @@ -124,7 +132,7 @@ /* Ready for when dimmension changes. */ - thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { recalculateScale() recalculate(); }) @@ -169,23 +177,27 @@ } } - function onFilesUpdated() { - + function onMarketFilesUpdated() { try { - - if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } - let newMarketFile = marketFiles.getFile(timePeriod); - if (newMarketFile !== undefined) { - marketFile = newMarketFile; recalculate(); } - } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onMarketFilesUpdated -> err = " + err.stack); } + } + } - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } + function onDailyFilesUpdated() { + try { + let newFileCursor = dailyFiles.getFileCursor(timePeriod); + if (newFileCursor !== undefined) { + fileCursor = newFileCursor; + recalculate(); + } + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFilesUpdated -> err = " + err.stack); } } } diff --git a/Trades.js b/Trades.js index bf4220182..a1a903e04 100644 --- a/Trades.js +++ b/Trades.js @@ -51,6 +51,13 @@ let trades = []; let headers; + let zoomChangedEventSubscriptionId + let offsetChangedEventSubscriptionId + let dragFinishedEventSubscriptionId + let dimmensionsChangedEventSubscriptionId + let marketFilesUpdatedEventSubscriptionId + let dailyFilesUpdatedEventSubscriptionId + return thisObject; function finalize() { @@ -60,11 +67,12 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening("Zoom Changed", onZoomChanged); - viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); - canvas.eventHandler.stopListening("Drag Finished", onDragFinished); - thisObject.container.eventHandler.stopListening('Dimmensions Changed') + viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); + viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); + thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) + marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); + dailyFiles.eventHandler.stopListening(dailyFilesUpdatedEventSubscriptionId); /* Destroyd References */ @@ -110,10 +118,11 @@ /* Listen to the necesary events. */ - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); + dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); /* Get ready for plotting. */ @@ -121,7 +130,7 @@ /* Ready for when dimmension changes. */ - thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { recalculateScale() recalculate(); }) @@ -161,23 +170,27 @@ } } - function onFilesUpdated() { - + function onMarketFilesUpdated() { try { - - if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } - let newMarketFile = marketFiles.getFile(timePeriod); - if (newMarketFile !== undefined) { - marketFile = newMarketFile; recalculate(); } - } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onMarketFilesUpdated -> err = " + err.stack); } + } + } - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } + function onDailyFilesUpdated() { + try { + let newFileCursor = dailyFiles.getFileCursor(timePeriod); + if (newFileCursor !== undefined) { + fileCursor = newFileCursor; + recalculate(); + } + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFilesUpdated -> err = " + err.stack); } } } diff --git a/TradingSimulation.js b/TradingSimulation.js index eaf31f481..a0579d2a2 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -55,9 +55,10 @@ let zoomChangedEventSubscriptionId let offsetChangedEventSubscriptionId - let filesUpdatedEventSubscriptionId let dragFinishedEventSubscriptionId let dimmensionsChangedEventSubscriptionId + let marketFilesUpdatedEventSubscriptionId + let dailyFilesUpdatedEventSubscriptionId return thisObject; @@ -68,9 +69,10 @@ viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); - marketFiles.eventHandler.stopListening(filesUpdatedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) + marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); + dailyFiles.eventHandler.stopListening(dailyFilesUpdatedEventSubscriptionId); /* icons */ @@ -122,8 +124,9 @@ zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - filesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); + dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); /* Get ready for plotting. */ @@ -161,21 +164,27 @@ } } - function onFilesUpdated() { - + function onMarketFilesUpdated() { try { - let newMarketFile = marketFiles.getFile(timePeriod); - if (newMarketFile !== undefined) { - marketFile = newMarketFile; recalculate(); } - } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onMarketFilesUpdated -> err = " + err.stack); } + } + } - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } + function onDailyFilesUpdated() { + try { + let newFileCursor = dailyFiles.getFileCursor(timePeriod); + if (newFileCursor !== undefined) { + fileCursor = newFileCursor; + recalculate(); + } + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFilesUpdated -> err = " + err.stack); } } } From a7c4f873f891a921eda044a30e22043eb782c158 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Sep 2019 09:34:23 +0200 Subject: [PATCH 091/157] Issue Fixed with stopLostPhase variable displaced --- TradingSimulation.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index a0579d2a2..80397fffc 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -521,8 +521,8 @@ thisObject.container.eventHandler.raiseEvent("Current Record Changed", eventRecords); } - let stopLossPhase = 0; - let takeProfitPhase = 0; + let stopLossPhase = -1; + let takeProfitPhase = -1; if (i > 0) { if (record.stopLossPhase !== records[i - 1].stopLossPhase) { @@ -740,9 +740,9 @@ browserCanvasContext.stroke() - if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > 0) { + if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > -1) { browserCanvasContext.drawImage(imageStopLossPhase, recordPoint6.x - imageSize, recordPoint6.y - imageSize * 1.25 + yOffset, imageSize, imageSize); - printLabel(stopLossPhase - 1, recordPoint6.x - imageSize / 2 - 3, recordPoint6.y - imageSize * 1.5 + yOffset * 2, '1', 9); + printLabel(stopLossPhase, recordPoint6.x - imageSize / 2 - 3, recordPoint6.y - imageSize * 1.5 + yOffset * 2, '1', 9); } /* Next we are drawing the Take Profit */ @@ -767,9 +767,9 @@ browserCanvasContext.lineWidth = 1 browserCanvasContext.stroke() - if (imageTakeProfitPhase.canDrawIcon === true && takeProfitPhase > 0) { + if (imageTakeProfitPhase.canDrawIcon === true && takeProfitPhase > -1) { browserCanvasContext.drawImage(imageTakeProfitPhase, recordPoint10.x - imageSize * 2 / 3, recordPoint10.y + imageSize / 4 - yOffset, imageSize, imageSize); - printLabel(takeProfitPhase - 1, recordPoint10.x - imageSize * 1 / 3, recordPoint10.y + imageSize * 1.9 - yOffset * 2, '1', 9); + printLabel(takeProfitPhase, recordPoint10.x - imageSize * 1 / 3, recordPoint10.y + imageSize * 1.9 - yOffset * 2, '1', 9); } } @@ -854,5 +854,6 @@ + From fa750d1158df6e2c9d577fb809e014c33a39dda8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 4 Oct 2019 21:21:50 +0200 Subject: [PATCH 092/157] cleaning --- TradingSimulation.js | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 80397fffc..bedc09101 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -820,40 +820,3 @@ } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 14800a83efc33b9fcd8f0be270ffc7055e1f4a4d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 6 Oct 2019 11:40:14 +0200 Subject: [PATCH 093/157] Adapting to no default Definition scheme --- Conditions.js | 155 ++++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 75 deletions(-) diff --git a/Conditions.js b/Conditions.js index 959587c73..1353eae7e 100644 --- a/Conditions.js +++ b/Conditions.js @@ -521,68 +521,73 @@ if (currentRecord === undefined) { return; } if (currentRecord.conditionsNames === undefined) { return; } if (canvas.strategySpace.workspace === undefined) { return; } - if (canvas.strategySpace.workspace.definition === undefined) { - if (noDefinitionOnFocusErrorDisplayed === false) { - if (ERROR_LOG === true) { logger.write("[WARN] sendRecordInfoToStrategySpace -> No Definition with Execution Focus."); } - noDefinitionOnFocusErrorDisplayed = true + + /* We will get now the designer trading system */ + let designerTradingSystem + let fileTradingSystem = currentRecord.conditionsNames; + + for (let i = 0; i < canvas.strategySpace.workspace.workspaceNode.rootNodes.length; i++) { + let rootNode = canvas.strategySpace.workspace.workspaceNode.rootNodes[i] + if (rootNode.type === 'Definition') { + if (rootNode.tradingSystem.id === fileTradingSystem.id) { + designerTradingSystem = rootNode.tradingSystem + } } - return - } else { - noDefinitionOnFocusErrorDisplayed = false } - if (canvas.strategySpace.workspace.definition.tradingSystem === undefined) { return; } + + if (designerTradingSystem === undefined) { return; } try { browserCanvasContext.beginPath(); - let tradingSystem = currentRecord.conditionsNames; + let conditionIndex = 0; let formulaErrorsIndex = 0; let formulaValuesIndex = 0; - canvas.strategySpace.workspace.definition.tradingSystem.payload.uiObject.setErrorMessage(tradingSystem.error) + designerTradingSystem.payload.uiObject.setErrorMessage(fileTradingSystem.error) - if (tradingSystem.parameters !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.parameters.payload.uiObject.setErrorMessage(tradingSystem.parameters.error) - if (tradingSystem.parameters.baseAsset !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.parameters.baseAsset.payload.uiObject.setErrorMessage(tradingSystem.parameters.baseAsset.error) + if (fileTradingSystem.parameters !== undefined) { + designerTradingSystem.parameters.payload.uiObject.setErrorMessage(fileTradingSystem.parameters.error) + if (fileTradingSystem.parameters.baseAsset !== undefined) { + designerTradingSystem.parameters.baseAsset.payload.uiObject.setErrorMessage(fileTradingSystem.parameters.baseAsset.error) } - if (tradingSystem.parameters.timeRange !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.parameters.timeRange.payload.uiObject.setErrorMessage(tradingSystem.parameters.timeRange.error) + if (fileTradingSystem.parameters.timeRange !== undefined) { + designerTradingSystem.parameters.timeRange.payload.uiObject.setErrorMessage(fileTradingSystem.parameters.timeRange.error) } - if (tradingSystem.parameters.slippage !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.parameters.slippage.payload.uiObject.setErrorMessage(tradingSystem.parameters.slippage.error) + if (fileTradingSystem.parameters.slippage !== undefined) { + designerTradingSystem.parameters.slippage.payload.uiObject.setErrorMessage(fileTradingSystem.parameters.slippage.error) } - if (tradingSystem.parameters.feeStructure !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.parameters.feeStructure.payload.uiObject.setErrorMessage(tradingSystem.parameters.feeStructure.error) + if (fileTradingSystem.parameters.feeStructure !== undefined) { + designerTradingSystem.parameters.feeStructure.payload.uiObject.setErrorMessage(fileTradingSystem.parameters.feeStructure.error) } } - for (let j = 0; j < tradingSystem.strategies.length; j++) { + for (let j = 0; j < fileTradingSystem.strategies.length; j++) { - let strategy = tradingSystem.strategies[j]; - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].payload.uiObject.setErrorMessage(strategy.error) + let strategy = fileTradingSystem.strategies[j]; + designerTradingSystem.strategies[j].payload.uiObject.setErrorMessage(strategy.error) if (currentRecord.strategyNumber === j) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].payload.uiObject.isExecuting = true + designerTradingSystem.strategies[j].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].payload.uiObject.isExecuting = false + designerTradingSystem.strategies[j].payload.uiObject.isExecuting = false } let triggerStage = strategy.triggerStage if (triggerStage !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.payload.uiObject.setErrorMessage(triggerStage.error) + designerTradingSystem.strategies[j].triggerStage.payload.uiObject.setErrorMessage(triggerStage.error) if (triggerStage.triggerOn !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOn.payload.uiObject.setErrorMessage(triggerStage.triggerOn.error) + designerTradingSystem.strategies[j].triggerStage.triggerOn.payload.uiObject.setErrorMessage(triggerStage.triggerOn.error) for (let k = 0; k < triggerStage.triggerOn.situations.length; k++) { let situation = triggerStage.triggerOn.situations[k]; - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOn.situations[k].error) - processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOn.situations[k]); + designerTradingSystem.strategies[j].triggerStage.triggerOn.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOn.situations[k].error) + processSituation(situation, designerTradingSystem.strategies[j].triggerStage.triggerOn.situations[k]); } } @@ -591,8 +596,8 @@ for (let k = 0; k < triggerStage.triggerOff.situations.length; k++) { let situation = triggerStage.triggerOff.situations[k]; - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOff.situations[k].error) - processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.triggerOff.situations[k]); + designerTradingSystem.strategies[j].triggerStage.triggerOff.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOff.situations[k].error) + processSituation(situation, designerTradingSystem.strategies[j].triggerStage.triggerOff.situations[k]); } } @@ -601,8 +606,8 @@ for (let k = 0; k < triggerStage.takePosition.situations.length; k++) { let situation = triggerStage.takePosition.situations[k]; - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.takePosition.situations[k].payload.uiObject.setErrorMessage(triggerStage.takePosition.situations[k].error) - processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].triggerStage.takePosition.situations[k]); + designerTradingSystem.strategies[j].triggerStage.takePosition.situations[k].payload.uiObject.setErrorMessage(triggerStage.takePosition.situations[k].error) + processSituation(situation, designerTradingSystem.strategies[j].triggerStage.takePosition.situations[k]); } } } @@ -610,96 +615,96 @@ let openStage = strategy.openStage if (openStage !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.payload.uiObject.setErrorMessage(openStage.error) + designerTradingSystem.strategies[j].openStage.payload.uiObject.setErrorMessage(openStage.error) let initialDefinition = openStage.initialDefinition if (initialDefinition !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.payload.uiObject.setErrorMessage(openStage.initialDefinition.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.payload.uiObject.setErrorMessage(openStage.initialDefinition.error) if (initialDefinition.stopLoss !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.error) for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false } let phase = initialDefinition.stopLoss.phases[p]; - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].error) + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].error) if (phase.formula !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.error) for (let k = 0; k < nextPhaseEvent.situations.length; k++) { let situation = nextPhaseEvent.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.situations[k]); + processSituation(situation, designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.situations[k]); } } } } if (initialDefinition.takeProfit !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.error) for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false } let phase = initialDefinition.takeProfit.phases[p]; - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].error) + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].error) if (phase.formula !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.error) for (let k = 0; k < nextPhaseEvent.situations.length; k++) { let situation = nextPhaseEvent.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.situations[k]); + processSituation(situation, designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.situations[k]); } } } @@ -709,97 +714,97 @@ let openExecution = openStage.openExecution if (openExecution !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].openStage.openExecution.payload.uiObject.setErrorMessage(openStage.openExecution.error) + designerTradingSystem.strategies[j].openStage.openExecution.payload.uiObject.setErrorMessage(openStage.openExecution.error) } } let manageStage = strategy.manageStage if (manageStage !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.payload.uiObject.setErrorMessage(manageStage.error) + designerTradingSystem.strategies[j].manageStage.payload.uiObject.setErrorMessage(manageStage.error) if (manageStage.stopLoss !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.payload.uiObject.setErrorMessage(manageStage.stopLoss.error) + designerTradingSystem.strategies[j].manageStage.stopLoss.payload.uiObject.setErrorMessage(manageStage.stopLoss.error) for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false } let phase = manageStage.stopLoss.phases[p]; - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].error) + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].error) if (phase.formula !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].nextPhaseEvent.error) + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].nextPhaseEvent.error) for (let k = 0; k < nextPhaseEvent.situations.length; k++) { let situation = nextPhaseEvent.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.situations[k]); + processSituation(situation, designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.situations[k]); } } } } if (manageStage.takeProfit !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.payload.uiObject.setErrorMessage(manageStage.takeProfit.error) + designerTradingSystem.strategies[j].manageStage.takeProfit.payload.uiObject.setErrorMessage(manageStage.takeProfit.error) for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false } let phase = manageStage.takeProfit.phases[p]; - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].error) + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].error) if (phase.formula !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].nextPhaseEvent.error) + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].nextPhaseEvent.error) for (let k = 0; k < nextPhaseEvent.situations.length; k++) { let situation = nextPhaseEvent.situations[k]; - processSituation(situation, canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.situations[k]); + processSituation(situation, designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.situations[k]); } } } @@ -810,12 +815,12 @@ let closeStage = strategy.closeStage if (closeStage !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].closeStage.payload.uiObject.setErrorMessage(closeStage.error) + designerTradingSystem.strategies[j].closeStage.payload.uiObject.setErrorMessage(closeStage.error) let closeExecution = closeStage.closeExecution if (closeExecution !== undefined) { - canvas.strategySpace.workspace.definition.tradingSystem.strategies[j].closeStage.closeExecution.payload.uiObject.setErrorMessage(closeStage.closeExecution.error) + designerTradingSystem.strategies[j].closeStage.closeExecution.payload.uiObject.setErrorMessage(closeStage.closeExecution.error) } } } From 1f84f7719ecf6e738db057462abfce4ff33954e4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 6 Oct 2019 16:03:56 +0200 Subject: [PATCH 094/157] Bug Fixed --- Conditions.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Conditions.js b/Conditions.js index 1353eae7e..2dc5a3552 100644 --- a/Conditions.js +++ b/Conditions.js @@ -541,7 +541,7 @@ browserCanvasContext.beginPath(); - + let conditionIndex = 0; let formulaErrorsIndex = 0; let formulaValuesIndex = 0; @@ -627,7 +627,7 @@ for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -640,13 +640,13 @@ designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -671,7 +671,7 @@ for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -684,13 +684,13 @@ designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -728,7 +728,7 @@ for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -741,12 +741,12 @@ designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 2 === p) { + if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -771,7 +771,7 @@ for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -784,13 +784,13 @@ designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 2 === p) { + if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ From 68f02bce88e9a95ff6d4c0909691b0c978ab2741 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 10 Oct 2019 16:18:19 +0200 Subject: [PATCH 095/157] latests objects cleaned --- Conditions.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/Conditions.js b/Conditions.js index 2dc5a3552..88e4e712d 100644 --- a/Conditions.js +++ b/Conditions.js @@ -336,7 +336,7 @@ headers = dailyFile[0]; - for (let i = 0; i < dailyFile[2].length; i++) { + for (let i = 0; i < dailyFile[1].length; i++) { let record = { begin: undefined, @@ -344,15 +344,15 @@ conditions: undefined }; - record.begin = dailyFile[2][i][0]; - record.end = dailyFile[2][i][1]; - record.strategyNumber = dailyFile[2][i][2]; - record.strategyPhase = dailyFile[2][i][3]; - record.stopLossPhase = dailyFile[2][i][4]; - record.takeProfitPhase = dailyFile[2][i][5]; - record.conditions = dailyFile[2][i][6]; - record.formulaErrors = dailyFile[2][i][7]; - record.formulaValues = dailyFile[2][i][8]; + record.begin = dailyFile[1][i][0]; + record.end = dailyFile[1][i][1]; + record.strategyNumber = dailyFile[1][i][2]; + record.strategyPhase = dailyFile[1][i][3]; + record.stopLossPhase = dailyFile[1][i][4]; + record.takeProfitPhase = dailyFile[1][i][5]; + record.conditions = dailyFile[1][i][6]; + record.formulaErrors = dailyFile[1][i][7]; + record.formulaValues = dailyFile[1][i][8]; if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { @@ -404,9 +404,8 @@ conditions = []; headers = marketFile[0]; - let lastObjects = marketFile[1]; // Here we get the values of the last 5 objects - for (let i = 0; i < marketFile[2].length; i++) { + for (let i = 0; i < marketFile[1].length; i++) { let record = { begin: undefined, @@ -414,15 +413,15 @@ conditions: undefined }; - record.begin = marketFile[2][i][0]; - record.end = marketFile[2][i][1]; - record.strategyNumber = marketFile[2][i][2]; - record.strategyPhase = marketFile[2][i][3]; - record.stopLossPhase = marketFile[2][i][4]; - record.takeProfitPhase = marketFile[2][i][5]; - record.conditions = marketFile[2][i][6]; - record.formulaErrors = marketFile[2][i][7]; - record.formulaValues = marketFile[2][i][8]; + record.begin = marketFile[1][i][0]; + record.end = marketFile[1][i][1]; + record.strategyNumber = marketFile[1][i][2]; + record.strategyPhase = marketFile[1][i][3]; + record.stopLossPhase = marketFile[1][i][4]; + record.takeProfitPhase = marketFile[1][i][5]; + record.conditions = marketFile[1][i][6]; + record.formulaErrors = marketFile[1][i][7]; + record.formulaValues = marketFile[1][i][8]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { From 6687336a278a076e963c03d33f7d96617bd18b15 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 16 Oct 2019 19:45:11 +0200 Subject: [PATCH 096/157] Session name as pannel name --- TradingSimulationPanel.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index e93d16e0f..d7811c9d2 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -5,6 +5,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation fitFunction: undefined, onEventRaised: onEventRaised, container: undefined, + session: undefined, draw: draw, getContainer: getContainer, initialize: initialize, @@ -15,8 +16,8 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation container.initialize(); thisObject.container = container; - container.displacement.containerName = "Trading Simulation"; - container.frame.containerName = "Trading Simulation"; + container.displacement.containerName = "Simulation"; + container.frame.containerName = "Simulation"; let currentRecord; let lastRecord; @@ -42,7 +43,16 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation } function finalize() { + thisObject.session = undefined + thisObject.container.finalize() + thisObject.container = undefined + thisObject.fitFunction = undefined + thisObject.onEventRaised = undefined + + currentRecord = undefined + lastRecord = undefined + panelTabButton = undefined } function getContainer(point) { @@ -83,6 +93,16 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation plotCurrentRecordInfo(); panelTabButton.draw() + + /* Define panel name */ + if (thisObject.session !== undefined) { + const MAX_LABEL_LENGTH = 25 + if (thisObject.session.name.length > MAX_LABEL_LENGTH) { + container.frame.containerName = thisObject.session.name.substring(0, MAX_LABEL_LENGTH) + '...' + } else { + container.frame.containerName = thisObject.session.name + } + } } From c703c1a07ac21954c92abbfcae9bd85ad2fb4701 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 17 Oct 2019 22:20:35 +0200 Subject: [PATCH 097/157] forced recalculation impleneted --- Conditions.js | 9 +++++++-- Strategies.js | 9 +++++++-- Trades.js | 9 +++++++-- TradingSimulation.js | 9 +++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Conditions.js b/Conditions.js index 88e4e712d..a6757a16d 100644 --- a/Conditions.js +++ b/Conditions.js @@ -881,14 +881,19 @@ } } - function onOffsetChanged() { + function onOffsetChanged(event) { try { if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + if (event !== undefined) { + if (event.recalculate === true) { + recalculate() + return + } + } if (Math.random() * 100 > 95) { - recalculate() }; diff --git a/Strategies.js b/Strategies.js index b868979bf..d793b4a37 100644 --- a/Strategies.js +++ b/Strategies.js @@ -619,14 +619,19 @@ } } - function onOffsetChanged() { + function onOffsetChanged(event) { try { if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + if (event !== undefined) { + if (event.recalculate === true) { + recalculate() + return + } + } if (Math.random() * 100 > 95) { - recalculate() }; diff --git a/Trades.js b/Trades.js index a1a903e04..a27f5e76f 100644 --- a/Trades.js +++ b/Trades.js @@ -616,14 +616,19 @@ } } - function onOffsetChanged() { + function onOffsetChanged(event) { try { if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + if (event !== undefined) { + if (event.recalculate === true) { + recalculate() + return + } + } if (Math.random() * 100 > 95) { - recalculate() }; diff --git a/TradingSimulation.js b/TradingSimulation.js index bedc09101..f8f5ba370 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -792,12 +792,17 @@ } } - function onOffsetChanged() { + function onOffsetChanged(event) { try { + if (event !== undefined) { + if (event.recalculate === true) { + recalculate() + return + } + } if (Math.random() * 100 > 95) { - recalculate() }; From b4a1c7bc80687da733f7cbe5e086079412bbf0f5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 21 Oct 2019 09:24:58 +0200 Subject: [PATCH 098/157] Reporting Errors at Announcement Formulas --- Conditions.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Conditions.js b/Conditions.js index a6757a16d..de1e4b9bb 100644 --- a/Conditions.js +++ b/Conditions.js @@ -588,6 +588,15 @@ designerTradingSystem.strategies[j].triggerStage.triggerOn.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOn.situations[k].error) processSituation(situation, designerTradingSystem.strategies[j].triggerStage.triggerOn.situations[k]); } + + for (let k = 0; k < triggerStage.triggerOn.announcements.length; k++) { + + let announcement = triggerStage.triggerOn.announcements[k]; + designerTradingSystem.strategies[j].triggerStage.triggerOn.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].triggerStage.triggerOn.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } } if (triggerStage.triggerOff !== undefined) { @@ -598,6 +607,15 @@ designerTradingSystem.strategies[j].triggerStage.triggerOff.situations[k].payload.uiObject.setErrorMessage(triggerStage.triggerOff.situations[k].error) processSituation(situation, designerTradingSystem.strategies[j].triggerStage.triggerOff.situations[k]); } + + for (let k = 0; k < triggerStage.triggerOff.announcements.length; k++) { + + let announcement = triggerStage.triggerOff.announcements[k]; + designerTradingSystem.strategies[j].triggerStage.triggerOff.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].triggerStage.triggerOff.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } } if (triggerStage.takePosition !== undefined) { @@ -608,6 +626,15 @@ designerTradingSystem.strategies[j].triggerStage.takePosition.situations[k].payload.uiObject.setErrorMessage(triggerStage.takePosition.situations[k].error) processSituation(situation, designerTradingSystem.strategies[j].triggerStage.takePosition.situations[k]); } + + for (let k = 0; k < triggerStage.takePosition.announcements.length; k++) { + + let announcement = triggerStage.takePosition.announcements[k]; + designerTradingSystem.strategies[j].triggerStage.takePosition.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].triggerStage.takePosition.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } } } @@ -661,6 +688,15 @@ processSituation(situation, designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.situations[k]); } + + for (let k = 0; k < nextPhaseEvent.announcements.length; k++) { + + let announcement = nextPhaseEvent.announcements[k]; + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } } } } @@ -705,6 +741,15 @@ processSituation(situation, designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.situations[k]); } + + for (let k = 0; k < nextPhaseEvent.announcements.length; k++) { + + let announcement = nextPhaseEvent.announcements[k]; + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } } } } @@ -761,6 +806,15 @@ processSituation(situation, designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.situations[k]); } + + for (let k = 0; k < nextPhaseEvent.announcements.length; k++) { + + let announcement = nextPhaseEvent.announcements[k]; + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } } } } @@ -805,6 +859,15 @@ processSituation(situation, designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.situations[k]); } + + for (let k = 0; k < nextPhaseEvent.announcements.length; k++) { + + let announcement = nextPhaseEvent.announcements[k]; + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } } } } From d8af112c7dafa20f329846499868cdf427a10b15 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 21 Oct 2019 14:24:21 +0200 Subject: [PATCH 099/157] Error in Phases Announcements --- Conditions.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Conditions.js b/Conditions.js index de1e4b9bb..4a7c04172 100644 --- a/Conditions.js +++ b/Conditions.js @@ -678,6 +678,15 @@ formulaValuesIndex++ } + for (let k = 0; k < phase.announcements.length; k++) { + + let announcement = phase.announcements[k]; + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } + let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].nextPhaseEvent.error) @@ -731,6 +740,15 @@ formulaValuesIndex++ } + for (let k = 0; k < phase.announcements.length; k++) { + + let announcement = phase.announcements[k]; + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } + let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].nextPhaseEvent.error) @@ -796,6 +814,15 @@ formulaValuesIndex++ } + for (let k = 0; k < phase.announcements.length; k++) { + + let announcement = phase.announcements[k]; + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } + let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].nextPhaseEvent.error) @@ -849,6 +876,15 @@ formulaValuesIndex++ } + for (let k = 0; k < phase.announcements.length; k++) { + + let announcement = phase.announcements[k]; + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } + let nextPhaseEvent = phase.nextPhaseEvent; if (nextPhaseEvent !== undefined) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].nextPhaseEvent.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].nextPhaseEvent.error) From e73f6d74f1e8692a72ac084a62640cfc23d7bd80 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 21 Oct 2019 17:15:42 +0200 Subject: [PATCH 100/157] Bug Fixed --- Conditions.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Conditions.js b/Conditions.js index 4a7c04172..41aa6df7e 100644 --- a/Conditions.js +++ b/Conditions.js @@ -681,9 +681,9 @@ for (let k = 0; k < phase.announcements.length; k++) { let announcement = phase.announcements[k]; - designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].announcements[k].payload.uiObject.setErrorMessage(announcement.error) if (announcement.formula !== undefined) { - designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) } } @@ -743,9 +743,9 @@ for (let k = 0; k < phase.announcements.length; k++) { let announcement = phase.announcements[k]; - designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].announcements[k].payload.uiObject.setErrorMessage(announcement.error) if (announcement.formula !== undefined) { - designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) } } @@ -817,9 +817,9 @@ for (let k = 0; k < phase.announcements.length; k++) { let announcement = phase.announcements[k]; - designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].announcements[k].payload.uiObject.setErrorMessage(announcement.error) if (announcement.formula !== undefined) { - designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) } } @@ -879,9 +879,9 @@ for (let k = 0; k < phase.announcements.length; k++) { let announcement = phase.announcements[k]; - designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.announcements[k].payload.uiObject.setErrorMessage(announcement.error) + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].announcements[k].payload.uiObject.setErrorMessage(announcement.error) if (announcement.formula !== undefined) { - designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) } } From aaa732e4fe5bd2ffc918aed87ee238f5d996ce4d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 27 Oct 2019 14:00:06 +0100 Subject: [PATCH 101/157] part to uiObject refactoring --- Conditions.js | 12 ++++++------ TradingSimulation.js | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Conditions.js b/Conditions.js index 41aa6df7e..8f75cc453 100644 --- a/Conditions.js +++ b/Conditions.js @@ -505,7 +505,7 @@ formulaValues: conditionRecord.formulaValues }; - sendRecordInfoToStrategySpace(currentRecord) + sendRecordInfoToDesignerSpace(currentRecord) } } @@ -515,18 +515,18 @@ } } - function sendRecordInfoToStrategySpace(currentRecord) { + function sendRecordInfoToDesignerSpace(currentRecord) { if (currentRecord === undefined) { return; } if (currentRecord.conditionsNames === undefined) { return; } - if (canvas.strategySpace.workspace === undefined) { return; } + if (canvas.designerSpace.workspace === undefined) { return; } /* We will get now the designer trading system */ let designerTradingSystem let fileTradingSystem = currentRecord.conditionsNames; - for (let i = 0; i < canvas.strategySpace.workspace.workspaceNode.rootNodes.length; i++) { - let rootNode = canvas.strategySpace.workspace.workspaceNode.rootNodes[i] + for (let i = 0; i < canvas.designerSpace.workspace.workspaceNode.rootNodes.length; i++) { + let rootNode = canvas.designerSpace.workspace.workspaceNode.rootNodes[i] if (rootNode.type === 'Definition') { if (rootNode.tradingSystem.id === fileTradingSystem.id) { designerTradingSystem = rootNode.tradingSystem @@ -960,7 +960,7 @@ browserCanvasContext.fill(); } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] sendRecordInfoToStrategySpace -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] sendRecordInfoToDesignerSpace -> err = " + err.stack); } } } diff --git a/TradingSimulation.js b/TradingSimulation.js index f8f5ba370..8313fdefb 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -141,9 +141,9 @@ /* Loading a few icons */ - imageStopLossPhase = canvas.strategySpace.iconByPartType.get('Stop'); - imageTakeProfitPhase = canvas.strategySpace.iconByPartType.get('Phase'); - imageRecord = canvas.strategySpace.iconByPartType.get('Trading System'); + imageStopLossPhase = canvas.designerSpace.iconByUiObjectType.get('Stop'); + imageTakeProfitPhase = canvas.designerSpace.iconByUiObjectType.get('Phase'); + imageRecord = canvas.designerSpace.iconByUiObjectType.get('Trading System'); callBackFunction(); From ad61de829293913bd8cbb30af7d5ff6a39f06ed3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 5 Nov 2019 14:31:07 +0100 Subject: [PATCH 102/157] Designer refactoring --- Strategies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Strategies.js b/Strategies.js index d793b4a37..9c1951e90 100644 --- a/Strategies.js +++ b/Strategies.js @@ -138,7 +138,7 @@ }) for (let i = 1; i < 15; i++) { - let strategyImage = canvas.strategySpace.iconByPartType.get('Strategy'); + let strategyImage = canvas.designerSpace.iconByUiObjectType.get('Strategy'); strategyImages.push(strategyImage); } From eb61498176d107185f95e507b01dfcfe0131ec15 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Nov 2019 18:34:48 +0100 Subject: [PATCH 103/157] Open strategies and trades --- Strategies.js | 10 +++++++--- Trades.js | 23 ++++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Strategies.js b/Strategies.js index 9c1951e90..50cf96a80 100644 --- a/Strategies.js +++ b/Strategies.js @@ -536,7 +536,7 @@ let imageSize = 20; let imageToDraw = strategyImages[record.number]; - if (record.status === 1) { + /* Draw the line that represents the duration of closed strategy */ browserCanvasContext.beginPath(); @@ -549,9 +549,13 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; browserCanvasContext.lineWidth = 1 - browserCanvasContext.setLineDash([0, 0]) + if (record.status === 1) { + browserCanvasContext.setLineDash([0, 0]) + } else { + browserCanvasContext.setLineDash([2, 4]) + } browserCanvasContext.stroke() - } + drawStick(recordPoint1, recordPoint3); diff --git a/Trades.js b/Trades.js index a27f5e76f..b38093e0a 100644 --- a/Trades.js +++ b/Trades.js @@ -515,23 +515,24 @@ let line1 = ''; let line2 = ''; - switch (record.exitType) { - case 1: { - line1 = 'Exit: STOP'; - break; - } - case 2: { - line1 = 'Exit: TP'; - break; + if (record.status === 1) { + switch (record.exitType) { + case 1: { + line1 = 'Exit: STOP'; + break; + } + case 2: { + line1 = 'Exit: TP'; + break; + } } + } else { + line1 = 'Open Position'; } if (record.lastTradeROI < 0) { - line2 = 'ROI:' + (record.lastTradeROI).toFixed(2) + ' %'; - } else { - line2 = 'ROI:' + (record.lastTradeROI).toFixed(2) + ' %'; } From 98352cbfc6164d23ffd0599f545d3f2c6f9e0dd3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Dec 2019 10:45:57 +0100 Subject: [PATCH 104/157] Data Mine Refactoring --- this.plotter.config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/this.plotter.config.json b/this.plotter.config.json index 9505e5005..d1c9d6830 100644 --- a/this.plotter.config.json +++ b/this.plotter.config.json @@ -1,7 +1,7 @@ { "displayName": "Plotters Trading Simulation", "codeName": "PlottersTradingSimulation", - "devTeam": "AAMasters", + "dataMine": "AAMasters", "modules": [ { "codeName": "TradingSimulation", From 5438a867b8656493b4db265a5637540021cf10c6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Dec 2019 13:27:59 +0100 Subject: [PATCH 105/157] Time Frame Refectoring --- Conditions.js | 42 ++++++++++++++++---------------- SimulationExecution.js | 46 +++++++++++++++++------------------ SimulationExecutionPanel.js | 16 ++++++------- Strategies.js | 42 ++++++++++++++++---------------- Trades.js | 42 ++++++++++++++++---------------- TradingSimulation.js | 48 ++++++++++++++++++------------------- 6 files changed, 118 insertions(+), 118 deletions(-) diff --git a/Conditions.js b/Conditions.js index 8f75cc453..ca66bc756 100644 --- a/Conditions.js +++ b/Conditions.js @@ -15,7 +15,7 @@ finalize: finalize, container: undefined, getContainer: getContainer, - setTimePeriod: setTimePeriod, + setTimeFrame: setTimeFrame, setDatetime: setDatetime, draw: draw, recalculateScale: recalculateScale, @@ -37,14 +37,14 @@ let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. - let timePeriod; // This will hold the current Time Period the user is at. + let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. let marketFile; // This is the current Market File being plotted. let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. - let marketFiles; // This object will provide the different Market Files at different Time Periods. - let dailyFiles; // This object will provide the different File Cursors at different Time Periods. + let marketFiles; // This object will provide the different Market Files at different Time Frames. + let dailyFiles; // This object will provide the different File Cursors at different Time Frames. /* these are module specific variables: */ @@ -82,7 +82,7 @@ dailyFiles = undefined; datetime = undefined; - timePeriod = undefined; + timeFrame = undefined; marketFile = undefined; fileCursor = undefined; @@ -93,7 +93,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { try { @@ -105,7 +105,7 @@ dailyFiles = pStorage.dailyFiles[0]; datetime = pDatetime; - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -115,8 +115,8 @@ /* Now we set the right files according to current Period. */ - marketFile = marketFiles.getFile(pTimePeriod); - fileCursor = dailyFiles.getFileCursor(pTimePeriod); + marketFile = marketFiles.getFile(pTimeFrame); + fileCursor = dailyFiles.getFileCursor(pTimeFrame); /* Listen to the necesary events. */ @@ -174,7 +174,7 @@ function onMarketFilesUpdated() { try { - let newMarketFile = marketFiles.getFile(timePeriod); + let newMarketFile = marketFiles.getFile(timeFrame); if (newMarketFile !== undefined) { marketFile = newMarketFile; recalculate(); @@ -186,7 +186,7 @@ function onDailyFilesUpdated() { try { - let newFileCursor = dailyFiles.getFileCursor(timePeriod); + let newFileCursor = dailyFiles.getFileCursor(timeFrame); if (newFileCursor !== undefined) { fileCursor = newFileCursor; recalculate(); @@ -196,23 +196,23 @@ } } - function setTimePeriod(pTimePeriod) { + function setTimeFrame(pTimeFrame) { try { - if (timePeriod !== pTimePeriod) { + if (timeFrame !== pTimeFrame) { - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timeFrame >= _1_HOUR_IN_MILISECONDS) { - marketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimeFrame); recalculate(); } else { - let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + let newFileCursor = dailyFiles.getFileCursor(pTimeFrame); fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. recalculate(); @@ -222,7 +222,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] setTimeFrame -> err = " + err.stack); } } } @@ -276,7 +276,7 @@ conditions = [] - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timeFrame >= _1_HOUR_IN_MILISECONDS) { recalculateUsingMarketFiles(); @@ -310,7 +310,7 @@ return; } // We need to wait until there are files in the cursor - let daysOnSides = getSideDays(timePeriod); + let daysOnSides = getSideDays(timeFrame); let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); @@ -392,7 +392,7 @@ if (marketFile === undefined) { return; } // Initialization not complete yet. - let daysOnSides = getSideDays(timePeriod); + let daysOnSides = getSideDays(timeFrame); let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); diff --git a/SimulationExecution.js b/SimulationExecution.js index 566c409e4..315e2ede8 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -14,7 +14,7 @@ finalize: finalize, container: undefined, getContainer: getContainer, - setTimePeriod: setTimePeriod, + setTimeFrame: setTimeFrame, setDatetime: setDatetime, recalculateScale: recalculateScale, draw: draw @@ -28,7 +28,7 @@ let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. - let timePeriod; // This will hold the current Time Period the user is at. + let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. /* these are module specific variables: */ @@ -57,7 +57,7 @@ /* Destroyd References */ datetime = undefined; - timePeriod = undefined; + timeFrame = undefined; fileSequence = undefined; plotElements = undefined; @@ -68,12 +68,12 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { try { datetime = pDatetime; - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; fileSequence = pStorage.fileSequences[0]; @@ -116,8 +116,8 @@ recalculate(); } - function setTimePeriod(pTimePeriod) { - timePeriod = pTimePeriod; + function setTimeFrame(pTimeFrame) { + timeFrame = pTimeFrame; recalculate(); } @@ -136,7 +136,7 @@ if (fileSequence === undefined) { return; } /* - We are going to filter the records depending on the Time Period. We want that for a 1 min time peroid all the records appears on screen, + We are going to filter the records depending on the Time Frame. We want that for a 1 min time peroid all the records appears on screen, but for higher periods, we will filter out some records, so that they do not overlap ever. */ @@ -163,7 +163,7 @@ /* First the small balls */ const ONE_MIN_IN_MILISECONDS = 60 * 1000; - let step = timePeriod / ONE_MIN_IN_MILISECONDS; + let step = timeFrame / ONE_MIN_IN_MILISECONDS; step = 1; // For now we dont discard records depending on the zoom level. let i = 0; @@ -200,7 +200,7 @@ /* Here we build the lines. */ - //if (timePeriod <= 1 * 60 * 1000) { + //if (timeFrame <= 1 * 60 * 1000) { if (newHistoryRecord.lastSellRate > 0) { lastSellRate = newHistoryRecord.lastSellRate; @@ -359,7 +359,7 @@ record = history[i]; currentRecord = record - let timestamp = record.date // Math.trunc(record.date / timePeriod) * timePeriod + timePeriod / 2; + let timestamp = record.date // Math.trunc(record.date / timeFrame) * timeFrame + timeFrame / 2; point = { x: timestamp, @@ -397,12 +397,12 @@ }; let point2 = { - x: record.date + timePeriod / 7 * (normalSize + extraSize), + x: record.date + timeFrame / 7 * (normalSize + extraSize), y: record.sellExecRate }; let point3 = { - x: record.date - timePeriod / 7 * (normalSize + extraSize), + x: record.date - timeFrame / 7 * (normalSize + extraSize), y: record.sellExecRate }; @@ -422,7 +422,7 @@ point2.y = point2.y - diff; point3.y = point3.y - diff; - currentRecord.timePeriod = diff + currentRecord.timeFrame = diff point2 = viewPort.fitIntoVisibleArea(point2); point3 = viewPort.fitIntoVisibleArea(point3); @@ -467,12 +467,12 @@ }; let point2 = { - x: record.date + timePeriod / 7 * (normalSize + extraSize), + x: record.date + timeFrame / 7 * (normalSize + extraSize), y: record.buyExecRate }; let point3 = { - x: record.date - timePeriod / 7 * (normalSize + extraSize), + x: record.date - timeFrame / 7 * (normalSize + extraSize), y: record.buyExecRate }; @@ -492,7 +492,7 @@ point2.y = point2.y + diff; point3.y = point3.y + diff; - currentRecord.timePeriod = diff + currentRecord.timeFrame = diff point2 = viewPort.fitIntoVisibleArea(point2); point3 = viewPort.fitIntoVisibleArea(point3); @@ -535,12 +535,12 @@ }; let point2 = { - x: record.date + timePeriod / 7 * (normalSize + extraSize), + x: record.date + timeFrame / 7 * (normalSize + extraSize), y: record.lastSellRate }; let point3 = { - x: record.date - timePeriod / 7 * (normalSize + extraSize), + x: record.date - timeFrame / 7 * (normalSize + extraSize), y: record.lastSellRate }; @@ -560,7 +560,7 @@ point2.y = point2.y - diff; point3.y = point3.y - diff; - currentRecord.timePeriod = diff + currentRecord.timeFrame = diff point2 = viewPort.fitIntoVisibleArea(point2); point3 = viewPort.fitIntoVisibleArea(point3); @@ -604,12 +604,12 @@ }; let point2 = { - x: record.date + timePeriod / 7 * (normalSize + extraSize), + x: record.date + timeFrame / 7 * (normalSize + extraSize), y: record.lastBuyRate }; let point3 = { - x: record.date - timePeriod / 7 * (normalSize + extraSize), + x: record.date - timeFrame / 7 * (normalSize + extraSize), y: record.lastBuyRate }; @@ -629,7 +629,7 @@ point2.y = point2.y + diff; point3.y = point3.y + diff; - currentRecord.timePeriod = diff + currentRecord.timeFrame = diff point2 = viewPort.fitIntoVisibleArea(point2); point3 = viewPort.fitIntoVisibleArea(point3); diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index e85d6d5e5..e90d2e5f7 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -116,12 +116,12 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu }; let point2 = { - x: X_AXIS + record.timePeriod / 4, + x: X_AXIS + record.timeFrame / 4, y: Y_AXIS }; let point3 = { - x: X_AXIS - record.timePeriod / 4, + x: X_AXIS - record.timeFrame / 4, y: Y_AXIS }; @@ -176,12 +176,12 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu }; let point2 = { - x: X_AXIS + record.timePeriod / 4, + x: X_AXIS + record.timeFrame / 4, y: Y_AXIS }; let point3 = { - x: X_AXIS - record.timePeriod / 4, + x: X_AXIS - record.timeFrame / 4, y: Y_AXIS }; @@ -234,12 +234,12 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu }; let point2 = { - x: X_AXIS + record.timePeriod / 4, + x: X_AXIS + record.timeFrame / 4, y: Y_AXIS }; let point3 = { - x: X_AXIS - record.timePeriod / 4, + x: X_AXIS - record.timeFrame / 4, y: Y_AXIS }; @@ -292,12 +292,12 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu }; let point2 = { - x: X_AXIS + record.timePeriod / 4, + x: X_AXIS + record.timeFrame / 4, y: Y_AXIS }; let point3 = { - x: X_AXIS - record.timePeriod / 4, + x: X_AXIS - record.timeFrame / 4, y: Y_AXIS }; diff --git a/Strategies.js b/Strategies.js index 50cf96a80..b0fbb4f82 100644 --- a/Strategies.js +++ b/Strategies.js @@ -15,7 +15,7 @@ finalize: finalize, container: undefined, getContainer: getContainer, - setTimePeriod: setTimePeriod, + setTimeFrame: setTimeFrame, setDatetime: setDatetime, draw: draw, recalculateScale: recalculateScale, @@ -37,14 +37,14 @@ let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. - let timePeriod; // This will hold the current Time Period the user is at. + let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. let marketFile; // This is the current Market File being plotted. let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. - let marketFiles; // This object will provide the different Market Files at different Time Periods. - let dailyFiles; // This object will provide the different File Cursors at different Time Periods. + let marketFiles; // This object will provide the different Market Files at different Time Frames. + let dailyFiles; // This object will provide the different File Cursors at different Time Frames. /* these are module specific variables: */ @@ -80,7 +80,7 @@ dailyFiles = undefined; datetime = undefined; - timePeriod = undefined; + timeFrame = undefined; marketFile = undefined; fileCursor = undefined; @@ -93,7 +93,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { try { @@ -105,7 +105,7 @@ dailyFiles = pStorage.dailyFiles[0]; datetime = pDatetime; - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -115,8 +115,8 @@ /* Now we set the right files according to current Period. */ - marketFile = marketFiles.getFile(pTimePeriod); - fileCursor = dailyFiles.getFileCursor(pTimePeriod); + marketFile = marketFiles.getFile(pTimeFrame); + fileCursor = dailyFiles.getFileCursor(pTimeFrame); /* Listen to the necesary events. */ @@ -179,7 +179,7 @@ function onMarketFilesUpdated() { try { - let newMarketFile = marketFiles.getFile(timePeriod); + let newMarketFile = marketFiles.getFile(timeFrame); if (newMarketFile !== undefined) { marketFile = newMarketFile; recalculate(); @@ -191,7 +191,7 @@ function onDailyFilesUpdated() { try { - let newFileCursor = dailyFiles.getFileCursor(timePeriod); + let newFileCursor = dailyFiles.getFileCursor(timeFrame); if (newFileCursor !== undefined) { fileCursor = newFileCursor; recalculate(); @@ -201,23 +201,23 @@ } } - function setTimePeriod(pTimePeriod) { + function setTimeFrame(pTimeFrame) { try { - if (timePeriod !== pTimePeriod) { + if (timeFrame !== pTimeFrame) { - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timeFrame >= _1_HOUR_IN_MILISECONDS) { - marketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimeFrame); recalculate(); } else { - let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + let newFileCursor = dailyFiles.getFileCursor(pTimeFrame); fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. recalculate(); @@ -227,7 +227,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] setTimeFrame -> err = " + err.stack); } } } @@ -281,7 +281,7 @@ strategies = [] - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timeFrame >= _1_HOUR_IN_MILISECONDS) { recalculateUsingMarketFiles(); @@ -315,7 +315,7 @@ return; } // We need to wait until there are files in the cursor - let daysOnSides = getSideDays(timePeriod); + let daysOnSides = getSideDays(timeFrame); let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); @@ -395,7 +395,7 @@ if (marketFile === undefined) { return; } // Initialization not complete yet. - let daysOnSides = getSideDays(timePeriod); + let daysOnSides = getSideDays(timeFrame); let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); diff --git a/Trades.js b/Trades.js index b38093e0a..d059b5f28 100644 --- a/Trades.js +++ b/Trades.js @@ -15,7 +15,7 @@ finalize: finalize, container: undefined, getContainer: getContainer, - setTimePeriod: setTimePeriod, + setTimeFrame: setTimeFrame, setDatetime: setDatetime, draw: draw, recalculateScale: recalculateScale, @@ -37,14 +37,14 @@ let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. - let timePeriod; // This will hold the current Time Period the user is at. + let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. let marketFile; // This is the current Market File being plotted. let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. - let marketFiles; // This object will provide the different Market Files at different Time Periods. - let dailyFiles; // This object will provide the different File Cursors at different Time Periods. + let marketFiles; // This object will provide the different Market Files at different Time Frames. + let dailyFiles; // This object will provide the different File Cursors at different Time Frames. /* these are module specific variables: */ @@ -80,7 +80,7 @@ dailyFiles = undefined; datetime = undefined; - timePeriod = undefined; + timeFrame = undefined; marketFile = undefined; fileCursor = undefined; @@ -91,7 +91,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { try { @@ -103,7 +103,7 @@ dailyFiles = pStorage.dailyFiles[0]; datetime = pDatetime; - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -113,8 +113,8 @@ /* Now we set the right files according to current Period. */ - marketFile = marketFiles.getFile(pTimePeriod); - fileCursor = dailyFiles.getFileCursor(pTimePeriod); + marketFile = marketFiles.getFile(pTimeFrame); + fileCursor = dailyFiles.getFileCursor(pTimeFrame); /* Listen to the necesary events. */ @@ -172,7 +172,7 @@ function onMarketFilesUpdated() { try { - let newMarketFile = marketFiles.getFile(timePeriod); + let newMarketFile = marketFiles.getFile(timeFrame); if (newMarketFile !== undefined) { marketFile = newMarketFile; recalculate(); @@ -184,7 +184,7 @@ function onDailyFilesUpdated() { try { - let newFileCursor = dailyFiles.getFileCursor(timePeriod); + let newFileCursor = dailyFiles.getFileCursor(timeFrame); if (newFileCursor !== undefined) { fileCursor = newFileCursor; recalculate(); @@ -194,23 +194,23 @@ } } - function setTimePeriod(pTimePeriod) { + function setTimeFrame(pTimeFrame) { try { - if (timePeriod !== pTimePeriod) { + if (timeFrame !== pTimeFrame) { - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timeFrame >= _1_HOUR_IN_MILISECONDS) { - marketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimeFrame); recalculate(); } else { - let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + let newFileCursor = dailyFiles.getFileCursor(pTimeFrame); fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. recalculate(); @@ -220,7 +220,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] setTimeFrame -> err = " + err.stack); } } } @@ -274,7 +274,7 @@ trades = [] - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timeFrame >= _1_HOUR_IN_MILISECONDS) { recalculateUsingMarketFiles(); @@ -308,7 +308,7 @@ return; } // We need to wait until there are files in the cursor - let daysOnSides = getSideDays(timePeriod); + let daysOnSides = getSideDays(timeFrame); let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); @@ -382,7 +382,7 @@ if (marketFile === undefined) { return; } // Initialization not complete yet. - let daysOnSides = getSideDays(timePeriod); + let daysOnSides = getSideDays(timeFrame); let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); diff --git a/TradingSimulation.js b/TradingSimulation.js index 8313fdefb..240f38874 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -14,7 +14,7 @@ finalize: finalize, container: undefined, getContainer: getContainer, - setTimePeriod: setTimePeriod, + setTimeFrame: setTimeFrame, setDatetime: setDatetime, draw: draw, recalculateScale: recalculateScale, @@ -36,14 +36,14 @@ let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. - let timePeriod; // This will hold the current Time Period the user is at. + let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. let marketFile; // This is the current Market File being plotted. let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. - let marketFiles; // This object will provide the different Market Files at different Time Periods. - let dailyFiles; // This object will provide the different File Cursors at different Time Periods. + let marketFiles; // This object will provide the different Market Files at different Time Frames. + let dailyFiles; // This object will provide the different File Cursors at different Time Frames. /* these are module specific variables: */ @@ -86,7 +86,7 @@ dailyFiles = undefined; datetime = undefined; - timePeriod = undefined; + timeFrame = undefined; marketFile = undefined; fileCursor = undefined; @@ -97,7 +97,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { try { @@ -107,7 +107,7 @@ dailyFiles = pStorage.dailyFiles[0]; datetime = pDatetime; - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -117,8 +117,8 @@ /* Now we set the right files according to current Period. */ - marketFile = marketFiles.getFile(pTimePeriod); - fileCursor = dailyFiles.getFileCursor(pTimePeriod); + marketFile = marketFiles.getFile(pTimeFrame); + fileCursor = dailyFiles.getFileCursor(pTimeFrame); /* Listen to the necesary events. */ @@ -166,7 +166,7 @@ function onMarketFilesUpdated() { try { - let newMarketFile = marketFiles.getFile(timePeriod); + let newMarketFile = marketFiles.getFile(timeFrame); if (newMarketFile !== undefined) { marketFile = newMarketFile; recalculate(); @@ -178,7 +178,7 @@ function onDailyFilesUpdated() { try { - let newFileCursor = dailyFiles.getFileCursor(timePeriod); + let newFileCursor = dailyFiles.getFileCursor(timeFrame); if (newFileCursor !== undefined) { fileCursor = newFileCursor; recalculate(); @@ -188,23 +188,23 @@ } } - function setTimePeriod(pTimePeriod) { + function setTimeFrame(pTimeFrame) { try { - if (timePeriod !== pTimePeriod) { + if (timeFrame !== pTimeFrame) { - timePeriod = pTimePeriod; + timeFrame = pTimeFrame; - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timeFrame >= _1_HOUR_IN_MILISECONDS) { - marketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimeFrame); recalculate(); } else { - let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + let newFileCursor = dailyFiles.getFileCursor(pTimeFrame); fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. recalculate(); @@ -214,7 +214,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] setTimeFrame -> err = " + err.stack); } } } @@ -264,7 +264,7 @@ records = [] - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timeFrame >= _1_HOUR_IN_MILISECONDS) { recalculateUsingMarketFiles(); @@ -296,7 +296,7 @@ return; } // We need to wait until there are files in the cursor - let daysOnSides = getSideDays(timePeriod); + let daysOnSides = getSideDays(timeFrame); let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); @@ -394,7 +394,7 @@ if (marketFile === undefined) { return; } // Initialization not complete yet. - let daysOnSides = getSideDays(timePeriod); + let daysOnSides = getSideDays(timeFrame); let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); @@ -535,12 +535,12 @@ } let recordPoint1 = { - x: record.begin + timePeriod / 7 * 1.5, + x: record.begin + timeFrame / 7 * 1.5, y: thisObject.container.frame.height }; let recordPoint2 = { - x: record.end + timePeriod / 7 * 5.5, + x: record.end + timeFrame / 7 * 5.5, y: thisObject.container.frame.height }; @@ -550,7 +550,7 @@ }; let recordPoint4 = { - x: record.begin + timePeriod / 7 * 1.5, + x: record.begin + timeFrame / 7 * 1.5, y: thisObject.container.frame.height * 100 }; From 5cfd77cffb5ab530bb78242c5f5d92d48f2ac2b1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 10 Jan 2020 08:06:32 +0100 Subject: [PATCH 106/157] Code Cleaning --- SimulationExecutionPanel.js | 1 - TradingSimulationPanel.js | 1 - 2 files changed, 2 deletions(-) diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index e90d2e5f7..f9b57b3b8 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -15,7 +15,6 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu container.initialize(); thisObject.container = container; - container.displacement.containerName = "Trading Execution"; container.frame.containerName = "Trading Execution"; let currentRecord; diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index d7811c9d2..181b315e5 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -16,7 +16,6 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation container.initialize(); thisObject.container = container; - container.displacement.containerName = "Simulation"; container.frame.containerName = "Simulation"; let currentRecord; From 2e98b587f69eaf1fb704fe9ac8070d7d0c8ee453 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 11 Jan 2020 18:38:23 +0100 Subject: [PATCH 107/157] Refactoring --- Conditions.js | 14 +++++++------- SimulationExecution.js | 36 ++++++++++++++++++------------------ Strategies.js | 22 +++++++++++----------- Trades.js | 20 ++++++++++---------- TradingSimulation.js | 34 +++++++++++++++++----------------- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Conditions.js b/Conditions.js index ca66bc756..8f39f4f3a 100644 --- a/Conditions.js +++ b/Conditions.js @@ -35,7 +35,7 @@ container.initialize(); thisObject.container = container; - let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -312,8 +312,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -394,8 +394,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -449,7 +449,7 @@ try { - if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + if (coordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { x: MIN_PLOTABLE_DATE.valueOf(), @@ -462,7 +462,7 @@ }; - timeLineCoordinateSystem.initialize( + coordinateSystem.initialize( minValue, maxValue, thisObject.container.frame.width, diff --git a/SimulationExecution.js b/SimulationExecution.js index 315e2ede8..12f9fcd1d 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -26,7 +26,7 @@ container.initialize(); thisObject.container = container; - let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -308,7 +308,7 @@ try { if (fileSequence === undefined) { return; } // We need the market file to be loaded to make the calculation. - if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + if (coordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { x: MIN_PLOTABLE_DATE.valueOf(), @@ -320,7 +320,7 @@ y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary }; - timeLineCoordinateSystem.initialize( + coordinateSystem.initialize( minValue, maxValue, thisObject.container.frame.width, @@ -366,7 +366,7 @@ y: record.marketRate }; - point = timeLineCoordinateSystem.transformThisPoint(point); + point = coordinateSystem.transformThisPoint(point); point = transformThisPoint(point, thisObject.container); if (point.x < viewPort.visibleArea.bottomLeft.x || point.x > viewPort.visibleArea.bottomRight.x) { continue; } @@ -406,15 +406,15 @@ y: record.sellExecRate }; - point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); - point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); - point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); point3 = viewPort.fitIntoVisibleArea(point3); @@ -476,15 +476,15 @@ y: record.buyExecRate }; - point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); - point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); - point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); point3 = viewPort.fitIntoVisibleArea(point3); @@ -544,15 +544,15 @@ y: record.lastSellRate }; - point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); - point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); - point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); point3 = viewPort.fitIntoVisibleArea(point3); @@ -613,15 +613,15 @@ y: record.lastBuyRate }; - point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); - point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); - point3 = timeLineCoordinateSystem.transformThisPoint(point3); + point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); point3 = viewPort.fitIntoVisibleArea(point3); @@ -731,11 +731,11 @@ y: line.y2 }; - point1 = timeLineCoordinateSystem.transformThisPoint(point1); + point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); - point2 = timeLineCoordinateSystem.transformThisPoint(point2); + point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); diff --git a/Strategies.js b/Strategies.js index b0fbb4f82..a84b3de64 100644 --- a/Strategies.js +++ b/Strategies.js @@ -35,7 +35,7 @@ container.initialize(); thisObject.container = container; - let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -317,8 +317,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -397,8 +397,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -450,7 +450,7 @@ try { - if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + if (coordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { x: MIN_PLOTABLE_DATE.valueOf(), @@ -463,7 +463,7 @@ }; - timeLineCoordinateSystem.initialize( + coordinateSystem.initialize( minValue, maxValue, thisObject.container.frame.width, @@ -511,10 +511,10 @@ y: record.endRate }; - recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); - recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); - recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); - recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); + recordPoint1 = coordinateSystem.transformThisPoint(recordPoint1); + recordPoint2 = coordinateSystem.transformThisPoint(recordPoint2); + recordPoint3 = coordinateSystem.transformThisPoint(recordPoint3); + recordPoint4 = coordinateSystem.transformThisPoint(recordPoint4); recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); diff --git a/Trades.js b/Trades.js index d059b5f28..8caedd9e2 100644 --- a/Trades.js +++ b/Trades.js @@ -35,7 +35,7 @@ container.initialize(); thisObject.container = container; - let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -310,8 +310,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -384,8 +384,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -431,7 +431,7 @@ try { - if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + if (coordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { x: MIN_PLOTABLE_DATE.valueOf(), @@ -444,7 +444,7 @@ }; - timeLineCoordinateSystem.initialize( + coordinateSystem.initialize( minValue, maxValue, thisObject.container.frame.width, @@ -496,9 +496,9 @@ y: record.endRate }; - recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); - recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); - recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); + recordPoint1 = coordinateSystem.transformThisPoint(recordPoint1); + recordPoint2 = coordinateSystem.transformThisPoint(recordPoint2); + recordPoint3 = coordinateSystem.transformThisPoint(recordPoint3); recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); diff --git a/TradingSimulation.js b/TradingSimulation.js index 240f38874..7d5f3e964 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -34,7 +34,7 @@ container.initialize(); thisObject.container = container; - let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -298,8 +298,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -396,8 +396,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -471,7 +471,7 @@ try { - if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + if (coordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { x: MIN_PLOTABLE_DATE.valueOf(), @@ -483,7 +483,7 @@ y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary }; - timeLineCoordinateSystem.initialize( + coordinateSystem.initialize( minValue, maxValue, thisObject.container.frame.width, @@ -602,16 +602,16 @@ recordPoint10.x = 0; } - recordPoint1 = timeLineCoordinateSystem.transformThisPoint(recordPoint1); - recordPoint2 = timeLineCoordinateSystem.transformThisPoint(recordPoint2); - recordPoint3 = timeLineCoordinateSystem.transformThisPoint(recordPoint3); - recordPoint4 = timeLineCoordinateSystem.transformThisPoint(recordPoint4); - recordPoint5 = timeLineCoordinateSystem.transformThisPoint(recordPoint5); - recordPoint6 = timeLineCoordinateSystem.transformThisPoint(recordPoint6); - recordPoint7 = timeLineCoordinateSystem.transformThisPoint(recordPoint7); - recordPoint8 = timeLineCoordinateSystem.transformThisPoint(recordPoint8); - recordPoint9 = timeLineCoordinateSystem.transformThisPoint(recordPoint9); - recordPoint10 = timeLineCoordinateSystem.transformThisPoint(recordPoint10); + recordPoint1 = coordinateSystem.transformThisPoint(recordPoint1); + recordPoint2 = coordinateSystem.transformThisPoint(recordPoint2); + recordPoint3 = coordinateSystem.transformThisPoint(recordPoint3); + recordPoint4 = coordinateSystem.transformThisPoint(recordPoint4); + recordPoint5 = coordinateSystem.transformThisPoint(recordPoint5); + recordPoint6 = coordinateSystem.transformThisPoint(recordPoint6); + recordPoint7 = coordinateSystem.transformThisPoint(recordPoint7); + recordPoint8 = coordinateSystem.transformThisPoint(recordPoint8); + recordPoint9 = coordinateSystem.transformThisPoint(recordPoint9); + recordPoint10 = coordinateSystem.transformThisPoint(recordPoint10); recordPoint1 = transformThisPoint(recordPoint1, thisObject.container); recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); From fbb240f6f3082cafdf1621c92cafd81eb652c426 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 11 Jan 2020 19:55:54 +0100 Subject: [PATCH 108/157] FitFunction Implemented --- SimulationExecution.js | 25 +++++++++++++++++++++++++ Strategies.js | 7 +++++++ Trades.js | 9 +++++++++ TradingSimulation.js | 41 ++++++++++++++++++++++++++++++++++++----- 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/SimulationExecution.js b/SimulationExecution.js index 12f9fcd1d..750a82b6d 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -13,6 +13,7 @@ initialize: initialize, finalize: finalize, container: undefined, + fitFunction: undefined, getContainer: getContainer, setTimeFrame: setTimeFrame, setDatetime: setDatetime, @@ -63,6 +64,7 @@ plotElements = undefined; plotLines = undefined; + thisObject.fitFunction = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> finalize -> err = " + err.stack.stack); } } @@ -372,6 +374,7 @@ if (point.x < viewPort.visibleArea.bottomLeft.x || point.x > viewPort.visibleArea.bottomRight.x) { continue; } point = viewPort.fitIntoVisibleArea(point); + point = thisObject.fitFunction(point); let isCurrentRecord = false; @@ -409,14 +412,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); + point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); + point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); point3 = viewPort.fitIntoVisibleArea(point3); + point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; point2.y = point2.y - diff; @@ -426,6 +432,8 @@ point2 = viewPort.fitIntoVisibleArea(point2); point3 = viewPort.fitIntoVisibleArea(point3); + point2 = thisObject.fitFunction(point2); + point3 = thisObject.fitFunction(point3); browserCanvasContext.beginPath(); @@ -479,14 +487,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); + point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); + point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); point3 = viewPort.fitIntoVisibleArea(point3); + point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; point2.y = point2.y + diff; @@ -496,6 +507,8 @@ point2 = viewPort.fitIntoVisibleArea(point2); point3 = viewPort.fitIntoVisibleArea(point3); + point2 = thisObject.fitFunction(point2); + point3 = thisObject.fitFunction(point3); browserCanvasContext.beginPath(); @@ -547,14 +560,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); + point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); + point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); point3 = viewPort.fitIntoVisibleArea(point3); + point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; point2.y = point2.y - diff; @@ -564,6 +580,8 @@ point2 = viewPort.fitIntoVisibleArea(point2); point3 = viewPort.fitIntoVisibleArea(point3); + point2 = thisObject.fitFunction(point2); + point3 = thisObject.fitFunction(point3); browserCanvasContext.beginPath(); @@ -616,14 +634,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); + point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); + point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); point3 = viewPort.fitIntoVisibleArea(point3); + point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; point2.y = point2.y + diff; @@ -633,6 +654,8 @@ point2 = viewPort.fitIntoVisibleArea(point2); point3 = viewPort.fitIntoVisibleArea(point3); + point2 = thisObject.fitFunction(point2); + point3 = thisObject.fitFunction(point3); browserCanvasContext.beginPath(); @@ -734,10 +757,12 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); point1 = viewPort.fitIntoVisibleArea(point1); + point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); point2 = viewPort.fitIntoVisibleArea(point2); + point2 = thisObject.fitFunction(point2); browserCanvasContext.beginPath(); diff --git a/Strategies.js b/Strategies.js index a84b3de64..8fb6f6e7c 100644 --- a/Strategies.js +++ b/Strategies.js @@ -14,6 +14,7 @@ initialize: initialize, finalize: finalize, container: undefined, + fitFunction: undefined, getContainer: getContainer, setTimeFrame: setTimeFrame, setDatetime: setDatetime, @@ -87,6 +88,7 @@ strategyImages = undefined; + thisObject.fitFunction = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } @@ -533,6 +535,11 @@ recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); + recordPoint1 = thisObject.fitFunction(recordPoint1, undefined, 30); + recordPoint2 = thisObject.fitFunction(recordPoint2, undefined, 30); + recordPoint3 = thisObject.fitFunction(recordPoint3, undefined, 30); + recordPoint4 = thisObject.fitFunction(recordPoint4, undefined, 30); + let imageSize = 20; let imageToDraw = strategyImages[record.number]; diff --git a/Trades.js b/Trades.js index 8caedd9e2..023849123 100644 --- a/Trades.js +++ b/Trades.js @@ -14,6 +14,7 @@ initialize: initialize, finalize: finalize, container: undefined, + fitFunction: undefined, getContainer: getContainer, setTimeFrame: setTimeFrame, setDatetime: setDatetime, @@ -85,6 +86,7 @@ marketFile = undefined; fileCursor = undefined; + thisObject.fitFunction = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } @@ -512,6 +514,10 @@ recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); + recordPoint1 = thisObject.fitFunction(recordPoint1); + recordPoint2 = thisObject.fitFunction(recordPoint2); + recordPoint3 = thisObject.fitFunction(recordPoint3); + let line1 = ''; let line2 = ''; @@ -576,6 +582,9 @@ point.y = recordPoint3.y - 100 } + point = viewPort.fitIntoVisibleArea(point); + point = thisObject.fitFunction(point, undefined, 50); + if ( recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 || diff --git a/TradingSimulation.js b/TradingSimulation.js index 7d5f3e964..7f4780840 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -13,6 +13,7 @@ initialize: initialize, finalize: finalize, container: undefined, + fitFunction: undefined, getContainer: getContainer, setTimeFrame: setTimeFrame, setDatetime: setDatetime, @@ -91,6 +92,7 @@ marketFile = undefined; fileCursor = undefined; + thisObject.fitFunction = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } @@ -668,7 +670,8 @@ y: recordPoint4.y + imageOffset.y } - imagePosition = thisObject.fitFunction(imagePosition) + imagePosition = viewPort.fitIntoVisibleArea(imagePosition) + imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) if (imageRecord.canDrawIcon === true) { browserCanvasContext.drawImage(imageRecord, imagePosition.x, imagePosition.y, imageSize, imageSize); @@ -739,10 +742,24 @@ browserCanvasContext.lineWidth = 1 browserCanvasContext.stroke() + imagePosition = { + x: recordPoint6.x - imageSize, + y: recordPoint6.y - imageSize * 1.25 + yOffset + } + + imagePosition = viewPort.fitIntoVisibleArea(imagePosition) + imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) + + let labelPosition = { + x: recordPoint6.x - imageSize / 2 - 3, + y: recordPoint6.y - imageSize * 1.5 + yOffset * 2 + } + labelPosition = viewPort.fitIntoVisibleArea(labelPosition) + labelPosition = thisObject.fitFunction(labelPosition, undefined, 30) if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > -1) { - browserCanvasContext.drawImage(imageStopLossPhase, recordPoint6.x - imageSize, recordPoint6.y - imageSize * 1.25 + yOffset, imageSize, imageSize); - printLabel(stopLossPhase, recordPoint6.x - imageSize / 2 - 3, recordPoint6.y - imageSize * 1.5 + yOffset * 2, '1', 9); + browserCanvasContext.drawImage(imageStopLossPhase, imagePosition.x, imagePosition.y, imageSize, imageSize); + printLabel(stopLossPhase, labelPosition.x, labelPosition.y, '1', 9); } /* Next we are drawing the Take Profit */ @@ -767,9 +784,23 @@ browserCanvasContext.lineWidth = 1 browserCanvasContext.stroke() + imagePosition = { + x: recordPoint10.x - imageSize * 2 / 3, + y: recordPoint10.y + imageSize / 4 - yOffset + } + imagePosition = viewPort.fitIntoVisibleArea(imagePosition) + imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) + + labelPosition = { + x: recordPoint10.x - imageSize * 1 / 3, + y: recordPoint10.y + imageSize * 1.9 - yOffset * 2 + } + labelPosition = viewPort.fitIntoVisibleArea(labelPosition) + labelPosition = thisObject.fitFunction(labelPosition, undefined, 30) + if (imageTakeProfitPhase.canDrawIcon === true && takeProfitPhase > -1) { - browserCanvasContext.drawImage(imageTakeProfitPhase, recordPoint10.x - imageSize * 2 / 3, recordPoint10.y + imageSize / 4 - yOffset, imageSize, imageSize); - printLabel(takeProfitPhase, recordPoint10.x - imageSize * 1 / 3, recordPoint10.y + imageSize * 1.9 - yOffset * 2, '1', 9); + browserCanvasContext.drawImage(imageTakeProfitPhase, imagePosition.x, imagePosition.y, imageSize, imageSize); + printLabel(takeProfitPhase, labelPosition.x, labelPosition.y, '1', 9); } } From b6519c15c4c7f4452f650e07aea745d1702b9186 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 Jan 2020 08:30:22 +0100 Subject: [PATCH 109/157] Code Cleaning --- Conditions.js | 2 +- SimulationExecution.js | 2 +- Strategies.js | 2 +- Trades.js | 2 +- TradingSimulation.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Conditions.js b/Conditions.js index 8f39f4f3a..a3fbb5b45 100644 --- a/Conditions.js +++ b/Conditions.js @@ -93,7 +93,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { try { diff --git a/SimulationExecution.js b/SimulationExecution.js index 750a82b6d..fe1529508 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -70,7 +70,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { try { diff --git a/Strategies.js b/Strategies.js index 8fb6f6e7c..b2327c23d 100644 --- a/Strategies.js +++ b/Strategies.js @@ -95,7 +95,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { try { diff --git a/Trades.js b/Trades.js index 023849123..e2025ab73 100644 --- a/Trades.js +++ b/Trades.js @@ -93,7 +93,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { try { diff --git a/TradingSimulation.js b/TradingSimulation.js index 7f4780840..0e8fab00c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -99,7 +99,7 @@ } } - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { try { From afab7d8ac7b797e9b7d8e8fb80bb5a1477eea21d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 17 Jan 2020 17:49:18 +0100 Subject: [PATCH 110/157] Viewport Related Refactoring --- Conditions.js | 16 ++++++++-------- SimulationExecution.js | 4 ++-- Strategies.js | 16 ++++++++-------- Trades.js | 16 ++++++++-------- TradingSimulation.js | 12 ++++++------ 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Conditions.js b/Conditions.js index a3fbb5b45..520bcfb95 100644 --- a/Conditions.js +++ b/Conditions.js @@ -120,8 +120,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -966,25 +966,25 @@ - function onZoomChanged(event) { + function onViewportZoomChanged(event) { try { - if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] onViewportZoomChanged -> Entering function."); } recalculate(); } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] onViewportZoomChanged -> err = " + err.stack); } } } - function onOffsetChanged(event) { + function onViewportPositionChanged(event) { try { - if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] onViewportPositionChanged -> Entering function."); } if (event !== undefined) { if (event.recalculate === true) { @@ -998,7 +998,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] onViewportPositionChanged -> err = " + err.stack); } } } diff --git a/SimulationExecution.js b/SimulationExecution.js index fe1529508..72b543402 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -83,7 +83,7 @@ recalculateScale(); filesUpdatedEventSubscriptionId = fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); /* Ready for when dimmension changes. */ @@ -127,7 +127,7 @@ datetime = newDatetime; } - function onOffsetChanged() { + function onViewportPositionChanged() { if (Math.random() * 100 > 95) { recalculate() } diff --git a/Strategies.js b/Strategies.js index b2327c23d..4883cb092 100644 --- a/Strategies.js +++ b/Strategies.js @@ -122,8 +122,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -616,25 +616,25 @@ } - function onZoomChanged(event) { + function onViewportZoomChanged(event) { try { - if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] onViewportZoomChanged -> Entering function."); } recalculate(); } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] onViewportZoomChanged -> err = " + err.stack); } } } - function onOffsetChanged(event) { + function onViewportPositionChanged(event) { try { - if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] onViewportPositionChanged -> Entering function."); } if (event !== undefined) { if (event.recalculate === true) { @@ -648,7 +648,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] onViewportPositionChanged -> err = " + err.stack); } } } diff --git a/Trades.js b/Trades.js index e2025ab73..121407b1e 100644 --- a/Trades.js +++ b/Trades.js @@ -120,8 +120,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -612,25 +612,25 @@ } - function onZoomChanged(event) { + function onViewportZoomChanged(event) { try { - if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] onViewportZoomChanged -> Entering function."); } recalculate(); } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] onViewportZoomChanged -> err = " + err.stack); } } } - function onOffsetChanged(event) { + function onViewportPositionChanged(event) { try { - if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] onViewportPositionChanged -> Entering function."); } if (event !== undefined) { if (event.recalculate === true) { @@ -644,7 +644,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] onViewportPositionChanged -> err = " + err.stack); } } } diff --git a/TradingSimulation.js b/TradingSimulation.js index 0e8fab00c..ae25640fe 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -124,8 +124,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -811,7 +811,7 @@ } - function onZoomChanged(event) { + function onViewportZoomChanged(event) { try { @@ -819,11 +819,11 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] onViewportZoomChanged -> err = " + err.stack); } } } - function onOffsetChanged(event) { + function onViewportPositionChanged(event) { try { @@ -839,7 +839,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } + if (ERROR_LOG === true) { logger.write("[ERROR] onViewportPositionChanged -> err = " + err.stack); } } } From 67e595b167e7f3e5ebe3097f23619cc941215d5f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 17 Jan 2020 18:46:27 +0100 Subject: [PATCH 111/157] Viewport inside the Chartspace --- Conditions.js | 16 +++++------ SimulationExecution.js | 56 ++++++++++++++++++------------------- SimulationExecutionPanel.js | 24 ++++++++-------- Strategies.js | 26 ++++++++--------- Trades.js | 34 +++++++++++----------- TradingSimulation.js | 48 +++++++++++++++---------------- TradingSimulationPanel.js | 4 +-- 7 files changed, 104 insertions(+), 104 deletions(-) diff --git a/Conditions.js b/Conditions.js index 520bcfb95..13e948b87 100644 --- a/Conditions.js +++ b/Conditions.js @@ -69,8 +69,8 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); - viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); @@ -120,8 +120,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + zoomChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -312,8 +312,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -394,8 +394,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); diff --git a/SimulationExecution.js b/SimulationExecution.js index 72b543402..a25259876 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -51,7 +51,7 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); fileSequence.eventHandler.stopListening(filesUpdatedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) @@ -83,7 +83,7 @@ recalculateScale(); filesUpdatedEventSubscriptionId = fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); /* Ready for when dimmension changes. */ @@ -371,9 +371,9 @@ point = coordinateSystem.transformThisPoint(point); point = transformThisPoint(point, thisObject.container); - if (point.x < viewPort.visibleArea.bottomLeft.x || point.x > viewPort.visibleArea.bottomRight.x) { continue; } + if (point.x < canvas.chartSpace.viewport.visibleArea.bottomLeft.x || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x) { continue; } - point = viewPort.fitIntoVisibleArea(point); + point = canvas.chartSpace.viewport.fitIntoVisibleArea(point); point = thisObject.fitFunction(point); let isCurrentRecord = false; @@ -411,17 +411,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); + point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); - point3 = viewPort.fitIntoVisibleArea(point3); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; @@ -430,8 +430,8 @@ currentRecord.timeFrame = diff - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); point2 = thisObject.fitFunction(point2); point3 = thisObject.fitFunction(point3); @@ -486,17 +486,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); + point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); - point3 = viewPort.fitIntoVisibleArea(point3); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; @@ -505,8 +505,8 @@ currentRecord.timeFrame = diff - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); point2 = thisObject.fitFunction(point2); point3 = thisObject.fitFunction(point3); @@ -559,17 +559,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); + point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); - point3 = viewPort.fitIntoVisibleArea(point3); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; @@ -578,8 +578,8 @@ currentRecord.timeFrame = diff - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); point2 = thisObject.fitFunction(point2); point3 = thisObject.fitFunction(point3); @@ -633,17 +633,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); + point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); - point3 = viewPort.fitIntoVisibleArea(point3); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; @@ -652,8 +652,8 @@ currentRecord.timeFrame = diff - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); point2 = thisObject.fitFunction(point2); point3 = thisObject.fitFunction(point3); @@ -705,7 +705,7 @@ browserCanvasContext.arc(point.x, point.y, currentRadius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); - if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + if (point.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } @@ -725,7 +725,7 @@ browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); - if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + if (point.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } @@ -756,12 +756,12 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = viewPort.fitIntoVisibleArea(point1); + point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = viewPort.fitIntoVisibleArea(point2); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); browserCanvasContext.beginPath(); diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index f9b57b3b8..85d929006 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -27,8 +27,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; - thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 4; - thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; + thisObject.container.frame.position.x = canvas.chartSpace.viewport.visibleArea.topLeft.x + thisObject.container.frame.width * 4; + thisObject.container.frame.position.y = canvas.chartSpace.viewport.visibleArea.topRight.y; panelTabButton = newPanelTabButton() panelTabButton.parentContainer = thisObject.container @@ -137,8 +137,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu point2.y = point2.y - diff; point3.y = point3.y - diff; - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); browserCanvasContext.beginPath(); @@ -197,8 +197,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu point2.y = point2.y + diff; point3.y = point3.y + diff; - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); browserCanvasContext.beginPath(); @@ -255,8 +255,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu point2.y = point2.y - diff; point3.y = point3.y - diff; - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); browserCanvasContext.beginPath(); @@ -313,8 +313,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu point2.y = point2.y + diff; point3.y = point3.y + diff; - point2 = viewPort.fitIntoVisibleArea(point2); - point3 = viewPort.fitIntoVisibleArea(point3); + point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); browserCanvasContext.beginPath(); @@ -353,7 +353,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu browserCanvasContext.arc(point.x, point.y, currentRadius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); - if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + if (point.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } browserCanvasContext.setLineDash([0, 0]) @@ -371,7 +371,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); - if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + if (point.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } browserCanvasContext.setLineDash([0, 0]) diff --git a/Strategies.js b/Strategies.js index 4883cb092..45d5e69bb 100644 --- a/Strategies.js +++ b/Strategies.js @@ -68,8 +68,8 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); - viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); @@ -122,8 +122,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + zoomChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -319,8 +319,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -399,8 +399,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -523,17 +523,17 @@ recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); - if (recordPoint2.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { + if (recordPoint2.x < canvas.chartSpace.viewport.visibleArea.bottomLeft.x || recordPoint1.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x) { continue; } recordPoint3.y = recordPoint1.y + 2000; recordPoint4.y = recordPoint1.y + 2000; - recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); - recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); - recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); - recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); + recordPoint1 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint1); + recordPoint2 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint2); + recordPoint3 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint3); + recordPoint4 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint4); recordPoint1 = thisObject.fitFunction(recordPoint1, undefined, 30); recordPoint2 = thisObject.fitFunction(recordPoint2, undefined, 30); diff --git a/Trades.js b/Trades.js index 121407b1e..bf16c8a18 100644 --- a/Trades.js +++ b/Trades.js @@ -68,8 +68,8 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); - viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); @@ -120,8 +120,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + zoomChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -312,8 +312,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -386,8 +386,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -506,13 +506,13 @@ recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); - if (recordPoint2.x < viewPort.visibleArea.bottomLeft.x || recordPoint1.x > viewPort.visibleArea.bottomRight.x) { + if (recordPoint2.x < canvas.chartSpace.viewport.visibleArea.bottomLeft.x || recordPoint1.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x) { continue; } - recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); - recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); - recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); + recordPoint1 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint1); + recordPoint2 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint2); + recordPoint3 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint3); recordPoint1 = thisObject.fitFunction(recordPoint1); recordPoint2 = thisObject.fitFunction(recordPoint2); @@ -582,17 +582,17 @@ point.y = recordPoint3.y - 100 } - point = viewPort.fitIntoVisibleArea(point); + point = canvas.chartSpace.viewport.fitIntoVisibleArea(point); point = thisObject.fitFunction(point, undefined, 50); if ( - recordPoint3.x < viewPort.visibleArea.topLeft.x + 250 + recordPoint3.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 250 || - recordPoint3.x > viewPort.visibleArea.bottomRight.x - 250 + recordPoint3.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 250 || - recordPoint3.y > viewPort.visibleArea.bottomRight.y - 150 + recordPoint3.y > canvas.chartSpace.viewport.visibleArea.bottomRight.y - 150 || - recordPoint3.y < viewPort.visibleArea.topLeft.y + 150 + recordPoint3.y < canvas.chartSpace.viewport.visibleArea.topLeft.y + 150 ) { // we do not write any text } else { diff --git a/TradingSimulation.js b/TradingSimulation.js index ae25640fe..3ecf81ffa 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -68,8 +68,8 @@ /* Stop listening to the necesary events. */ - viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); - viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); + canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); @@ -124,8 +124,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + zoomChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -300,8 +300,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -398,8 +398,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -626,16 +626,16 @@ recordPoint9 = transformThisPoint(recordPoint9, thisObject.container); recordPoint10 = transformThisPoint(recordPoint10, thisObject.container); - recordPoint1 = viewPort.fitIntoVisibleArea(recordPoint1); - recordPoint2 = viewPort.fitIntoVisibleArea(recordPoint2); - recordPoint3 = viewPort.fitIntoVisibleArea(recordPoint3); - recordPoint4 = viewPort.fitIntoVisibleArea(recordPoint4); - recordPoint5 = viewPort.fitIntoVisibleArea(recordPoint5); - recordPoint6 = viewPort.fitIntoVisibleArea(recordPoint6); - recordPoint7 = viewPort.fitIntoVisibleArea(recordPoint7); - recordPoint8 = viewPort.fitIntoVisibleArea(recordPoint8); - recordPoint9 = viewPort.fitIntoVisibleArea(recordPoint9); - recordPoint10 = viewPort.fitIntoVisibleArea(recordPoint10); + recordPoint1 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint1); + recordPoint2 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint2); + recordPoint3 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint3); + recordPoint4 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint4); + recordPoint5 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint5); + recordPoint6 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint6); + recordPoint7 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint7); + recordPoint8 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint8); + recordPoint9 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint9); + recordPoint10 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint10); recordPoint1 = thisObject.fitFunction(recordPoint1); recordPoint2 = thisObject.fitFunction(recordPoint2); @@ -670,7 +670,7 @@ y: recordPoint4.y + imageOffset.y } - imagePosition = viewPort.fitIntoVisibleArea(imagePosition) + imagePosition = canvas.chartSpace.viewport.fitIntoVisibleArea(imagePosition) imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) if (imageRecord.canDrawIcon === true) { @@ -682,7 +682,7 @@ browserCanvasContext.restore(); } - if (recordPoint5.x < viewPort.visibleArea.bottomLeft.x || recordPoint5.x > viewPort.visibleArea.bottomRight.x) { + if (recordPoint5.x < canvas.chartSpace.viewport.visibleArea.bottomLeft.x || recordPoint5.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x) { continue; } @@ -747,14 +747,14 @@ y: recordPoint6.y - imageSize * 1.25 + yOffset } - imagePosition = viewPort.fitIntoVisibleArea(imagePosition) + imagePosition = canvas.chartSpace.viewport.fitIntoVisibleArea(imagePosition) imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) let labelPosition = { x: recordPoint6.x - imageSize / 2 - 3, y: recordPoint6.y - imageSize * 1.5 + yOffset * 2 } - labelPosition = viewPort.fitIntoVisibleArea(labelPosition) + labelPosition = canvas.chartSpace.viewport.fitIntoVisibleArea(labelPosition) labelPosition = thisObject.fitFunction(labelPosition, undefined, 30) if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > -1) { @@ -788,14 +788,14 @@ x: recordPoint10.x - imageSize * 2 / 3, y: recordPoint10.y + imageSize / 4 - yOffset } - imagePosition = viewPort.fitIntoVisibleArea(imagePosition) + imagePosition = canvas.chartSpace.viewport.fitIntoVisibleArea(imagePosition) imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) labelPosition = { x: recordPoint10.x - imageSize * 1 / 3, y: recordPoint10.y + imageSize * 1.9 - yOffset * 2 } - labelPosition = viewPort.fitIntoVisibleArea(labelPosition) + labelPosition = canvas.chartSpace.viewport.fitIntoVisibleArea(labelPosition) labelPosition = thisObject.fitFunction(labelPosition, undefined, 30) if (imageTakeProfitPhase.canDrawIcon === true && takeProfitPhase > -1) { diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 181b315e5..36e65a70d 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -30,8 +30,8 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; - thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 3; - thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; + thisObject.container.frame.position.x = canvas.chartSpace.viewport.visibleArea.topLeft.x + thisObject.container.frame.width * 3; + thisObject.container.frame.position.y = canvas.chartSpace.viewport.visibleArea.topRight.y; panelTabButton = newPanelTabButton() panelTabButton.parentContainer = thisObject.container From 1b53c950f21c324dfb11f601ff769f90e40017d4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 20 Jan 2020 15:30:13 +0100 Subject: [PATCH 112/157] refactoring --- Conditions.js | 2 +- SimulationExecution.js | 2 +- Strategies.js | 2 +- Trades.js | 2 +- TradingSimulation.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Conditions.js b/Conditions.js index 13e948b87..01ae2ca3a 100644 --- a/Conditions.js +++ b/Conditions.js @@ -458,7 +458,7 @@ let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary }; diff --git a/SimulationExecution.js b/SimulationExecution.js index a25259876..d6d2c82e4 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -319,7 +319,7 @@ let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary }; coordinateSystem.initialize( diff --git a/Strategies.js b/Strategies.js index 45d5e69bb..bda368538 100644 --- a/Strategies.js +++ b/Strategies.js @@ -461,7 +461,7 @@ let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary }; diff --git a/Trades.js b/Trades.js index bf16c8a18..b7ac90273 100644 --- a/Trades.js +++ b/Trades.js @@ -442,7 +442,7 @@ let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary }; diff --git a/TradingSimulation.js b/TradingSimulation.js index 3ecf81ffa..8353cf7aa 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -482,7 +482,7 @@ let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary }; coordinateSystem.initialize( From e55e075b34a99362b32ddc3a89b3c6576f46faa4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 Jan 2020 14:44:15 +0100 Subject: [PATCH 113/157] Bug fixed from refactoring --- SimulationExecutionPanel.js | 4 ++-- TradingSimulationPanel.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index 85d929006..37f05d7b4 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -5,7 +5,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu let thisObject = { fitFunction: undefined, container: undefined, - onEventRaised: onEventRaised, + onRecordChange: onRecordChange, draw: draw, getContainer: getContainer, initialize: initialize @@ -60,7 +60,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu } - function onEventRaised(lastCurrentCandle) { + function onRecordChange(lastCurrentCandle) { currentRecord = lastCurrentCandle; diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 36e65a70d..e60c48c73 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -3,7 +3,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation let thisObject = { fitFunction: undefined, - onEventRaised: onEventRaised, + onRecordChange: onRecordChange, container: undefined, session: undefined, draw: draw, @@ -30,7 +30,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; - thisObject.container.frame.position.x = canvas.chartSpace.viewport.visibleArea.topLeft.x + thisObject.container.frame.width * 3; + thisObject.container.frame.position.x = canvas.chartSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; thisObject.container.frame.position.y = canvas.chartSpace.viewport.visibleArea.topRight.y; panelTabButton = newPanelTabButton() @@ -47,7 +47,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation thisObject.container.finalize() thisObject.container = undefined thisObject.fitFunction = undefined - thisObject.onEventRaised = undefined + thisObject.onRecordChange = undefined currentRecord = undefined lastRecord = undefined @@ -77,7 +77,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation } - function onEventRaised(records) { + function onRecordChange(records) { currentRecord = records.currentRecord; lastRecord = records.lastRecord From 92d1a971cac0d7011a2519b121eb6c4973ac2fed Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 29 Jan 2020 10:25:28 +0100 Subject: [PATCH 114/157] showPanles functionality implemented --- SimulationExecutionPanel.js | 19 ++++++++++++++++--- TradingSimulationPanel.js | 6 ++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index 37f05d7b4..d809b2ef5 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -5,10 +5,12 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu let thisObject = { fitFunction: undefined, container: undefined, + isVisible: true, onRecordChange: onRecordChange, draw: draw, getContainer: getContainer, - initialize: initialize + initialize: initialize, + finalize: finalize }; let container = newContainer(); @@ -22,6 +24,17 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu return thisObject; + function finalize() { + thisObject.container.finalize() + thisObject.container = undefined + thisObject.fitFunction = undefined + thisObject.isVisible = undefined + + currentRecord = undefined + panelTabButton.finalize() + panelTabButton = undefined + } + function initialize() { thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; @@ -38,7 +51,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu } function getContainer(point) { - + if (thisObject.isVisible !== true) { return } let container; container = panelTabButton.getContainer(point) @@ -68,7 +81,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu function draw() { - + if (thisObject.isVisible !== true) { return } thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); plot(); diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index e60c48c73..048de40a3 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -6,6 +6,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation onRecordChange: onRecordChange, container: undefined, session: undefined, + isVisible: true, draw: draw, getContainer: getContainer, initialize: initialize, @@ -48,6 +49,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation thisObject.container = undefined thisObject.fitFunction = undefined thisObject.onRecordChange = undefined + thisObject.isVisible = undefined currentRecord = undefined lastRecord = undefined @@ -55,7 +57,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation } function getContainer(point) { - + if (thisObject.isVisible !== true) { return } let container; container = panelTabButton.getContainer(point) @@ -86,7 +88,7 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation function draw() { - + if (thisObject.isVisible !== true) { return } thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); plotCurrentRecordInfo(); From c9162c37cf741aa058fc7f90e3a3cff87d00ba0f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 30 Jan 2020 19:13:28 +0100 Subject: [PATCH 115/157] coordinateSystem going down to Plotters --- SimulationExecution.js | 18 ++++++++++++------ Strategies.js | 17 +++++++++-------- Trades.js | 17 +++++++++-------- TradingSimulation.js | 15 +++++++++------ 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/SimulationExecution.js b/SimulationExecution.js index d6d2c82e4..80def9f64 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -17,6 +17,7 @@ getContainer: getContainer, setTimeFrame: setTimeFrame, setDatetime: setDatetime, + setCoordinateSystem: setCoordinateSystem, recalculateScale: recalculateScale, draw: draw }; @@ -27,7 +28,7 @@ container.initialize(); thisObject.container = container; - let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -65,22 +66,24 @@ plotLines = undefined; thisObject.fitFunction = undefined + + coordinateSystem = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> finalize -> err = " + err.stack.stack); } } } - function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, pCoordinateSystem, callBackFunction) { try { datetime = pDatetime; timeFrame = pTimeFrame; + coordinateSystem = pCoordinateSystem fileSequence = pStorage.fileSequences[0]; recalculate(); - recalculateScale(); filesUpdatedEventSubscriptionId = fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); @@ -89,7 +92,6 @@ dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { recalculate(); - recalculateScale(); }) callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); @@ -123,8 +125,12 @@ recalculate(); } - function setDatetime(newDatetime) { - datetime = newDatetime; + function setDatetime(pDatetime) { + datetime = pDatetime; + } + + function setCoordinateSystem(pCoordinateSystem) { + coordinateSystem = pCoordinateSystem } function onViewportPositionChanged() { diff --git a/Strategies.js b/Strategies.js index bda368538..4f8aa50eb 100644 --- a/Strategies.js +++ b/Strategies.js @@ -18,6 +18,7 @@ getContainer: getContainer, setTimeFrame: setTimeFrame, setDatetime: setDatetime, + setCoordinateSystem: setCoordinateSystem, draw: draw, recalculateScale: recalculateScale, @@ -36,7 +37,7 @@ container.initialize(); thisObject.container = container; - let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -89,13 +90,15 @@ strategyImages = undefined; thisObject.fitFunction = undefined + + coordinateSystem = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } - function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, pCoordinateSystem, callBackFunction) { try { @@ -108,13 +111,12 @@ datetime = pDatetime; timeFrame = pTimeFrame; + coordinateSystem = pCoordinateSystem /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - recalculateScale(); - /* Now we set the right files according to current Period. */ marketFile = marketFiles.getFile(pTimeFrame); @@ -135,7 +137,6 @@ /* Ready for when dimmension changes. */ dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { - recalculateScale() recalculate(); }) @@ -234,11 +235,11 @@ } function setDatetime(pDatetime) { - - if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } - datetime = pDatetime; + } + function setCoordinateSystem(pCoordinateSystem) { + coordinateSystem = pCoordinateSystem } function onDailyFileLoaded(event) { diff --git a/Trades.js b/Trades.js index b7ac90273..daecc4c02 100644 --- a/Trades.js +++ b/Trades.js @@ -18,6 +18,7 @@ getContainer: getContainer, setTimeFrame: setTimeFrame, setDatetime: setDatetime, + setCoordinateSystem: setCoordinateSystem, draw: draw, recalculateScale: recalculateScale, @@ -36,7 +37,7 @@ container.initialize(); thisObject.container = container; - let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -87,13 +88,15 @@ fileCursor = undefined; thisObject.fitFunction = undefined + + coordinateSystem = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } - function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, pCoordinateSystem, callBackFunction) { try { @@ -106,13 +109,12 @@ datetime = pDatetime; timeFrame = pTimeFrame; + coordinateSystem = pCoordinateSystem /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - recalculateScale(); - /* Now we set the right files according to current Period. */ marketFile = marketFiles.getFile(pTimeFrame); @@ -133,7 +135,6 @@ /* Ready for when dimmension changes. */ dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { - recalculateScale() recalculate(); }) @@ -227,11 +228,11 @@ } function setDatetime(pDatetime) { - - if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } - datetime = pDatetime; + } + function setCoordinateSystem(pCoordinateSystem) { + coordinateSystem = pCoordinateSystem } function onDailyFileLoaded(event) { diff --git a/TradingSimulation.js b/TradingSimulation.js index 8353cf7aa..98a85bd6b 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -17,6 +17,7 @@ getContainer: getContainer, setTimeFrame: setTimeFrame, setDatetime: setDatetime, + setCoordinateSystem: setCoordinateSystem, draw: draw, recalculateScale: recalculateScale, @@ -35,7 +36,7 @@ container.initialize(); thisObject.container = container; - let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -93,13 +94,15 @@ fileCursor = undefined; thisObject.fitFunction = undefined + + coordinateSystem = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } - function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, pCoordinateSystem, callBackFunction) { try { @@ -110,13 +113,12 @@ datetime = pDatetime; timeFrame = pTimeFrame; + coordinateSystem = pCoordinateSystem /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - recalculateScale(); - /* Now we set the right files according to current Period. */ marketFile = marketFiles.getFile(pTimeFrame); @@ -137,7 +139,6 @@ /* Ready for when dimmension changes. */ dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { - recalculateScale() recalculate(); }) @@ -221,9 +222,11 @@ } function setDatetime(pDatetime) { - datetime = pDatetime; + } + function setCoordinateSystem(pCoordinateSystem) { + coordinateSystem = pCoordinateSystem } function onDailyFileLoaded(event) { From c3010097c6adc3890da8282e98c703d3432ca614 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 30 Jan 2020 22:05:00 +0100 Subject: [PATCH 116/157] no more getUserPosition --- SimulationExecution.js | 11 ++++++++--- Strategies.js | 12 ++++++++---- Trades.js | 12 ++++++++---- TradingSimulation.js | 12 ++++++++---- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/SimulationExecution.js b/SimulationExecution.js index 80def9f64..fa2891643 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -41,6 +41,7 @@ let previousNotesSetKey; + let onMouseOverEventSuscriptionId let offsetChangedEventSubscriptionId let filesUpdatedEventSubscriptionId let dimmensionsChangedEventSubscriptionId @@ -51,7 +52,7 @@ try { /* Stop listening to the necesary events. */ - + thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); fileSequence.eventHandler.stopListening(filesUpdatedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) @@ -87,6 +88,7 @@ filesUpdatedEventSubscriptionId = fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + onMouseOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) /* Ready for when dimmension changes. */ @@ -101,6 +103,11 @@ } } + function onMouseOver(event) { + let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + userPositionDate = userPosition.valueOf() + } + function getContainer(point) { try { let container; @@ -347,8 +354,6 @@ function plotChart() { try { - let userPosition = getUserPosition() - let userPositionDate = userPosition.point.x let currentRecord let point = { diff --git a/Strategies.js b/Strategies.js index 4f8aa50eb..d511fb226 100644 --- a/Strategies.js +++ b/Strategies.js @@ -53,6 +53,7 @@ let strategies = []; let strategyImages = []; + let onMouseOverEventSuscriptionId let zoomChangedEventSubscriptionId let offsetChangedEventSubscriptionId let dragFinishedEventSubscriptionId @@ -68,7 +69,7 @@ if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } /* Stop listening to the necesary events. */ - + thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); @@ -129,6 +130,7 @@ dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); + onMouseOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) /* Get ready for plotting. */ @@ -153,6 +155,11 @@ } } + function onMouseOver(event) { + let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + userPositionDate = userPosition.valueOf() + } + function getContainer(point) { try { @@ -483,9 +490,6 @@ try { - let userPosition = getUserPosition() - let userPositionDate = userPosition.point.x - thisObject.container.eventHandler.raiseEvent("Current Strategy Record Changed", undefined); let record; diff --git a/Trades.js b/Trades.js index daecc4c02..bfda0ef71 100644 --- a/Trades.js +++ b/Trades.js @@ -53,6 +53,7 @@ let trades = []; let headers; + let onMouseOverEventSuscriptionId let zoomChangedEventSubscriptionId let offsetChangedEventSubscriptionId let dragFinishedEventSubscriptionId @@ -68,7 +69,7 @@ if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); } /* Stop listening to the necesary events. */ - + thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); @@ -127,6 +128,7 @@ dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); + onMouseOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) /* Get ready for plotting. */ @@ -146,6 +148,11 @@ } } + function onMouseOver(event) { + let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + userPositionDate = userPosition.valueOf() + } + function getContainer(point) { try { @@ -464,9 +471,6 @@ try { - let userPosition = getUserPosition() - let userPositionDate = userPosition.point.x - thisObject.container.eventHandler.raiseEvent("Current Trade Record Changed", undefined); let record; diff --git a/TradingSimulation.js b/TradingSimulation.js index 98a85bd6b..66d879c98 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -55,6 +55,7 @@ let imageTakeProfitPhase; let imageRecord; + let onMouseOverEventSuscriptionId let zoomChangedEventSubscriptionId let offsetChangedEventSubscriptionId let dragFinishedEventSubscriptionId @@ -68,7 +69,7 @@ try { /* Stop listening to the necesary events. */ - + thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); @@ -131,6 +132,7 @@ dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); + onMouseOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) /* Get ready for plotting. */ @@ -156,6 +158,11 @@ } } + function onMouseOver(event) { + let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + userPositionDate = userPosition.valueOf() + } + function getContainer(point) { let container; /* First we check if this point is inside this space. */ @@ -505,9 +512,6 @@ try { - let userPosition = getUserPosition() - let userPositionDate = userPosition.point.x - let record; /* Now we calculate and plot the records */ From 7752458a917e0924024d1173c96baf0a3bd46798 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 31 Jan 2020 11:47:23 +0100 Subject: [PATCH 117/157] events at coordinate system --- SimulationExecution.js | 18 ++++++++++++++++++ Strategies.js | 28 ++++++++++++++++++++++++++-- Trades.js | 28 ++++++++++++++++++++++++++-- TradingSimulation.js | 28 ++++++++++++++++++++++++++-- 4 files changed, 96 insertions(+), 6 deletions(-) diff --git a/SimulationExecution.js b/SimulationExecution.js index fa2891643..9f56b4c69 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -45,7 +45,9 @@ let offsetChangedEventSubscriptionId let filesUpdatedEventSubscriptionId let dimmensionsChangedEventSubscriptionId + let scaleChangedEventSubscriptionId + let userPositionDate return thisObject; function finalize() { @@ -68,6 +70,7 @@ thisObject.fitFunction = undefined + finalizeCoordinateSystem() coordinateSystem = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> finalize -> err = " + err.stack.stack); } @@ -81,6 +84,7 @@ datetime = pDatetime; timeFrame = pTimeFrame; coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() fileSequence = pStorage.fileSequences[0]; @@ -103,6 +107,18 @@ } } + function initializeCoordinateSystem() { + scaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged) + } + + function finalizeCoordinateSystem() { + coordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId) + } + + function onScaleChanged() { + recalculate(); + } + function onMouseOver(event) { let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() @@ -137,7 +153,9 @@ } function setCoordinateSystem(pCoordinateSystem) { + finalizeCoordinateSystem() coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() } function onViewportPositionChanged() { diff --git a/Strategies.js b/Strategies.js index d511fb226..272a663be 100644 --- a/Strategies.js +++ b/Strategies.js @@ -60,7 +60,9 @@ let dimmensionsChangedEventSubscriptionId let marketFilesUpdatedEventSubscriptionId let dailyFilesUpdatedEventSubscriptionId + let scaleChangedEventSubscriptionId + let userPositionDate return thisObject; function finalize() { @@ -92,6 +94,7 @@ thisObject.fitFunction = undefined + finalizeCoordinateSystem() coordinateSystem = undefined } catch (err) { @@ -113,6 +116,7 @@ datetime = pDatetime; timeFrame = pTimeFrame; coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -155,6 +159,18 @@ } } + function initializeCoordinateSystem() { + scaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged) + } + + function finalizeCoordinateSystem() { + coordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId) + } + + function onScaleChanged() { + recalculate(); + } + function onMouseOver(event) { let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() @@ -246,7 +262,9 @@ } function setCoordinateSystem(pCoordinateSystem) { + finalizeCoordinateSystem() coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() } function onDailyFileLoaded(event) { @@ -367,7 +385,10 @@ record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; - if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + if ( + (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && + (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) + ) { strategies.push(record); @@ -439,7 +460,10 @@ strategies.push(record); - if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + if ( + (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && + (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) + ) { thisObject.currentRecord = record; thisObject.container.eventHandler.raiseEvent("Current Strategy Changed", thisObject.currentRecord); diff --git a/Trades.js b/Trades.js index bfda0ef71..db72ed397 100644 --- a/Trades.js +++ b/Trades.js @@ -60,7 +60,9 @@ let dimmensionsChangedEventSubscriptionId let marketFilesUpdatedEventSubscriptionId let dailyFilesUpdatedEventSubscriptionId + let scaleChangedEventSubscriptionId + let userPositionDate return thisObject; function finalize() { @@ -90,6 +92,7 @@ thisObject.fitFunction = undefined + finalizeCoordinateSystem() coordinateSystem = undefined } catch (err) { @@ -111,6 +114,7 @@ datetime = pDatetime; timeFrame = pTimeFrame; coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -148,6 +152,18 @@ } } + function initializeCoordinateSystem() { + scaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged) + } + + function finalizeCoordinateSystem() { + coordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId) + } + + function onScaleChanged() { + recalculate(); + } + function onMouseOver(event) { let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() @@ -239,7 +255,9 @@ } function setCoordinateSystem(pCoordinateSystem) { + finalizeCoordinateSystem() coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() } function onDailyFileLoaded(event) { @@ -354,7 +372,10 @@ record.endRate = dailyFile[i][5]; record.exitType = dailyFile[i][6]; - if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + if ( + (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && + (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) + ) { trades.push(record); @@ -416,7 +437,10 @@ record.endRate = marketFile[i][5]; record.exitType = marketFile[i][6]; - if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { + if ( + (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && + (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) + ) { trades.push(record); diff --git a/TradingSimulation.js b/TradingSimulation.js index 66d879c98..3bec2298f 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -62,7 +62,9 @@ let dimmensionsChangedEventSubscriptionId let marketFilesUpdatedEventSubscriptionId let dailyFilesUpdatedEventSubscriptionId + let scaleChangedEventSubscriptionId + let userPositionDate return thisObject; function finalize() { @@ -96,6 +98,7 @@ thisObject.fitFunction = undefined + finalizeCoordinateSystem() coordinateSystem = undefined } catch (err) { @@ -115,6 +118,7 @@ datetime = pDatetime; timeFrame = pTimeFrame; coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -158,6 +162,18 @@ } } + function initializeCoordinateSystem() { + scaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged) + } + + function finalizeCoordinateSystem() { + coordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId) + } + + function onScaleChanged() { + recalculate(); + } + function onMouseOver(event) { let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() @@ -233,7 +249,9 @@ } function setCoordinateSystem(pCoordinateSystem) { + finalizeCoordinateSystem() coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() } function onDailyFileLoaded(event) { @@ -370,7 +388,10 @@ record.positionPeriods = dailyFile[i][34]; record.positionDays = dailyFile[i][35]; - if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + if ( + (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && + (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) + ) { records.push(record); @@ -458,7 +479,10 @@ record.positionPeriods = marketFile[i][34]; record.positionDays = marketFile[i][35]; - if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { + if ( + (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && + (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) + ) { records.push(record); From 383069cdb690476caf4c0cbb94bc6ded6c326c05 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 31 Jan 2020 20:16:44 +0100 Subject: [PATCH 118/157] Cleaning --- Conditions.js | 35 ----------------------------------- SimulationExecution.js | 30 ------------------------------ Strategies.js | 31 ------------------------------- Trades.js | 31 ------------------------------- TradingSimulation.js | 30 ------------------------------ 5 files changed, 157 deletions(-) diff --git a/Conditions.js b/Conditions.js index 01ae2ca3a..c95c14967 100644 --- a/Conditions.js +++ b/Conditions.js @@ -18,7 +18,6 @@ setTimeFrame: setTimeFrame, setDatetime: setDatetime, draw: draw, - recalculateScale: recalculateScale, /* Events declared outside the plotter. */ @@ -111,8 +110,6 @@ marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - recalculateScale(); - /* Now we set the right files according to current Period. */ marketFile = marketFiles.getFile(pTimeFrame); @@ -133,7 +130,6 @@ /* Ready for when dimmension changes. */ dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { - recalculateScale() recalculate(); }) @@ -444,37 +440,6 @@ } } - function recalculateScale() { - - try { - - - if (coordinateSystem.maxValue > 0) { return; } // Already calculated. - - let minValue = { - x: MIN_PLOTABLE_DATE.valueOf(), - y: 0 - }; - - let maxValue = { - x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary - }; - - - coordinateSystem.initialize( - minValue, - maxValue, - thisObject.container.frame.width, - thisObject.container.frame.height - ); - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } - } - } - function plotChart() { try { diff --git a/SimulationExecution.js b/SimulationExecution.js index 9f56b4c69..2164905d7 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -18,7 +18,6 @@ setTimeFrame: setTimeFrame, setDatetime: setDatetime, setCoordinateSystem: setCoordinateSystem, - recalculateScale: recalculateScale, draw: draw }; @@ -336,35 +335,6 @@ } } - function recalculateScale() { - - try { - - if (fileSequence === undefined) { return; } // We need the market file to be loaded to make the calculation. - if (coordinateSystem.maxValue > 0) { return; } // Already calculated. - - let minValue = { - x: MIN_PLOTABLE_DATE.valueOf(), - y: 0 - }; - - let maxValue = { - x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary - }; - - coordinateSystem.initialize( - minValue, - maxValue, - thisObject.container.frame.width, - thisObject.container.frame.height - ); - - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] ' + MODULE_NAME + ' -> recalculateScale -> err = " + err.stack); } - } - } - function draw() { plotChart(); } diff --git a/Strategies.js b/Strategies.js index 272a663be..e28e54e06 100644 --- a/Strategies.js +++ b/Strategies.js @@ -20,7 +20,6 @@ setDatetime: setDatetime, setCoordinateSystem: setCoordinateSystem, draw: draw, - recalculateScale: recalculateScale, /* Events declared outside the plotter. */ @@ -480,36 +479,6 @@ } } - function recalculateScale() { - - try { - - if (coordinateSystem.maxValue > 0) { return; } // Already calculated. - - let minValue = { - x: MIN_PLOTABLE_DATE.valueOf(), - y: 0 - }; - - let maxValue = { - x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary - }; - - - coordinateSystem.initialize( - minValue, - maxValue, - thisObject.container.frame.width, - thisObject.container.frame.height - ); - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } - } - } - function plotChart() { try { diff --git a/Trades.js b/Trades.js index db72ed397..f920f748e 100644 --- a/Trades.js +++ b/Trades.js @@ -20,7 +20,6 @@ setDatetime: setDatetime, setCoordinateSystem: setCoordinateSystem, draw: draw, - recalculateScale: recalculateScale, /* Events declared outside the plotter. */ @@ -461,36 +460,6 @@ } } - function recalculateScale() { - - try { - - if (coordinateSystem.maxValue > 0) { return; } // Already calculated. - - let minValue = { - x: MIN_PLOTABLE_DATE.valueOf(), - y: 0 - }; - - let maxValue = { - x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary - }; - - - coordinateSystem.initialize( - minValue, - maxValue, - thisObject.container.frame.width, - thisObject.container.frame.height - ); - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } - } - } - function plotChart() { try { diff --git a/TradingSimulation.js b/TradingSimulation.js index 3bec2298f..21d966750 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -19,7 +19,6 @@ setDatetime: setDatetime, setCoordinateSystem: setCoordinateSystem, draw: draw, - recalculateScale: recalculateScale, /* Events declared outside the plotter. */ @@ -503,35 +502,6 @@ } } - function recalculateScale() { - - try { - - if (coordinateSystem.maxValue > 0) { return; } // Already calculated. - - let minValue = { - x: MIN_PLOTABLE_DATE.valueOf(), - y: 0 - }; - - let maxValue = { - x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary - }; - - coordinateSystem.initialize( - minValue, - maxValue, - thisObject.container.frame.width, - thisObject.container.frame.height - ); - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } - } - } - function plotChart() { try { From 674b007e1fe3dfeef3ee9821df52fa7bb135c16a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Feb 2020 13:38:20 +0100 Subject: [PATCH 119/157] bug fixed --- TradingSimulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 21d966750..856a22f61 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -668,7 +668,7 @@ let imagePosition = { x: recordPoint4.x + imageOffset.x, - y: recordPoint4.y + imageOffset.y + y: 0 } imagePosition = canvas.chartSpace.viewport.fitIntoVisibleArea(imagePosition) From 8584f49408f220fb047ceac5f8e4ad55d8b0258f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 12 Feb 2020 19:17:09 +0100 Subject: [PATCH 120/157] Refactoring --- Conditions.js | 8 ++++---- SimulationExecution.js | 2 +- Strategies.js | 10 +++++----- Trades.js | 10 +++++----- TradingSimulation.js | 10 +++++----- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Conditions.js b/Conditions.js index c95c14967..53c535088 100644 --- a/Conditions.js +++ b/Conditions.js @@ -308,8 +308,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -390,8 +390,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); diff --git a/SimulationExecution.js b/SimulationExecution.js index 2164905d7..e937af57d 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -119,7 +119,7 @@ } function onMouseOver(event) { - let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + let userPosition = getDateFromPointAtBrowserCanvas(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() } diff --git a/Strategies.js b/Strategies.js index e28e54e06..4da8a543c 100644 --- a/Strategies.js +++ b/Strategies.js @@ -171,7 +171,7 @@ } function onMouseOver(event) { - let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + let userPosition = getDateFromPointAtBrowserCanvas(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() } @@ -344,8 +344,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -427,8 +427,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); diff --git a/Trades.js b/Trades.js index f920f748e..cf8d612ce 100644 --- a/Trades.js +++ b/Trades.js @@ -164,7 +164,7 @@ } function onMouseOver(event) { - let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + let userPosition = getDateFromPointAtBrowserCanvas(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() } @@ -337,8 +337,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -414,8 +414,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); diff --git a/TradingSimulation.js b/TradingSimulation.js index 856a22f61..3e0604399 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -174,7 +174,7 @@ } function onMouseOver(event) { - let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + let userPosition = getDateFromPointAtBrowserCanvas(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() } @@ -327,8 +327,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -428,8 +428,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); From f957ff0b5142ade355f34e27aa3dc309a6726d87 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 14 Feb 2020 21:54:53 +0100 Subject: [PATCH 121/157] refactoring --- Conditions.js | 22 +++++++-------- SimulationExecution.js | 56 ++++++++++++++++++------------------- SimulationExecutionPanel.js | 24 ++++++++-------- Strategies.js | 28 +++++++++---------- Trades.js | 34 +++++++++++----------- TradingSimulation.js | 54 +++++++++++++++++------------------ TradingSimulationPanel.js | 4 +-- 7 files changed, 111 insertions(+), 111 deletions(-) diff --git a/Conditions.js b/Conditions.js index 53c535088..4e77bac9f 100644 --- a/Conditions.js +++ b/Conditions.js @@ -68,8 +68,8 @@ /* Stop listening to the necesary events. */ - canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); - canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); @@ -117,8 +117,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); - offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + zoomChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -308,8 +308,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -390,8 +390,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -484,14 +484,14 @@ if (currentRecord === undefined) { return; } if (currentRecord.conditionsNames === undefined) { return; } - if (canvas.designerSpace.workspace === undefined) { return; } + if (canvas.designSpace.workspace === undefined) { return; } /* We will get now the designer trading system */ let designerTradingSystem let fileTradingSystem = currentRecord.conditionsNames; - for (let i = 0; i < canvas.designerSpace.workspace.workspaceNode.rootNodes.length; i++) { - let rootNode = canvas.designerSpace.workspace.workspaceNode.rootNodes[i] + for (let i = 0; i < canvas.designSpace.workspace.workspaceNode.rootNodes.length; i++) { + let rootNode = canvas.designSpace.workspace.workspaceNode.rootNodes[i] if (rootNode.type === 'Definition') { if (rootNode.tradingSystem.id === fileTradingSystem.id) { designerTradingSystem = rootNode.tradingSystem diff --git a/SimulationExecution.js b/SimulationExecution.js index e937af57d..2717579d5 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -54,7 +54,7 @@ /* Stop listening to the necesary events. */ thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) - canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); fileSequence.eventHandler.stopListening(filesUpdatedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) @@ -90,7 +90,7 @@ recalculate(); filesUpdatedEventSubscriptionId = fileSequence.eventHandler.listenToEvent("Files Updated", onFilesUpdated); // Only the first sequence is supported right now. - offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + offsetChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); onMouseOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) /* Ready for when dimmension changes. */ @@ -370,9 +370,9 @@ point = coordinateSystem.transformThisPoint(point); point = transformThisPoint(point, thisObject.container); - if (point.x < canvas.chartSpace.viewport.visibleArea.bottomLeft.x || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x) { continue; } + if (point.x < canvas.chartingSpace.viewport.visibleArea.bottomLeft.x || point.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x) { continue; } - point = canvas.chartSpace.viewport.fitIntoVisibleArea(point); + point = canvas.chartingSpace.viewport.fitIntoVisibleArea(point); point = thisObject.fitFunction(point); let isCurrentRecord = false; @@ -410,17 +410,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); + point1 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; @@ -429,8 +429,8 @@ currentRecord.timeFrame = diff - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); point2 = thisObject.fitFunction(point2); point3 = thisObject.fitFunction(point3); @@ -485,17 +485,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); + point1 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; @@ -504,8 +504,8 @@ currentRecord.timeFrame = diff - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); point2 = thisObject.fitFunction(point2); point3 = thisObject.fitFunction(point3); @@ -558,17 +558,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); + point1 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; @@ -577,8 +577,8 @@ currentRecord.timeFrame = diff - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); point2 = thisObject.fitFunction(point2); point3 = thisObject.fitFunction(point3); @@ -632,17 +632,17 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); + point1 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); point3 = coordinateSystem.transformThisPoint(point3); point3 = transformThisPoint(point3, thisObject.container); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); point3 = thisObject.fitFunction(point3); let diff = point2.x - point3.x; @@ -651,8 +651,8 @@ currentRecord.timeFrame = diff - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); point2 = thisObject.fitFunction(point2); point3 = thisObject.fitFunction(point3); @@ -704,7 +704,7 @@ browserCanvasContext.arc(point.x, point.y, currentRadius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); - if (point.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + if (point.x < canvas.chartingSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } @@ -724,7 +724,7 @@ browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); - if (point.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + if (point.x < canvas.chartingSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } @@ -755,12 +755,12 @@ point1 = coordinateSystem.transformThisPoint(point1); point1 = transformThisPoint(point1, thisObject.container); - point1 = canvas.chartSpace.viewport.fitIntoVisibleArea(point1); + point1 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point1); point1 = thisObject.fitFunction(point1); point2 = coordinateSystem.transformThisPoint(point2); point2 = transformThisPoint(point2, thisObject.container); - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point2 = thisObject.fitFunction(point2); browserCanvasContext.beginPath(); diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index d809b2ef5..24ee27d23 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -40,8 +40,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL; thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; - thisObject.container.frame.position.x = canvas.chartSpace.viewport.visibleArea.topLeft.x + thisObject.container.frame.width * 4; - thisObject.container.frame.position.y = canvas.chartSpace.viewport.visibleArea.topRight.y; + thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topLeft.x + thisObject.container.frame.width * 4; + thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; panelTabButton = newPanelTabButton() panelTabButton.parentContainer = thisObject.container @@ -150,8 +150,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu point2.y = point2.y - diff; point3.y = point3.y - diff; - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); browserCanvasContext.beginPath(); @@ -210,8 +210,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu point2.y = point2.y + diff; point3.y = point3.y + diff; - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); browserCanvasContext.beginPath(); @@ -268,8 +268,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu point2.y = point2.y - diff; point3.y = point3.y - diff; - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); browserCanvasContext.beginPath(); @@ -326,8 +326,8 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu point2.y = point2.y + diff; point3.y = point3.y + diff; - point2 = canvas.chartSpace.viewport.fitIntoVisibleArea(point2); - point3 = canvas.chartSpace.viewport.fitIntoVisibleArea(point3); + point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); + point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); browserCanvasContext.beginPath(); @@ -366,7 +366,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu browserCanvasContext.arc(point.x, point.y, currentRadius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); - if (point.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + if (point.x < canvas.chartingSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } browserCanvasContext.setLineDash([0, 0]) @@ -384,7 +384,7 @@ function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecu browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true); browserCanvasContext.closePath(); - if (point.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { + if (point.x < canvas.chartingSpace.viewport.visibleArea.topLeft.x + 50 || point.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else { browserCanvasContext.fill(); } browserCanvasContext.setLineDash([0, 0]) diff --git a/Strategies.js b/Strategies.js index 4da8a543c..be159d9de 100644 --- a/Strategies.js +++ b/Strategies.js @@ -71,8 +71,8 @@ /* Stop listening to the necesary events. */ thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) - canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); - canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); @@ -128,8 +128,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); - offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + zoomChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -146,7 +146,7 @@ }) for (let i = 1; i < 15; i++) { - let strategyImage = canvas.designerSpace.iconByUiObjectType.get('Strategy'); + let strategyImage = canvas.designSpace.iconByUiObjectType.get('Strategy'); strategyImages.push(strategyImage); } @@ -344,8 +344,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -427,8 +427,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -521,17 +521,17 @@ recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); recordPoint4 = transformThisPoint(recordPoint4, thisObject.container); - if (recordPoint2.x < canvas.chartSpace.viewport.visibleArea.bottomLeft.x || recordPoint1.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x) { + if (recordPoint2.x < canvas.chartingSpace.viewport.visibleArea.bottomLeft.x || recordPoint1.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x) { continue; } recordPoint3.y = recordPoint1.y + 2000; recordPoint4.y = recordPoint1.y + 2000; - recordPoint1 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint1); - recordPoint2 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint2); - recordPoint3 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint3); - recordPoint4 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint4); + recordPoint1 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint1); + recordPoint2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint2); + recordPoint3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint3); + recordPoint4 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint4); recordPoint1 = thisObject.fitFunction(recordPoint1, undefined, 30); recordPoint2 = thisObject.fitFunction(recordPoint2, undefined, 30); diff --git a/Trades.js b/Trades.js index cf8d612ce..d5bdcb9a1 100644 --- a/Trades.js +++ b/Trades.js @@ -71,8 +71,8 @@ /* Stop listening to the necesary events. */ thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) - canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); - canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); @@ -126,8 +126,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); - offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + zoomChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -337,8 +337,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -414,8 +414,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -504,13 +504,13 @@ recordPoint2 = transformThisPoint(recordPoint2, thisObject.container); recordPoint3 = transformThisPoint(recordPoint3, thisObject.container); - if (recordPoint2.x < canvas.chartSpace.viewport.visibleArea.bottomLeft.x || recordPoint1.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x) { + if (recordPoint2.x < canvas.chartingSpace.viewport.visibleArea.bottomLeft.x || recordPoint1.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x) { continue; } - recordPoint1 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint1); - recordPoint2 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint2); - recordPoint3 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint3); + recordPoint1 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint1); + recordPoint2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint2); + recordPoint3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint3); recordPoint1 = thisObject.fitFunction(recordPoint1); recordPoint2 = thisObject.fitFunction(recordPoint2); @@ -580,17 +580,17 @@ point.y = recordPoint3.y - 100 } - point = canvas.chartSpace.viewport.fitIntoVisibleArea(point); + point = canvas.chartingSpace.viewport.fitIntoVisibleArea(point); point = thisObject.fitFunction(point, undefined, 50); if ( - recordPoint3.x < canvas.chartSpace.viewport.visibleArea.topLeft.x + 250 + recordPoint3.x < canvas.chartingSpace.viewport.visibleArea.topLeft.x + 250 || - recordPoint3.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x - 250 + recordPoint3.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x - 250 || - recordPoint3.y > canvas.chartSpace.viewport.visibleArea.bottomRight.y - 150 + recordPoint3.y > canvas.chartingSpace.viewport.visibleArea.bottomRight.y - 150 || - recordPoint3.y < canvas.chartSpace.viewport.visibleArea.topLeft.y + 150 + recordPoint3.y < canvas.chartingSpace.viewport.visibleArea.topLeft.y + 150 ) { // we do not write any text } else { diff --git a/TradingSimulation.js b/TradingSimulation.js index 3e0604399..b82eae6b0 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -71,8 +71,8 @@ /* Stop listening to the necesary events. */ thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) - canvas.chartSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); - canvas.chartSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); + canvas.chartingSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId); @@ -130,8 +130,8 @@ /* Listen to the necesary events. */ - zoomChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); - offsetChangedEventSubscriptionId = canvas.chartSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); + zoomChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Zoom Changed", onViewportZoomChanged); + offsetChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent("Position Changed", onViewportPositionChanged); dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); @@ -149,9 +149,9 @@ /* Loading a few icons */ - imageStopLossPhase = canvas.designerSpace.iconByUiObjectType.get('Stop'); - imageTakeProfitPhase = canvas.designerSpace.iconByUiObjectType.get('Phase'); - imageRecord = canvas.designerSpace.iconByUiObjectType.get('Trading System'); + imageStopLossPhase = canvas.designSpace.iconByUiObjectType.get('Stop'); + imageTakeProfitPhase = canvas.designSpace.iconByUiObjectType.get('Phase'); + imageRecord = canvas.designSpace.iconByUiObjectType.get('Trading System'); callBackFunction(); @@ -327,8 +327,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -428,8 +428,8 @@ let daysOnSides = getSideDays(timeFrame); - let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); - let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem); + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartingSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -627,16 +627,16 @@ recordPoint9 = transformThisPoint(recordPoint9, thisObject.container); recordPoint10 = transformThisPoint(recordPoint10, thisObject.container); - recordPoint1 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint1); - recordPoint2 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint2); - recordPoint3 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint3); - recordPoint4 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint4); - recordPoint5 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint5); - recordPoint6 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint6); - recordPoint7 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint7); - recordPoint8 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint8); - recordPoint9 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint9); - recordPoint10 = canvas.chartSpace.viewport.fitIntoVisibleArea(recordPoint10); + recordPoint1 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint1); + recordPoint2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint2); + recordPoint3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint3); + recordPoint4 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint4); + recordPoint5 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint5); + recordPoint6 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint6); + recordPoint7 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint7); + recordPoint8 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint8); + recordPoint9 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint9); + recordPoint10 = canvas.chartingSpace.viewport.fitIntoVisibleArea(recordPoint10); recordPoint1 = thisObject.fitFunction(recordPoint1); recordPoint2 = thisObject.fitFunction(recordPoint2); @@ -671,7 +671,7 @@ y: 0 } - imagePosition = canvas.chartSpace.viewport.fitIntoVisibleArea(imagePosition) + imagePosition = canvas.chartingSpace.viewport.fitIntoVisibleArea(imagePosition) imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) if (imageRecord.canDrawIcon === true) { @@ -683,7 +683,7 @@ browserCanvasContext.restore(); } - if (recordPoint5.x < canvas.chartSpace.viewport.visibleArea.bottomLeft.x || recordPoint5.x > canvas.chartSpace.viewport.visibleArea.bottomRight.x) { + if (recordPoint5.x < canvas.chartingSpace.viewport.visibleArea.bottomLeft.x || recordPoint5.x > canvas.chartingSpace.viewport.visibleArea.bottomRight.x) { continue; } @@ -748,14 +748,14 @@ y: recordPoint6.y - imageSize * 1.25 + yOffset } - imagePosition = canvas.chartSpace.viewport.fitIntoVisibleArea(imagePosition) + imagePosition = canvas.chartingSpace.viewport.fitIntoVisibleArea(imagePosition) imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) let labelPosition = { x: recordPoint6.x - imageSize / 2 - 3, y: recordPoint6.y - imageSize * 1.5 + yOffset * 2 } - labelPosition = canvas.chartSpace.viewport.fitIntoVisibleArea(labelPosition) + labelPosition = canvas.chartingSpace.viewport.fitIntoVisibleArea(labelPosition) labelPosition = thisObject.fitFunction(labelPosition, undefined, 30) if (imageStopLossPhase.canDrawIcon === true && stopLossPhase > -1) { @@ -789,14 +789,14 @@ x: recordPoint10.x - imageSize * 2 / 3, y: recordPoint10.y + imageSize / 4 - yOffset } - imagePosition = canvas.chartSpace.viewport.fitIntoVisibleArea(imagePosition) + imagePosition = canvas.chartingSpace.viewport.fitIntoVisibleArea(imagePosition) imagePosition = thisObject.fitFunction(imagePosition, undefined, 0, 0, imageSize) labelPosition = { x: recordPoint10.x - imageSize * 1 / 3, y: recordPoint10.y + imageSize * 1.9 - yOffset * 2 } - labelPosition = canvas.chartSpace.viewport.fitIntoVisibleArea(labelPosition) + labelPosition = canvas.chartingSpace.viewport.fitIntoVisibleArea(labelPosition) labelPosition = thisObject.fitFunction(labelPosition, undefined, 30) if (imageTakeProfitPhase.canDrawIcon === true && takeProfitPhase > -1) { diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 048de40a3..5781fa645 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -31,8 +31,8 @@ function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulation thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; - thisObject.container.frame.position.x = canvas.chartSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; - thisObject.container.frame.position.y = canvas.chartSpace.viewport.visibleArea.topRight.y; + thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; + thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; panelTabButton = newPanelTabButton() panelTabButton.parentContainer = thisObject.container From afadd6d688d0f539a6f9b51a1e268ef85fbd4916 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 21 Feb 2020 13:50:48 +0100 Subject: [PATCH 122/157] upgrade --- Conditions.js | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/Conditions.js b/Conditions.js index 4e77bac9f..bab56a965 100644 --- a/Conditions.js +++ b/Conditions.js @@ -34,7 +34,7 @@ container.initialize(); thisObject.container = container; - let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let coordinateSystem let timeFrame; // This will hold the current Time Frame the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -58,6 +58,7 @@ let dimmensionsChangedEventSubscriptionId let marketFilesUpdatedEventSubscriptionId let dailyFilesUpdatedEventSubscriptionId + let scaleChangedEventSubscriptionId return thisObject; @@ -86,13 +87,15 @@ marketFile = undefined; fileCursor = undefined; + finalizeCoordinateSystem() + coordinateSystem = undefined } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } - function initialize(pStorage, pDatetime, pTimeFrame, callBackFunction) { + function initialize(pStorage, pDatetime, pTimeFrame, pCoordinateSystem, callBackFunction) { try { @@ -105,6 +108,8 @@ datetime = pDatetime; timeFrame = pTimeFrame; + coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -141,6 +146,23 @@ } } + function initializeCoordinateSystem() { + scaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged) + } + + function finalizeCoordinateSystem() { + coordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId) + } + + function onScaleChanged() { + recalculate(); + } + + function onMouseOver(event) { + let userPosition = getDateFromPointAtBrowserCanvas(event, thisObject.container, coordinateSystem) + userPositionDate = userPosition.valueOf() + } + function getContainer(point) { try { @@ -230,6 +252,12 @@ } + function setCoordinateSystem(pCoordinateSystem) { + finalizeCoordinateSystem() + coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() + } + function onDailyFileLoaded(event) { try { @@ -350,7 +378,10 @@ record.formulaErrors = dailyFile[1][i][7]; record.formulaValues = dailyFile[1][i][8]; - if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + if ( + (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && + (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) + ) { conditions.push(record); @@ -419,7 +450,10 @@ record.formulaErrors = marketFile[1][i][7]; record.formulaValues = marketFile[1][i][8]; - if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { + if ( + (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && + (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) + ) { conditions.push(record); @@ -444,9 +478,6 @@ try { - let userPosition = getUserPosition() - let userPositionDate = userPosition.point.x - thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", undefined); let conditionRecord; From dfef468f43f65200b7e1ebc1c91075a4ca68acb7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 22 Feb 2020 18:38:12 +0100 Subject: [PATCH 123/157] bug fixed --- Conditions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Conditions.js b/Conditions.js index bab56a965..3cd2549f7 100644 --- a/Conditions.js +++ b/Conditions.js @@ -60,6 +60,7 @@ let dailyFilesUpdatedEventSubscriptionId let scaleChangedEventSubscriptionId + let userPositionDate return thisObject; function finalize() { From 3a329c1e4bf4907c96c2b8acd12cb8d4afac733e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 11 Mar 2020 20:59:39 +0100 Subject: [PATCH 124/157] Rafactoring --- Conditions.js | 2 +- SimulationExecution.js | 2 +- SimulationExecutionPanel.js | 2 +- Strategies.js | 2 +- Trades.js | 2 +- TradingSimulation.js | 2 +- TradingSimulationPanel.js | 2 +- this.plotter.config.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Conditions.js b/Conditions.js index 3cd2549f7..a4d62f3c9 100644 --- a/Conditions.js +++ b/Conditions.js @@ -1,4 +1,4 @@ -function newAAMastersPlottersTradingSimulationConditions() { +function newMastersPlottersTradingSimulationConditions() { const MODULE_NAME = "Conditions Plotter"; const INFO_LOG = false; diff --git a/SimulationExecution.js b/SimulationExecution.js index 2717579d5..f1a7eb78f 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -1,4 +1,4 @@ -function newAAMastersPlottersTradingSimulationSimulationExecution() { +function newMastersPlottersTradingSimulationSimulationExecution() { const MODULE_NAME = "Simulation Execution Plotter"; const INTENSIVE_LOG = false; diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index 24ee27d23..bdc14e7db 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -1,5 +1,5 @@  -function newAAMastersPlottersTradingSimulationSimulationExecutionSimulationExecutionPanel() { +function newMastersPlottersTradingSimulationSimulationExecutionSimulationExecutionPanel() { let thisObject = { diff --git a/Strategies.js b/Strategies.js index be159d9de..d6f84e9e4 100644 --- a/Strategies.js +++ b/Strategies.js @@ -1,4 +1,4 @@ -function newAAMastersPlottersTradingSimulationStrategies() { +function newMastersPlottersTradingSimulationStrategies() { const MODULE_NAME = "Strategies Plotter"; const INFO_LOG = false; diff --git a/Trades.js b/Trades.js index d5bdcb9a1..0973949d8 100644 --- a/Trades.js +++ b/Trades.js @@ -1,4 +1,4 @@ -function newAAMastersPlottersTradingSimulationTrades() { +function newMastersPlottersTradingSimulationTrades() { const MODULE_NAME = "Trades Plotter"; const INFO_LOG = false; diff --git a/TradingSimulation.js b/TradingSimulation.js index b82eae6b0..5b31af848 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -1,4 +1,4 @@ -function newAAMastersPlottersTradingSimulationTradingSimulation() { +function newMastersPlottersTradingSimulationTradingSimulation() { const MODULE_NAME = "Simulation Plotter"; const ERROR_LOG = true; diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 5781fa645..054486fbd 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -1,5 +1,5 @@  -function newAAMastersPlottersTradingSimulationTradingSimulationTradingSimulationPanel() { +function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPanel() { let thisObject = { fitFunction: undefined, diff --git a/this.plotter.config.json b/this.plotter.config.json index d1c9d6830..d5ff7028d 100644 --- a/this.plotter.config.json +++ b/this.plotter.config.json @@ -1,7 +1,7 @@ { "displayName": "Plotters Trading Simulation", "codeName": "PlottersTradingSimulation", - "dataMine": "AAMasters", + "dataMine": "Masters", "modules": [ { "codeName": "TradingSimulation", From 3e5829925dbb0d89748c669307740f089dacddb3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 16 Mar 2020 08:12:46 +0100 Subject: [PATCH 125/157] Refactoring --- SimulationExecutionPanel.js | 20 ++++++++++---------- TradingSimulationPanel.js | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index bdc14e7db..37a002b81 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -20,7 +20,7 @@ function newMastersPlottersTradingSimulationSimulationExecutionSimulationExecuti container.frame.containerName = "Trading Execution"; let currentRecord; - let panelTabButton + let upDownButton return thisObject; @@ -31,8 +31,8 @@ function newMastersPlottersTradingSimulationSimulationExecutionSimulationExecuti thisObject.isVisible = undefined currentRecord = undefined - panelTabButton.finalize() - panelTabButton = undefined + upDownButton.finalize() + upDownButton = undefined } function initialize() { @@ -43,18 +43,18 @@ function newMastersPlottersTradingSimulationSimulationExecutionSimulationExecuti thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topLeft.x + thisObject.container.frame.width * 4; thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; - panelTabButton = newPanelTabButton() - panelTabButton.parentContainer = thisObject.container - panelTabButton.container.frame.parentFrame = thisObject.container.frame - panelTabButton.fitFunction = thisObject.fitFunction - panelTabButton.initialize() + upDownButton = newUpDownButton() + upDownButton.parentContainer = thisObject.container + upDownButton.container.frame.parentFrame = thisObject.container.frame + upDownButton.fitFunction = thisObject.fitFunction + upDownButton.initialize() } function getContainer(point) { if (thisObject.isVisible !== true) { return } let container; - container = panelTabButton.getContainer(point) + container = upDownButton.getContainer(point) if (container !== undefined) { return container } if (thisObject.container.frame.isThisPointHere(point, true) === true) { @@ -86,7 +86,7 @@ function newMastersPlottersTradingSimulationSimulationExecutionSimulationExecuti plot(); - panelTabButton.draw() + upDownButton.draw() } diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 054486fbd..5d30e25d1 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -21,7 +21,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa let currentRecord; let lastRecord; - let panelTabButton + let upDownButton return thisObject; @@ -34,11 +34,11 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; - panelTabButton = newPanelTabButton() - panelTabButton.parentContainer = thisObject.container - panelTabButton.container.frame.parentFrame = thisObject.container.frame - panelTabButton.fitFunction = thisObject.fitFunction - panelTabButton.initialize() + upDownButton = newUpDownButton() + upDownButton.parentContainer = thisObject.container + upDownButton.container.frame.parentFrame = thisObject.container.frame + upDownButton.fitFunction = thisObject.fitFunction + upDownButton.initialize() } @@ -53,14 +53,14 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa currentRecord = undefined lastRecord = undefined - panelTabButton = undefined + upDownButton = undefined } function getContainer(point) { if (thisObject.isVisible !== true) { return } let container; - container = panelTabButton.getContainer(point) + container = upDownButton.getContainer(point) if (container !== undefined) { return container } if (thisObject.container.frame.isThisPointHere(point, true) === true) { @@ -93,7 +93,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa plotCurrentRecordInfo(); - panelTabButton.draw() + upDownButton.draw() /* Define panel name */ if (thisObject.session !== undefined) { From 10481b68afa1fec2be7120c8c0fe79fcdebda2ee Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 09:30:00 +0100 Subject: [PATCH 126/157] reporting for autoscale --- TradingSimulation.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/TradingSimulation.js b/TradingSimulation.js index 5b31af848..1f0054a73 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -514,6 +514,14 @@ record = records[i]; + /* Contributing to Auto-Scale*/ + if (record.stopLoss !== 0) { + coordinateSystem.reportYValue(record.stopLoss) + } + if (record.takeProfit !== 0) { + coordinateSystem.reportYValue(record.takeProfit) + } + /* Send the current record to the panel */ if (userPositionDate >= record.begin && userPositionDate <= record.end) { From 83b55ee5e8d86ba5ae8dfd5267c402969aedfa42 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 10:21:56 +0100 Subject: [PATCH 127/157] quoted asset fix --- TradingSimulation.js | 10 ++++++---- TradingSimulationPanel.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 1f0054a73..9f62fd06d 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -384,8 +384,9 @@ record.minimunBalanceB = dailyFile[i][31]; record.maximunBalanceB = dailyFile[i][32]; record.baseAsset = dailyFile[i][33]; - record.positionPeriods = dailyFile[i][34]; - record.positionDays = dailyFile[i][35]; + record.quotedAsset = dailyFile[i][34]; + record.positionPeriods = dailyFile[i][35]; + record.positionDays = dailyFile[i][36]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -475,8 +476,9 @@ record.minimunBalanceB = marketFile[i][31]; record.maximunBalanceB = marketFile[i][32]; record.baseAsset = marketFile[i][33]; - record.positionPeriods = marketFile[i][34]; - record.positionDays = marketFile[i][35]; + record.quotedAsset = marketFile[i][34]; + record.positionPeriods = marketFile[i][35]; + record.positionDays = marketFile[i][36]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 5d30e25d1..7eb7b9496 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -270,7 +270,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa params.MIN_VALUE = currentRecord.minimunBalanceA params.MAX_VALUE = currentRecord.maximunBalanceA params.ASSET_LABEL = 'Asset A' - params.ASSET_NAME = DEFAULT_MARKET.assetB + params.ASSET_NAME = currentRecord.baseAsset params.LEFT_OFFSET = 100 params.POSITION_TAKEN = positionTaken params.BASE_ASSET = currentRecord.baseAsset @@ -284,7 +284,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa params.INIT_VALUE = currentRecord.initialBalanceB params.MAX_VALUE = currentRecord.maximunBalanceB params.ASSET_LABEL = 'Asset B' - params.ASSET_NAME = DEFAULT_MARKET.assetA + params.ASSET_NAME = currentRecord.quotedAsset params.LEFT_OFFSET = 220 params.POSITION_TAKEN = positionTaken params.BASE_ASSET = currentRecord.baseAsset From 994121d4ac0cd4e3a43ceabfe7f4b480b807d854 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 10:53:26 +0100 Subject: [PATCH 128/157] Panel Splitted in 2 --- TradingSimulationCurrentPositionPanel.js | 227 +++++++++++++++++++++++ TradingSimulationPanel.js | 38 +--- 2 files changed, 229 insertions(+), 36 deletions(-) create mode 100644 TradingSimulationCurrentPositionPanel.js diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js new file mode 100644 index 000000000..757229176 --- /dev/null +++ b/TradingSimulationCurrentPositionPanel.js @@ -0,0 +1,227 @@ + + + +function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationCurrentPositionPanel() { + + let thisObject = { + fitFunction: undefined, + onRecordChange: onRecordChange, + container: undefined, + session: undefined, + isVisible: true, + draw: draw, + getContainer: getContainer, + initialize: initialize, + finalize: finalize + }; + + let container = newContainer(); + container.initialize(); + thisObject.container = container; + + container.frame.containerName = "Simulation"; + + let currentRecord; + let lastRecord; + let upDownButton + + + return thisObject; + + function initialize() { + + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 1; + + thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; + thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; + + upDownButton = newUpDownButton() + upDownButton.parentContainer = thisObject.container + upDownButton.container.frame.parentFrame = thisObject.container.frame + upDownButton.fitFunction = thisObject.fitFunction + upDownButton.initialize() + + } + + function finalize() { + thisObject.session = undefined + + thisObject.container.finalize() + thisObject.container = undefined + thisObject.fitFunction = undefined + thisObject.onRecordChange = undefined + thisObject.isVisible = undefined + + currentRecord = undefined + lastRecord = undefined + upDownButton = undefined + } + + function getContainer(point) { + if (thisObject.isVisible !== true) { return } + let container; + + container = upDownButton.getContainer(point) + if (container !== undefined) { return container } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + + let checkPoint = { + x: point.x, + y: point.y + } + + checkPoint = thisObject.fitFunction(checkPoint) + + if (point.x === checkPoint.x && point.y === checkPoint.y) { + return thisObject.container; + } + } + } + + + function onRecordChange(records) { + + currentRecord = records.currentRecord; + lastRecord = records.lastRecord + + } + + + function draw() { + if (thisObject.isVisible !== true) { return } + thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); + + plotCurrentRecordInfo(); + + upDownButton.draw() + + /* Define panel name */ + if (thisObject.session !== undefined) { + const MAX_LABEL_LENGTH = 25 + if (thisObject.session.name.length > MAX_LABEL_LENGTH) { + container.frame.containerName = thisObject.session.name.substring(0, MAX_LABEL_LENGTH) + '...' + } else { + container.frame.containerName = thisObject.session.name + } + } + } + + + function plotCurrentRecordInfo() { + + if (currentRecord === undefined) { return; } + + const frameBodyHeight = thisObject.container.frame.getBodyHeight(); + const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; + + const X_AXIS = thisObject.container.frame.width / 2; + const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; + + + /* put the labels with the records values */ + + browserCanvasContext.beginPath(); + + let y = 0; + let increment = 0.024 * 2.5; + + y = y + increment; + y = y + increment; + printLabel('Current Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); + + y = y + increment; + printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + y = y + increment; + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + y = y + increment; + printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + + + + function printLabel(labelToPrint, x, y, opacity, fontSize) { + + let labelPoint; + if (fontSize === undefined) { fontSize = 10 }; + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY; + + let label = '' + labelToPrint; + if (isNaN(label) === false) { + label = Number(label).toLocaleString(); + if ((label === "-0" || label === "0") && (labelToPrint !== 0) && (labelToPrint !== "0.00")) { + label = Number(labelToPrint).toFixed(6); + } + } + let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; + + labelPoint = { + x: x - xOffset, + y: y + }; + + labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); + labelPoint = thisObject.fitFunction(labelPoint) + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); + + } + + browserCanvasContext.closePath(); + browserCanvasContext.fill(); + + + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 7eb7b9496..a6404a0b5 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -29,7 +29,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa function initialize() { thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.0; thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; @@ -123,41 +123,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa browserCanvasContext.beginPath(); let y = 0; - let increment = 0.024; - - y = y + increment; - y = y + increment; - printLabel('Current Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); - - y = y + increment; - printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + let increment = 0.024 / 2 * 2.5; y = y + increment; y = y + increment; From 9214df955cbc5583971003140d4776b092c151f4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 11:38:24 +0100 Subject: [PATCH 129/157] removing printLabel --- TradingSimulationCurrentPositionPanel.js | 63 ++++-------------- TradingSimulationPanel.js | 83 +++++++----------------- 2 files changed, 37 insertions(+), 109 deletions(-) diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js index 757229176..c75a6bb2e 100644 --- a/TradingSimulationCurrentPositionPanel.js +++ b/TradingSimulationCurrentPositionPanel.js @@ -122,80 +122,43 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationCu /* put the labels with the records values */ - browserCanvasContext.beginPath(); - let y = 0; let increment = 0.024 * 2.5; y = y + increment; y = y + increment; - printLabel('Current Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); + printLabel('Current Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - - function printLabel(labelToPrint, x, y, opacity, fontSize) { - - let labelPoint; - if (fontSize === undefined) { fontSize = 10 }; - - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY; - - let label = '' + labelToPrint; - if (isNaN(label) === false) { - label = Number(label).toLocaleString(); - if ((label === "-0" || label === "0") && (labelToPrint !== 0) && (labelToPrint !== "0.00")) { - label = Number(labelToPrint).toFixed(6); - } - } - let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; - - labelPoint = { - x: x - xOffset, - y: y - }; - - labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); - labelPoint = thisObject.fitFunction(labelPoint) - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - - } - - browserCanvasContext.closePath(); - browserCanvasContext.fill(); - - } } diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index a6404a0b5..1844a1ad2 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -120,106 +120,71 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa /* put the labels with the records values */ - browserCanvasContext.beginPath(); - let y = 0; let increment = 0.024 / 2 * 2.5; y = y + increment; y = y + increment; - printLabel('Latest Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); + printLabel('Latest Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; y = y + increment; - printLabel('Partial Results', X_AXIS , frameTitleHeight + frameBodyHeight * y, '1', 14); + printLabel('Partial Results', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Profit / Loss', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.profit, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Trades', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.roundtrips, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Hits', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.hits, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Fails', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.fails, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Hit Ratio', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('ROI', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Periods', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.periods, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Days', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.days, X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); + printLabel(currentRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel('Anualized Rate of Return', X_AXIS , frameTitleHeight + frameBodyHeight * y, '0.60'); + printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS , frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - - function printLabel(labelToPrint, x, y, opacity, fontSize) { - - let labelPoint; - if (fontSize === undefined) { fontSize = 10 }; - - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY; - - let label = '' + labelToPrint; - if (isNaN(label) === false) { - label = Number(label).toLocaleString(); - if ((label === "-0" || label === "0") && (labelToPrint !== 0) && (labelToPrint !== "0.00")) { - label = Number(labelToPrint).toFixed(6); - } - } - let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; - - labelPoint = { - x: x - xOffset, - y: y - }; - - labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); - labelPoint = thisObject.fitFunction(labelPoint) - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - - } - - browserCanvasContext.closePath(); - browserCanvasContext.fill(); + printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); /* Parameters */ let params From 6493ddefcb054201b7b12d09022d0bde6ee1b24c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 15:45:37 +0100 Subject: [PATCH 130/157] panel splitted in 3 --- Project.njsproj | 6 + TradingSimulationCurrentPositionPanel.js | 48 +++--- TradingSimulationPanel.js | 94 +----------- TradingSimulationPartialResultsPanel.js | 177 +++++++++++++++++++++++ 4 files changed, 205 insertions(+), 120 deletions(-) create mode 100644 TradingSimulationPartialResultsPanel.js diff --git a/Project.njsproj b/Project.njsproj index 3551d717d..0595d3968 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -26,12 +26,18 @@ Code + + Code + Code Code + + Code + diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js index c75a6bb2e..ead5ed180 100644 --- a/TradingSimulationCurrentPositionPanel.js +++ b/TradingSimulationCurrentPositionPanel.js @@ -19,19 +19,20 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationCu container.initialize(); thisObject.container = container; - container.frame.containerName = "Simulation"; + container.frame.containerName = "Simulation Current Position Panel"; let currentRecord; let lastRecord; let upDownButton + const HEIGHT_FACTOR = 1.5 return thisObject; function initialize() { thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 1; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * HEIGHT_FACTOR; thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; @@ -123,7 +124,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationCu /* put the labels with the records values */ let y = 0; - let increment = 0.024 * 2.5; + let increment = 0.024 / HEIGHT_FACTOR * 2.5; y = y + increment; y = y + increment; @@ -159,32 +160,19 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationCu y = y + increment; printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + y = y + increment; + printLabel('Latest Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel((currentRecord.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + } } - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/TradingSimulationPanel.js b/TradingSimulationPanel.js index 1844a1ad2..7441e5bad 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationPanel.js @@ -17,19 +17,20 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa container.initialize(); thisObject.container = container; - container.frame.containerName = "Simulation"; + container.frame.containerName = "Simulation Panel"; let currentRecord; let lastRecord; let upDownButton + const HEIGHT_FACTOR = 1.5 return thisObject; function initialize() { thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.0; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * HEIGHT_FACTOR; thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; @@ -117,75 +118,15 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa const X_AXIS = thisObject.container.frame.width / 2; const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; - /* put the labels with the records values */ let y = 0; - let increment = 0.024 / 2 * 2.5; - - y = y + increment; - y = y + increment; - printLabel('Latest Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel((currentRecord.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + let increment = 0.024 / HEIGHT_FACTOR * 2.5; y = y + increment; y = y + increment; printLabel('Partial Results', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel(currentRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel(currentRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel(currentRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel(currentRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel(currentRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel(currentRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - - y = y + increment; - printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - y = y + increment; - printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); - /* Parameters */ let params let paramsArray = [] @@ -226,30 +167,3 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa canvas.cockpitSpace.assetBalances.setParamsArray(paramsArray) } } - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/TradingSimulationPartialResultsPanel.js b/TradingSimulationPartialResultsPanel.js new file mode 100644 index 000000000..c1b551d31 --- /dev/null +++ b/TradingSimulationPartialResultsPanel.js @@ -0,0 +1,177 @@ + +function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPartialResultsPanel() { + + let thisObject = { + fitFunction: undefined, + onRecordChange: onRecordChange, + container: undefined, + session: undefined, + isVisible: true, + draw: draw, + getContainer: getContainer, + initialize: initialize, + finalize: finalize + }; + + let container = newContainer(); + container.initialize(); + thisObject.container = container; + + container.frame.containerName = "Simulation Partial Results Panel"; + + let currentRecord; + let lastRecord; + let upDownButton + + const HEIGHT_FACTOR = 1.5 + + return thisObject; + + function initialize() { + + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 1; + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * HEIGHT_FACTOR; + + thisObject.container.frame.position.x = canvas.chartingSpace.viewport.visibleArea.topRight.x - thisObject.container.frame.width * 1; + thisObject.container.frame.position.y = canvas.chartingSpace.viewport.visibleArea.topRight.y; + + upDownButton = newUpDownButton() + upDownButton.parentContainer = thisObject.container + upDownButton.container.frame.parentFrame = thisObject.container.frame + upDownButton.fitFunction = thisObject.fitFunction + upDownButton.initialize() + + } + + function finalize() { + thisObject.session = undefined + + thisObject.container.finalize() + thisObject.container = undefined + thisObject.fitFunction = undefined + thisObject.onRecordChange = undefined + thisObject.isVisible = undefined + + currentRecord = undefined + lastRecord = undefined + upDownButton = undefined + } + + function getContainer(point) { + if (thisObject.isVisible !== true) { return } + let container; + + container = upDownButton.getContainer(point) + if (container !== undefined) { return container } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + + let checkPoint = { + x: point.x, + y: point.y + } + + checkPoint = thisObject.fitFunction(checkPoint) + + if (point.x === checkPoint.x && point.y === checkPoint.y) { + return thisObject.container; + } + } + } + + + function onRecordChange(records) { + + currentRecord = records.currentRecord; + lastRecord = records.lastRecord + + } + + + function draw() { + if (thisObject.isVisible !== true) { return } + thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); + + plotCurrentRecordInfo(); + + upDownButton.draw() + + /* Define panel name */ + if (thisObject.session !== undefined) { + const MAX_LABEL_LENGTH = 25 + if (thisObject.session.name.length > MAX_LABEL_LENGTH) { + container.frame.containerName = thisObject.session.name.substring(0, MAX_LABEL_LENGTH) + '...' + } else { + container.frame.containerName = thisObject.session.name + } + } + } + + + function plotCurrentRecordInfo() { + + if (currentRecord === undefined) { return; } + + const frameBodyHeight = thisObject.container.frame.getBodyHeight(); + const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; + + const X_AXIS = thisObject.container.frame.width / 2; + const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; + + + /* put the labels with the records values */ + + let y = 0; + let increment = 0.024 / HEIGHT_FACTOR * 2.5; + + y = y + increment; + y = y + increment; + printLabel('Partial Results', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel(currentRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel(currentRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel(currentRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel(currentRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel(currentRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel(currentRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + y = y + increment; + printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + y = y + increment; + printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + + } +} From 4040ad8074575011b50e7096ea9610e2b84d98a8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 15:56:34 +0100 Subject: [PATCH 131/157] renamed --- ...lationPanel.js => TradingSimulationAssetBalancesPanel.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename TradingSimulationPanel.js => TradingSimulationAssetBalancesPanel.js (94%) diff --git a/TradingSimulationPanel.js b/TradingSimulationAssetBalancesPanel.js similarity index 94% rename from TradingSimulationPanel.js rename to TradingSimulationAssetBalancesPanel.js index 7441e5bad..9b07adfdb 100644 --- a/TradingSimulationPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -1,5 +1,5 @@  -function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPanel() { +function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAssetBalancesPanel() { let thisObject = { fitFunction: undefined, @@ -17,7 +17,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa container.initialize(); thisObject.container = container; - container.frame.containerName = "Simulation Panel"; + container.frame.containerName = "Simulation Asset Balances Panel"; let currentRecord; let lastRecord; @@ -125,7 +125,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa y = y + increment; y = y + increment; - printLabel('Partial Results', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel('Asset Balances', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); /* Parameters */ let params From dc557189986a02592e9fde138077010f03d69272 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 16:30:44 +0100 Subject: [PATCH 132/157] Asset Balances on Panel --- TradingSimulationAssetBalancesPanel.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index 9b07adfdb..1ad34ee54 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -23,7 +23,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAs let lastRecord; let upDownButton - const HEIGHT_FACTOR = 1.5 + const HEIGHT_FACTOR = 1 return thisObject; @@ -41,6 +41,10 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAs upDownButton.fitFunction = thisObject.fitFunction upDownButton.initialize() + thisObject.assetBalances = newAssetalances() + thisObject.assetBalances.container.connectToParent(thisObject.container, true, true) + thisObject.assetBalances.initialize() + } function finalize() { @@ -55,6 +59,9 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAs currentRecord = undefined lastRecord = undefined upDownButton = undefined + + thisObject.assetBalances.finalize() + thisObject.assetBalances = undefined } function getContainer(point) { @@ -96,6 +103,8 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAs upDownButton.draw() + thisObject.assetBalances.draw() + /* Define panel name */ if (thisObject.session !== undefined) { const MAX_LABEL_LENGTH = 25 @@ -143,7 +152,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAs params.MAX_VALUE = currentRecord.maximunBalanceA params.ASSET_LABEL = 'Asset A' params.ASSET_NAME = currentRecord.baseAsset - params.LEFT_OFFSET = 100 + params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken params.BASE_ASSET = currentRecord.baseAsset params.DECIMALS = 4 @@ -157,13 +166,14 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAs params.MAX_VALUE = currentRecord.maximunBalanceB params.ASSET_LABEL = 'Asset B' params.ASSET_NAME = currentRecord.quotedAsset - params.LEFT_OFFSET = 220 + params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken params.BASE_ASSET = currentRecord.baseAsset params.DECIMALS = 2 paramsArray.push(params) - canvas.cockpitSpace.assetBalances.setParamsArray(paramsArray) + thisObject.assetBalances.setParamsArray(paramsArray) + } } From 37af5a63cfe795f71d8ed6fc9ab3245e9aa01c72 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 16:40:31 +0100 Subject: [PATCH 133/157] Final Touch --- TradingSimulationCurrentPositionPanel.js | 2 +- TradingSimulationPartialResultsPanel.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js index ead5ed180..bf6190672 100644 --- a/TradingSimulationCurrentPositionPanel.js +++ b/TradingSimulationCurrentPositionPanel.js @@ -25,7 +25,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationCu let lastRecord; let upDownButton - const HEIGHT_FACTOR = 1.5 + const HEIGHT_FACTOR = 1.25 return thisObject; diff --git a/TradingSimulationPartialResultsPanel.js b/TradingSimulationPartialResultsPanel.js index c1b551d31..d68ee4dd0 100644 --- a/TradingSimulationPartialResultsPanel.js +++ b/TradingSimulationPartialResultsPanel.js @@ -23,7 +23,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPa let lastRecord; let upDownButton - const HEIGHT_FACTOR = 1.5 + const HEIGHT_FACTOR = 1.25 return thisObject; From bb3e6f6836ed85a5a87c85616fd3104052995db3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 17:16:28 +0100 Subject: [PATCH 134/157] Minor improvements --- Strategies.js | 40 +++++++++++++++++--------- Trades.js | 4 +-- TradingSimulationAssetBalancesPanel.js | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Strategies.js b/Strategies.js index d6f84e9e4..68ff6566d 100644 --- a/Strategies.js +++ b/Strategies.js @@ -542,26 +542,40 @@ let imageToDraw = strategyImages[record.number]; - /* Draw the line that represents the duration of closed strategy */ + /* Draw the line that represents the duration of closed strategy */ - browserCanvasContext.beginPath(); + browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(recordPoint3.x + imageSize / 2, recordPoint3.y); - browserCanvasContext.lineTo(recordPoint4.x - imageSize / 2, recordPoint4.y); + browserCanvasContext.moveTo(recordPoint3.x + imageSize / 2, recordPoint3.y); + browserCanvasContext.lineTo(recordPoint4.x - imageSize / 2, recordPoint4.y); - browserCanvasContext.closePath(); + browserCanvasContext.closePath(); - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; - browserCanvasContext.lineWidth = 1 + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 1)'; + browserCanvasContext.lineWidth = 1 - if (record.status === 1) { - browserCanvasContext.setLineDash([0, 0]) - } else { - browserCanvasContext.setLineDash([2, 4]) - } - browserCanvasContext.stroke() + if (record.status === 1) { + browserCanvasContext.setLineDash([0, 0]) + } else { + browserCanvasContext.setLineDash([2, 4]) + } + browserCanvasContext.stroke() + /* Draw the Area */ + /* + browserCanvasContext.beginPath(); + browserCanvasContext.moveTo(recordPoint1.x, recordPoint2.y); + browserCanvasContext.lineTo(recordPoint3.x, recordPoint3.y); + browserCanvasContext.lineTo(recordPoint4.x, recordPoint4.y); + browserCanvasContext.lineTo(recordPoint2.x, recordPoint2.y); + + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.LIGHT_GREY + ', ' + 0.5 + ')'; + browserCanvasContext.fill(); + */ + /* Draw the Sticks */ drawStick(recordPoint1, recordPoint3); drawStick(recordPoint2, recordPoint4); diff --git a/Trades.js b/Trades.js index 0973949d8..9c5e16f88 100644 --- a/Trades.js +++ b/Trades.js @@ -522,11 +522,11 @@ if (record.status === 1) { switch (record.exitType) { case 1: { - line1 = 'Exit: STOP'; + line1 = 'Stop Loss'; break; } case 2: { - line1 = 'Exit: TP'; + line1 = 'Take Profit'; break; } } diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index 1ad34ee54..3ca0292ff 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -23,7 +23,7 @@ function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAs let lastRecord; let upDownButton - const HEIGHT_FACTOR = 1 + const HEIGHT_FACTOR = 1.25 return thisObject; From 308f649e5863efe4d2697201f587622cff9d649e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 18 Mar 2020 11:43:27 +0100 Subject: [PATCH 135/157] Update TradingSimulation.js --- TradingSimulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 9f62fd06d..6222e1fae 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -689,7 +689,7 @@ browserCanvasContext.save(); browserCanvasContext.translate(recordPoint3.x + labelOffset.x, recordPoint3.y + labelOffset.y); browserCanvasContext.rotate(-Math.PI / 2); - printLabel(recordLabel, 0, 0, '1', 8); + printLabel(recordLabel, 0, 0, '1', 8, undefined, undefined, undefined, undefined, true); browserCanvasContext.restore(); } From 2f41834b2d00351adac7bef8f51f6b0fe8c9dcbf Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Mar 2020 11:59:12 +0100 Subject: [PATCH 136/157] refactoring --- Conditions.js | 2 +- SimulationExecution.js | 2 +- SimulationExecutionPanel.js | 2 +- Strategies.js | 2 +- Trades.js | 2 +- TradingSimulation.js | 2 +- TradingSimulationCurrentPositionPanel.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Conditions.js b/Conditions.js index a4d62f3c9..1f51a541e 100644 --- a/Conditions.js +++ b/Conditions.js @@ -1,4 +1,4 @@ -function newMastersPlottersTradingSimulationConditions() { +function newTrading-EnginesPlottersTradingSimulationConditions() { const MODULE_NAME = "Conditions Plotter"; const INFO_LOG = false; diff --git a/SimulationExecution.js b/SimulationExecution.js index f1a7eb78f..19fece640 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -1,4 +1,4 @@ -function newMastersPlottersTradingSimulationSimulationExecution() { +function newTrading-EnginesPlottersTradingSimulationSimulationExecution() { const MODULE_NAME = "Simulation Execution Plotter"; const INTENSIVE_LOG = false; diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index 37a002b81..bf6dc79ce 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -1,5 +1,5 @@  -function newMastersPlottersTradingSimulationSimulationExecutionSimulationExecutionPanel() { +function newTrading-EnginesPlottersTradingSimulationSimulationExecutionSimulationExecutionPanel() { let thisObject = { diff --git a/Strategies.js b/Strategies.js index 68ff6566d..7c24da760 100644 --- a/Strategies.js +++ b/Strategies.js @@ -1,4 +1,4 @@ -function newMastersPlottersTradingSimulationStrategies() { +function newTrading-EnginesPlottersTradingSimulationStrategies() { const MODULE_NAME = "Strategies Plotter"; const INFO_LOG = false; diff --git a/Trades.js b/Trades.js index 9c5e16f88..324b1a9a2 100644 --- a/Trades.js +++ b/Trades.js @@ -1,4 +1,4 @@ -function newMastersPlottersTradingSimulationTrades() { +function newTrading-EnginesPlottersTradingSimulationTrades() { const MODULE_NAME = "Trades Plotter"; const INFO_LOG = false; diff --git a/TradingSimulation.js b/TradingSimulation.js index 6222e1fae..ce55d7f87 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -1,4 +1,4 @@ -function newMastersPlottersTradingSimulationTradingSimulation() { +function newTrading-EnginesPlottersTradingSimulationTradingSimulation() { const MODULE_NAME = "Simulation Plotter"; const ERROR_LOG = true; diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js index bf6190672..c75e29da5 100644 --- a/TradingSimulationCurrentPositionPanel.js +++ b/TradingSimulationCurrentPositionPanel.js @@ -1,7 +1,7 @@  -function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationCurrentPositionPanel() { +function newTrading-EnginesPlottersTradingSimulationTradingSimulationTradingSimulationCurrentPositionPanel() { let thisObject = { fitFunction: undefined, From ebffe758df42888b9f9a6c7a57861dec81db3fdf Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Mar 2020 12:06:04 +0100 Subject: [PATCH 137/157] no dash --- Conditions.js | 2 +- SimulationExecution.js | 2 +- SimulationExecutionPanel.js | 2 +- Strategies.js | 2 +- Trades.js | 2 +- TradingSimulation.js | 2 +- TradingSimulationCurrentPositionPanel.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Conditions.js b/Conditions.js index 1f51a541e..3d673f08a 100644 --- a/Conditions.js +++ b/Conditions.js @@ -1,4 +1,4 @@ -function newTrading-EnginesPlottersTradingSimulationConditions() { +function newTradingEnginesPlottersTradingSimulationConditions() { const MODULE_NAME = "Conditions Plotter"; const INFO_LOG = false; diff --git a/SimulationExecution.js b/SimulationExecution.js index 19fece640..9db58a633 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -1,4 +1,4 @@ -function newTrading-EnginesPlottersTradingSimulationSimulationExecution() { +function newTradingEnginesPlottersTradingSimulationSimulationExecution() { const MODULE_NAME = "Simulation Execution Plotter"; const INTENSIVE_LOG = false; diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index bf6dc79ce..48410e698 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -1,5 +1,5 @@  -function newTrading-EnginesPlottersTradingSimulationSimulationExecutionSimulationExecutionPanel() { +function newTradingEnginesPlottersTradingSimulationSimulationExecutionSimulationExecutionPanel() { let thisObject = { diff --git a/Strategies.js b/Strategies.js index 7c24da760..3ca511d39 100644 --- a/Strategies.js +++ b/Strategies.js @@ -1,4 +1,4 @@ -function newTrading-EnginesPlottersTradingSimulationStrategies() { +function newTradingEnginesPlottersTradingSimulationStrategies() { const MODULE_NAME = "Strategies Plotter"; const INFO_LOG = false; diff --git a/Trades.js b/Trades.js index 324b1a9a2..24e64c7cd 100644 --- a/Trades.js +++ b/Trades.js @@ -1,4 +1,4 @@ -function newTrading-EnginesPlottersTradingSimulationTrades() { +function newTradingEnginesPlottersTradingSimulationTrades() { const MODULE_NAME = "Trades Plotter"; const INFO_LOG = false; diff --git a/TradingSimulation.js b/TradingSimulation.js index ce55d7f87..624c489c2 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -1,4 +1,4 @@ -function newTrading-EnginesPlottersTradingSimulationTradingSimulation() { +function newTradingEnginesPlottersTradingSimulationTradingSimulation() { const MODULE_NAME = "Simulation Plotter"; const ERROR_LOG = true; diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js index c75e29da5..6fc1ab6f5 100644 --- a/TradingSimulationCurrentPositionPanel.js +++ b/TradingSimulationCurrentPositionPanel.js @@ -1,7 +1,7 @@  -function newTrading-EnginesPlottersTradingSimulationTradingSimulationTradingSimulationCurrentPositionPanel() { +function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimulationCurrentPositionPanel() { let thisObject = { fitFunction: undefined, From 789991eafd106922a55de5434e40304695b1dc57 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Mar 2020 12:20:11 +0100 Subject: [PATCH 138/157] bug fixed --- Project.njsproj | 8 ++++---- TradingSimulationAssetBalancesPanel.js | 2 +- TradingSimulationPartialResultsPanel.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Project.njsproj b/Project.njsproj index 0595d3968..40731b136 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -20,26 +20,26 @@ Code + + Code Code - - Code - Code Code + Code - + diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index 3ca0292ff..b73d0be65 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -1,5 +1,5 @@  -function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationAssetBalancesPanel() { +function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimulationAssetBalancesPanel() { let thisObject = { fitFunction: undefined, diff --git a/TradingSimulationPartialResultsPanel.js b/TradingSimulationPartialResultsPanel.js index d68ee4dd0..bd07abf7d 100644 --- a/TradingSimulationPartialResultsPanel.js +++ b/TradingSimulationPartialResultsPanel.js @@ -1,5 +1,5 @@  -function newMastersPlottersTradingSimulationTradingSimulationTradingSimulationPartialResultsPanel() { +function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimulationPartialResultsPanel() { let thisObject = { fitFunction: undefined, From a102595eaf1349430232fe390150394cba7d55a2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Mar 2020 13:51:15 +0100 Subject: [PATCH 139/157] Bug fixed --- Conditions.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Conditions.js b/Conditions.js index 3d673f08a..9258a7b1e 100644 --- a/Conditions.js +++ b/Conditions.js @@ -52,6 +52,7 @@ let noDefinitionOnFocusErrorDisplayed = false + let onMouseOverEventSuscriptionId let zoomChangedEventSubscriptionId let offsetChangedEventSubscriptionId let dragFinishedEventSubscriptionId @@ -70,6 +71,7 @@ /* Stop listening to the necesary events. */ + thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId) canvas.chartingSpace.viewport.eventHandler.stopListening(zoomChangedEventSubscriptionId); canvas.chartingSpace.viewport.eventHandler.stopListening(offsetChangedEventSubscriptionId); canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); @@ -128,6 +130,7 @@ dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent("Files Updated", onMarketFilesUpdated); dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent("Files Updated", onDailyFilesUpdated); + onMouseOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) /* Get ready for plotting. */ @@ -524,9 +527,9 @@ for (let i = 0; i < canvas.designSpace.workspace.workspaceNode.rootNodes.length; i++) { let rootNode = canvas.designSpace.workspace.workspaceNode.rootNodes[i] - if (rootNode.type === 'Definition') { - if (rootNode.tradingSystem.id === fileTradingSystem.id) { - designerTradingSystem = rootNode.tradingSystem + if (rootNode.type === 'Trading System') { + if (rootNode.id === fileTradingSystem.id) { + designerTradingSystem = rootNode } } } From e79c84714d8723d7c3ffe0c43583f2bdd9c010b4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Mar 2020 14:01:59 +0100 Subject: [PATCH 140/157] Update TradingSimulationAssetBalancesPanel.js --- TradingSimulationAssetBalancesPanel.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index b73d0be65..3cc23fa0e 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -103,8 +103,6 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul upDownButton.draw() - thisObject.assetBalances.draw() - /* Define panel name */ if (thisObject.session !== undefined) { const MAX_LABEL_LENGTH = 25 @@ -145,6 +143,17 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul positionTaken = true } + let testPoint = { + x: 0, + y: thisObject.container.frame.height + } + + testPoint = thisObject.container.frame.frameThisPoint(testPoint) + let fitPoint = thisObject.fitFunction(testPoint) + if (fitPoint.y !== testPoint.y) { + return + } + params = {} params.VALUE = currentRecord.balanceA; params.INIT_VALUE = currentRecord.initialBalanceA @@ -174,6 +183,6 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul paramsArray.push(params) thisObject.assetBalances.setParamsArray(paramsArray) - + thisObject.assetBalances.draw() } } From beeba4bfbfedae83663568943af79e2a9fe85294 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 21 Mar 2020 18:02:08 +0100 Subject: [PATCH 141/157] bug fixes --- Conditions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Conditions.js b/Conditions.js index 9258a7b1e..f65c5d9e6 100644 --- a/Conditions.js +++ b/Conditions.js @@ -935,9 +935,9 @@ if (condition !== undefined) { condition.payload.uiObject.setErrorMessage(situation.conditions[m].error) - if (situation.conditions[m].code !== undefined) { - if (condition.code !== undefined) { - condition.code.payload.uiObject.setErrorMessage(situation.conditions[m].code.error) + if (situation.conditions[m].javascriptCode !== undefined) { + if (condition.javascriptCode !== undefined) { + condition.javascriptCode.payload.uiObject.setErrorMessage(situation.conditions[m].javascriptCode.error) } } From 34f6abf2db01f7d611168358d1ad3a440f45daec Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Mar 2020 17:50:09 +0100 Subject: [PATCH 142/157] Situation Names --- Strategies.js | 8 ++++++++ Trades.js | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Strategies.js b/Strategies.js index 3ca511d39..41b911914 100644 --- a/Strategies.js +++ b/Strategies.js @@ -383,6 +383,7 @@ record.number = dailyFile[i][3]; record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; + record.triggerOnSituation = dailyFile[i][6]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -454,6 +455,7 @@ record.number = marketFile[i][3]; record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; + record.triggerOnSituation = marketFile[i][6]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -575,6 +577,12 @@ browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.LIGHT_GREY + ', ' + 0.5 + ')'; browserCanvasContext.fill(); */ + + /* Situation Name */ + let digit = record.begin.toFixed(0).substring(7,8) + let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) + printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY , '1', 9); + /* Draw the Sticks */ drawStick(recordPoint1, recordPoint3); diff --git a/Trades.js b/Trades.js index 24e64c7cd..2d38c3233 100644 --- a/Trades.js +++ b/Trades.js @@ -370,6 +370,7 @@ record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; record.exitType = dailyFile[i][6]; + record.takePositionSituation = dailyFile[i][7]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -435,6 +436,7 @@ record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; record.exitType = marketFile[i][6]; + record.takePositionSituation = marketFile[i][7]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && @@ -516,6 +518,7 @@ recordPoint2 = thisObject.fitFunction(recordPoint2); recordPoint3 = thisObject.fitFunction(recordPoint3); + let line0 = record.takePositionSituation let line1 = ''; let line2 = ''; @@ -595,7 +598,7 @@ // we do not write any text } else { - + printLabel(line0, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y - 15, '1', 12); printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y, '1', 12); printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, point.y + 15, '1', 12); From aceb486320b542f6b50da73080b59c18d30d2b5a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Mar 2020 19:59:06 +0100 Subject: [PATCH 143/157] Update Strategies.js --- Strategies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Strategies.js b/Strategies.js index 41b911914..668496f87 100644 --- a/Strategies.js +++ b/Strategies.js @@ -581,7 +581,7 @@ /* Situation Name */ let digit = record.begin.toFixed(0).substring(7,8) let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) - printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY , '1', 9); + printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY , '1', 12); /* Draw the Sticks */ From 258a45285dd26bb773a70daf6a00848f1d38f17c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Mar 2020 17:42:09 +0100 Subject: [PATCH 144/157] no default situation name --- Strategies.js | 6 ++++-- Trades.js | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Strategies.js b/Strategies.js index 668496f87..a42d0b823 100644 --- a/Strategies.js +++ b/Strategies.js @@ -580,8 +580,10 @@ /* Situation Name */ let digit = record.begin.toFixed(0).substring(7,8) - let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) - printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY , '1', 12); + let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) + if (record.triggerOnSituation !== "My Situation") { + printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); + } /* Draw the Sticks */ diff --git a/Trades.js b/Trades.js index 2d38c3233..1d99ee700 100644 --- a/Trades.js +++ b/Trades.js @@ -522,6 +522,10 @@ let line1 = ''; let line2 = ''; + if (line0 === 'My Situation') { + line0 = '' + } + if (record.status === 1) { switch (record.exitType) { case 1: { From 63755feae23d4c88a38f782a4f46dd0a6db74faa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Mar 2020 17:51:27 +0100 Subject: [PATCH 145/157] improvement not showing text --- Strategies.js | 6 ++++-- Trades.js | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Strategies.js b/Strategies.js index a42d0b823..c522c7a82 100644 --- a/Strategies.js +++ b/Strategies.js @@ -581,8 +581,10 @@ /* Situation Name */ let digit = record.begin.toFixed(0).substring(7,8) let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) - if (record.triggerOnSituation !== "My Situation") { - printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); + if (canvas.chartingSpace.viewport.zoomLevel >= ZOOM_OUT_THRESHOLD_FOR_HIDDING_CHARTS_LABELS) { + if (record.triggerOnSituation !== "My Situation") { + printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); + } } /* Draw the Sticks */ diff --git a/Trades.js b/Trades.js index 1d99ee700..f90c577bc 100644 --- a/Trades.js +++ b/Trades.js @@ -602,11 +602,11 @@ // we do not write any text } else { - printLabel(line0, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y - 15, '1', 12); - printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y, '1', 12); - printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, point.y + 15, '1', 12); - - + if (canvas.chartingSpace.viewport.zoomLevel >= ZOOM_OUT_THRESHOLD_FOR_HIDDING_CHARTS_LABELS) { + printLabel(line0, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y - 15, '1', 12); + printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y, '1', 12); + printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, point.y + 15, '1', 12); + } } } From 1273c292798e594c4976cc035003af351570f6bc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 1 Apr 2020 09:37:01 +0200 Subject: [PATCH 146/157] New Situation --- Strategies.js | 2 +- Trades.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Strategies.js b/Strategies.js index c522c7a82..5f49a356a 100644 --- a/Strategies.js +++ b/Strategies.js @@ -582,7 +582,7 @@ let digit = record.begin.toFixed(0).substring(7,8) let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) if (canvas.chartingSpace.viewport.zoomLevel >= ZOOM_OUT_THRESHOLD_FOR_HIDDING_CHARTS_LABELS) { - if (record.triggerOnSituation !== "My Situation") { + if (record.triggerOnSituation !== "New Situation") { printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); } } diff --git a/Trades.js b/Trades.js index f90c577bc..9da7b37b6 100644 --- a/Trades.js +++ b/Trades.js @@ -522,7 +522,7 @@ let line1 = ''; let line2 = ''; - if (line0 === 'My Situation') { + if (line0 === 'New Situation') { line0 = '' } From 3f8cf530ec5325a9f7743596e408d2a3b5ae0bae Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 20 Apr 2020 16:58:20 +0200 Subject: [PATCH 147/157] Update Conditions.js --- Conditions.js | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/Conditions.js b/Conditions.js index f65c5d9e6..a9eb8a1c8 100644 --- a/Conditions.js +++ b/Conditions.js @@ -707,6 +707,29 @@ } } } + + for (let n = 0; n < phase.moveToPhaseEvents.length; n++) { + let moveToPhaseEvent = phase.moveToPhaseEvents[n]; + if (moveToPhaseEvent !== undefined) { + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].moveToPhaseEvents[n].payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].moveToPhaseEvents[n].error) + + for (let k = 0; k < moveToPhaseEvent.situations.length; k++) { + + let situation = moveToPhaseEvent.situations[k]; + + processSituation(situation, designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].moveToPhaseEvents[n].situations[k]); + } + + for (let k = 0; k < moveToPhaseEvent.announcements.length; k++) { + + let announcement = moveToPhaseEvent.announcements[k]; + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].moveToPhaseEvents[n].announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].moveToPhaseEvents[n].announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } + } + } } } @@ -769,6 +792,29 @@ } } } + + for (let n = 0; n < phase.moveToPhaseEvents.length; n++) { + let moveToPhaseEvent = phase.moveToPhaseEvents[n]; + if (moveToPhaseEvent !== undefined) { + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].moveToPhaseEvents[n].payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].moveToPhaseEvent[n].error) + + for (let k = 0; k < moveToPhaseEvent.situations.length; k++) { + + let situation = moveToPhaseEvent.situations[k]; + + processSituation(situation, designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].moveToPhaseEvents[n].situations[k]); + } + + for (let k = 0; k < moveToPhaseEvent.announcements.length; k++) { + + let announcement = moveToPhaseEvent.announcements[k]; + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].moveToPhaseEvents[n].announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].moveToPhaseEvents[n].announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } + } + } } } } @@ -843,6 +889,29 @@ } } } + + for (let n = 0; n < phase.moveToPhaseEvents.length; n++) { + let moveToPhaseEvent = phase.moveToPhaseEvents[n]; + if (moveToPhaseEvent !== undefined) { + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].moveToPhaseEvent[n].payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].moveToPhaseEvent[n].error) + + for (let k = 0; k < moveToPhaseEvent.situations.length; k++) { + + let situation = moveToPhaseEvent.situations[k]; + + processSituation(situation, designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].moveToPhaseEvent[n].situations[k]); + } + + for (let k = 0; k < moveToPhaseEvent.announcements.length; k++) { + + let announcement = moveToPhaseEvent.announcements[k]; + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].moveToPhaseEvent[n].announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].moveToPhaseEvent[n].announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } + } + } } } @@ -905,6 +974,28 @@ } } } + for (let n = 0; n < phase.moveToPhaseEvents.length; n++) { + let moveToPhaseEvent = phase.moveToPhaseEvents[n]; + if (moveToPhaseEvent !== undefined) { + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].moveToPhaseEvents[n].payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].moveToPhaseEvents[n].error) + + for (let k = 0; k < moveToPhaseEvent.situations.length; k++) { + + let situation = moveToPhaseEvent.situations[k]; + + processSituation(situation, designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].moveToPhaseEvents[n].situations[k]); + } + + for (let k = 0; k < moveToPhaseEvent.announcements.length; k++) { + + let announcement = moveToPhaseEvent.announcements[k]; + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].moveToPhaseEvents[n].announcements[k].payload.uiObject.setErrorMessage(announcement.error) + if (announcement.formula !== undefined) { + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].moveToPhaseEvents[n].announcements[k].formula.payload.uiObject.setErrorMessage(announcement.formula.error) + } + } + } + } } } } From 6dc9f2abc800e44b554040f6efc593dcd6cd6065 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 2 May 2020 10:16:34 +0200 Subject: [PATCH 148/157] bug fixed --- TradingSimulation.js | 12 ++-- TradingSimulationAssetBalancesPanel.js | 79 ++++++++++++++++++-------- 2 files changed, 63 insertions(+), 28 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 624c489c2..f9b3b5787 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -385,8 +385,10 @@ record.maximunBalanceB = dailyFile[i][32]; record.baseAsset = dailyFile[i][33]; record.quotedAsset = dailyFile[i][34]; - record.positionPeriods = dailyFile[i][35]; - record.positionDays = dailyFile[i][36]; + record.marketBaseAsset = dailyFile[i][35]; + record.marketQuotedAsset = dailyFile[i][36]; + record.positionPeriods = dailyFile[i][37]; + record.positionDays = dailyFile[i][38]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -477,8 +479,10 @@ record.maximunBalanceB = marketFile[i][32]; record.baseAsset = marketFile[i][33]; record.quotedAsset = marketFile[i][34]; - record.positionPeriods = marketFile[i][35]; - record.positionDays = marketFile[i][36]; + record.marketBaseAsset = marketFile[i][35]; + record.marketQuotedAsset = marketFile[i][36]; + record.positionPeriods = marketFile[i][37]; + record.positionDays = marketFile[i][38]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index 3cc23fa0e..7272577da 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -154,33 +154,64 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul return } - params = {} - params.VALUE = currentRecord.balanceA; - params.INIT_VALUE = currentRecord.initialBalanceA - params.MIN_VALUE = currentRecord.minimunBalanceA - params.MAX_VALUE = currentRecord.maximunBalanceA - params.ASSET_LABEL = 'Asset A' - params.ASSET_NAME = currentRecord.baseAsset - params.LEFT_OFFSET = X_AXIS - params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset - params.DECIMALS = 4 + if (currentRecord.baseAsset === currentRecord.marketBaseAsset) { + params = {} + params.VALUE = currentRecord.balanceA; + params.INIT_VALUE = currentRecord.initialBalanceA + params.MIN_VALUE = currentRecord.minimunBalanceA + params.MAX_VALUE = currentRecord.maximunBalanceA + params.ASSET_LABEL = 'Base' + params.ASSET_NAME = currentRecord.baseAsset + params.LEFT_OFFSET = X_AXIS + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 4 - paramsArray.push(params) + paramsArray.push(params) - params = {} - params.VALUE = currentRecord.balanceB; - params.MIN_VALUE = currentRecord.minimunBalanceB - params.INIT_VALUE = currentRecord.initialBalanceB - params.MAX_VALUE = currentRecord.maximunBalanceB - params.ASSET_LABEL = 'Asset B' - params.ASSET_NAME = currentRecord.quotedAsset - params.LEFT_OFFSET = X_AXIS - params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset - params.DECIMALS = 2 + params = {} + params.VALUE = currentRecord.balanceB; + params.MIN_VALUE = currentRecord.minimunBalanceB + params.INIT_VALUE = currentRecord.initialBalanceB + params.MAX_VALUE = currentRecord.maximunBalanceB + params.ASSET_LABEL = 'Quoted' + params.ASSET_NAME = currentRecord.quotedAsset + params.LEFT_OFFSET = X_AXIS + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 2 + + paramsArray.push(params) + } else { + params = {} + params.VALUE = currentRecord.balanceB; + params.INIT_VALUE = currentRecord.initialBalanceB + params.MIN_VALUE = currentRecord.minimunBalanceB + params.MAX_VALUE = currentRecord.maximunBalanceB + params.ASSET_LABEL = 'Base' + params.ASSET_NAME = currentRecord.baseAsset + params.LEFT_OFFSET = X_AXIS + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 4 + + paramsArray.push(params) + + params = {} + params.VALUE = currentRecord.balanceA; + params.MIN_VALUE = currentRecord.minimunBalanceA + params.INIT_VALUE = currentRecord.initialBalanceA + params.MAX_VALUE = currentRecord.maximunBalanceA + params.ASSET_LABEL = 'Quoted' + params.ASSET_NAME = currentRecord.quotedAsset + params.LEFT_OFFSET = X_AXIS + params.POSITION_TAKEN = positionTaken + params.BASE_ASSET = currentRecord.baseAsset + params.DECIMALS = 2 + + paramsArray.push(params) + } - paramsArray.push(params) thisObject.assetBalances.setParamsArray(paramsArray) thisObject.assetBalances.draw() From cbf3c3fd4e44ea31fa990d9ea0ceb0668b884a6f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 18 May 2020 20:43:56 +0200 Subject: [PATCH 149/157] Strategy Name at Plotter --- Strategies.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Strategies.js b/Strategies.js index 5f49a356a..2e82c2267 100644 --- a/Strategies.js +++ b/Strategies.js @@ -384,6 +384,7 @@ record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; record.triggerOnSituation = dailyFile[i][6]; + record.name = dailyFile[i][7]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -456,6 +457,7 @@ record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; record.triggerOnSituation = marketFile[i][6]; + record.name = marketFile[i][7]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -581,7 +583,11 @@ /* Situation Name */ let digit = record.begin.toFixed(0).substring(7,8) let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) + if (canvas.chartingSpace.viewport.zoomLevel >= ZOOM_OUT_THRESHOLD_FOR_HIDDING_CHARTS_LABELS) { + if (record.name !== "New Strategy") { + printLabel(record.name, recordPoint1.x + 5, positionY - 15, '1', 12); + } if (record.triggerOnSituation !== "New Situation") { printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); } From 00efa026b81a4aaed1ec92eba5774cb28203b38b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 19 May 2020 15:03:00 +0200 Subject: [PATCH 150/157] Removing some code debt --- Conditions.js | 55 ++-- FinalResults.js | 348 ----------------------- FinalResultsPanel.js | 360 ------------------------ Project.njsproj | 2 - Project.njsproj.user | 6 + TradingSimulation.js | 140 +++++---- TradingSimulationPartialResultsPanel.js | 4 +- 7 files changed, 101 insertions(+), 814 deletions(-) delete mode 100644 FinalResults.js delete mode 100644 FinalResultsPanel.js create mode 100644 Project.njsproj.user diff --git a/Conditions.js b/Conditions.js index a9eb8a1c8..8115c6e9e 100644 --- a/Conditions.js +++ b/Conditions.js @@ -374,13 +374,12 @@ record.begin = dailyFile[1][i][0]; record.end = dailyFile[1][i][1]; - record.strategyNumber = dailyFile[1][i][2]; - record.strategyPhase = dailyFile[1][i][3]; - record.stopLossPhase = dailyFile[1][i][4]; - record.takeProfitPhase = dailyFile[1][i][5]; - record.conditions = dailyFile[1][i][6]; - record.formulaErrors = dailyFile[1][i][7]; - record.formulaValues = dailyFile[1][i][8]; + record.strategyIndex = dailyFile[1][i][2]; + record.stopLossPhase = dailyFile[1][i][3]; + record.takeProfitPhase = dailyFile[1][i][4]; + record.conditions = dailyFile[1][i][5]; + record.formulaErrors = dailyFile[1][i][6]; + record.formulaValues = dailyFile[1][i][7]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -446,13 +445,12 @@ record.begin = marketFile[1][i][0]; record.end = marketFile[1][i][1]; - record.strategyNumber = marketFile[1][i][2]; - record.strategyPhase = marketFile[1][i][3]; - record.stopLossPhase = marketFile[1][i][4]; - record.takeProfitPhase = marketFile[1][i][5]; - record.conditions = marketFile[1][i][6]; - record.formulaErrors = marketFile[1][i][7]; - record.formulaValues = marketFile[1][i][8]; + record.strategyIndex = marketFile[1][i][2]; + record.stopLossPhase = marketFile[1][i][3]; + record.takeProfitPhase = marketFile[1][i][4]; + record.conditions = marketFile[1][i][5]; + record.formulaErrors = marketFile[1][i][6]; + record.formulaValues = marketFile[1][i][7]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && @@ -496,8 +494,7 @@ let currentRecord = { conditionsNames: headers, - strategyNumber: conditionRecord.strategyNumber, - strategyPhase: conditionRecord.strategyPhase, + strategyIndex: conditionRecord.strategyIndex, stopLossPhase: conditionRecord.stopLossPhase, takeProfitPhase: conditionRecord.takeProfitPhase, conditionsValues: conditionRecord.conditions, @@ -568,7 +565,7 @@ let strategy = fileTradingSystem.strategies[j]; designerTradingSystem.strategies[j].payload.uiObject.setErrorMessage(strategy.error) - if (currentRecord.strategyNumber === j) { + if (currentRecord.strategyIndex === j) { designerTradingSystem.strategies[j].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].payload.uiObject.isExecuting = false @@ -653,7 +650,7 @@ for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase === p) { + if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -666,13 +663,13 @@ designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase === p) { + if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase === p) { + if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -738,7 +735,7 @@ for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase === p) { + if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -751,13 +748,13 @@ designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase === p) { + if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase === p) { + if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -836,7 +833,7 @@ for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { + if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -849,12 +846,12 @@ designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { + if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyNumber === j && currentRecord.stopLossPhase - 1 === p) { + if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -920,7 +917,7 @@ for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { + if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -933,13 +930,13 @@ designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { + if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyNumber === j && currentRecord.takeProfitPhase - 1 === p) { + if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ diff --git a/FinalResults.js b/FinalResults.js deleted file mode 100644 index dcc9ce8d2..000000000 --- a/FinalResults.js +++ /dev/null @@ -1,348 +0,0 @@ -function newAAMastersPlottersTradingSimulationFinalResults() { - - const MODULE_NAME = "Final Results Plotter"; - const ERROR_LOG = true; - const INTENSIVE_LOG = false; - const logger = newWebDebugLog(); - logger.fileName = MODULE_NAME; - - let thisObject = { - - // Main functions and properties. - - initialize: initialize, - finalize: finalize, - container: undefined, - getContainer: getContainer, - setTimePeriod: setTimePeriod, - setDatetime: setDatetime, - draw: draw, - recalculateScale: recalculateScale, - currentRecord: undefined - }; - - /* this is part of the module template */ - - let container = newContainer(); // Do not touch this 3 lines, they are just needed. - container.initialize(); - thisObject.container = container; - - let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. - - let timePeriod; // This will hold the current Time Period the user is at. - let datetime; // This will hold the current Datetime the user is at. - - let dataFile; // This is the current Market File being plotted. - let fileCursor; // This is the current File Cursor being used to retrieve Daily Files. - - let singleFile; // This object will provide the different Market Files at different Time Periods. - - /* these are module specific variables: */ - - let records = []; // Here we keep the records to be ploted every time the Draw() function is called by the AAWebPlatform. - - let imageStopLossPhase; - let imageTakeProfitPhase; - let imageRecord; - - let zoomChangedEventSubscriptionId - let offsetChangedEventSubscriptionId - let filesUpdatedEventSubscriptionId - let dragFinishedEventSubscriptionId - let dimmensionsChangedEventSubscriptionId - - return thisObject; - - function finalize() { - try { - - /* Stop listening to the necesary events. */ - - viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId); - viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId); - singleFile.eventHandler.stopListening(filesUpdatedEventSubscriptionId); - canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId); - thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) - - /* icons */ - - imageStopLossPhase = undefined; - imageTakeProfitPhase = undefined; - imageRecord = undefined; - - /* Destroy References */ - - singleFile = undefined; - - datetime = undefined; - timePeriod = undefined; - - dataFile = undefined; - fileCursor = undefined; - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } - } - } - - function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { - - try { - - /* Store the information received. */ - - singleFile = pStorage.singleFile; - - datetime = pDatetime; - timePeriod = pTimePeriod; - - dataFile = singleFile.getFile(timePeriod); - - /* Listen to the necesary events. */ - - zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - filesUpdatedEventSubscriptionId = singleFile.eventHandler.listenToEvent("Files Updated", onFilesUpdated); - dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - - /* Get ready for plotting. */ - - recalculate(); - - /* Ready for when dimmension changes. */ - - dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { - recalculate(); - }) - - callBackFunction(); - - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err.stack); } - } - } - - function getContainer(point) { - let container; - /* First we check if this point is inside this space. */ - if (this.container.frame.isThisPointHere(point) === true) { - return this.container; - } else { - /* This point does not belong to this space. */ - return undefined; - } - } - - function onFilesUpdated() { - try { - dataFile = singleFile.getFile(timePeriod); - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } - } - } - - function setTimePeriod(pTimePeriod) { - try { - if (timePeriod !== pTimePeriod) { - timePeriod = pTimePeriod; - dataFile = singleFile.getFile(timePeriod); - recalculate(); - } - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } - } - } - - function setDatetime(pDatetime) { - datetime = pDatetime; - } - - function draw() { - try { - // Nothing to draw for now - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err.stack); } - } - } - - function recalculate() { - - try { - - records = [] - - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - - recalculateUsingMarketFiles(); - - } else { - - recalculateUsingDailyFiles(); - - } - - thisObject.container.eventHandler.raiseEvent("Records Changed", records); - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } - } - } - - function recalculate() { - - try { - - if (dataFile === undefined) { return; } // Initialization not complete yet. - - records = []; - - for (let i = 0; i < dataFile.length; i++) { - - let record = {}; - - record.begin = dataFile[i][0]; - record.end = dataFile[i][1]; - record.type = dataFile[i][2]; - record.rate = dataFile[i][3]; - record.amount = dataFile[i][4]; - record.balanceA = dataFile[i][5]; - record.balanceB = dataFile[i][6]; - record.profit = dataFile[i][7]; - record.lastTradeProfitLoss = dataFile[i][8]; - record.stopLoss = dataFile[i][9]; - record.roundtrips = dataFile[i][10]; - record.hits = dataFile[i][11]; - record.fails = dataFile[i][12]; - record.hitRatio = dataFile[i][13]; - record.ROI = dataFile[i][14]; - record.periods = dataFile[i][15]; - record.days = dataFile[i][16]; - record.anualizedRateOfReturn = dataFile[i][17]; - record.sellRate = dataFile[i][18]; - record.lastTradeROI = dataFile[i][19]; - record.strategy = dataFile[i][20]; - record.strategyPhase = dataFile[i][21]; - record.takeProfit = dataFile[i][22]; - record.stopLossPhase = dataFile[i][23]; - record.takeProfitPhase = dataFile[i][24]; - record.positionSize = dataFile[i][26]; // 25 is the message for the executor - record.initialBalanceA = dataFile[i][27]; - record.minimunBalanceA = dataFile[i][28]; - record.maximunBalanceA = dataFile[i][29]; - record.initialBalanceB = dataFile[i][30]; - record.minimunBalanceB = dataFile[i][31]; - record.maximunBalanceB = dataFile[i][32]; - record.baseAsset = dataFile[i][33]; - record.positionPeriods = dataFile[i][34]; - record.positionDays = dataFile[i][35]; - - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", thisObject.currentRecord); - } - - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } - } - } - - function recalculateScale() { - try { - // No scale needed - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } - } - } - - function plotChart() { - try { - let userPosition = getUserPosition() - let userPositionDate = userPosition.point.x - - let record; - - /* Now we calculate and plot the records */ - for (let i = 0; i < records.length; i++) { // We do not start in 0 so as to be able to read the previous record i - 1 - - record = records[i]; - - /* Send the current record to the panel */ - - if (userPositionDate >= record.begin && userPositionDate <= record.end) { - - let eventRecords = { - currentRecord: record, - lastRecord: records[records.length - 1] - }; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", eventRecords); - } - } - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } - } - } - - function onZoomChanged(event) { - try { - recalculate(); - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } - } - } - - function onOffsetChanged() { - try { - if (Math.random() * 100 > 95) { - recalculate() - }; - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } - } - } - - function onDragFinished() { - try { - recalculate(); - } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err = " + err.stack); } - } - } -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/FinalResultsPanel.js b/FinalResultsPanel.js deleted file mode 100644 index 0907ae991..000000000 --- a/FinalResultsPanel.js +++ /dev/null @@ -1,360 +0,0 @@ - -function newAAMastersPlottersTradingSimulationTradingSimulationFinalResultsPanel() { - - let thisObject = { - fitFunction: undefined, - onEventRaised: onEventRaised, - container: undefined, - draw: draw, - getContainer: getContainer, - initialize: initialize, - finalize: finalize - }; - - let container = newContainer(); - container.initialize(); - thisObject.container = container; - - container.displacement.containerName = "Final Results"; - container.frame.containerName = "Final Results"; - - let currentRecord; - let lastRecord; - let panelTabButton - - - return thisObject; - - function initialize() { - - thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL * 2; - thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 2.5; - - thisObject.container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 1; - thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y; - - panelTabButton = newPanelTabButton() - panelTabButton.parentContainer = thisObject.container - panelTabButton.container.frame.parentFrame = thisObject.container.frame - panelTabButton.fitFunction = thisObject.fitFunction - panelTabButton.initialize() - - } - - function finalize() { - - } - - function getContainer(point) { - - let container; - - container = panelTabButton.getContainer(point) - if (container !== undefined) { return container } - - if (thisObject.container.frame.isThisPointHere(point, true) === true) { - - let checkPoint = { - x: point.x, - y: point.y - } - - checkPoint = thisObject.fitFunction(checkPoint) - - if (point.x === checkPoint.x && point.y === checkPoint.y) { - return thisObject.container; - } - } - } - - - function onEventRaised(records) { - - currentRecord = records.currentRecord; - lastRecord = records.lastRecord - - } - - - function draw() { - - thisObject.container.frame.draw(false, false, true, thisObject.fitFunction); - - plotCurrentRecordInfo(); - - panelTabButton.draw() - } - - - function plotCurrentRecordInfo() { - - if (currentRecord === undefined) { return; } - if (lastRecord === undefined) { return; } - - const frameBodyHeight = thisObject.container.frame.getBodyHeight(); - const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; - - const X_AXIS = thisObject.container.frame.width / 2; - const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; - - - /* put the labels with the records values */ - - browserCanvasContext.beginPath(); - - let y = 0; - let increment = 0.024; - - y = y + increment; - y = y + increment; - printLabel('Current Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); - - y = y + increment; - printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - y = y + increment; - printLabel('Latest Position', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1', 14); - - y = y + increment; - printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - - - let bifurcationLevel = y - y = y + increment; - y = y + increment; - printLabel('Partial Results', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1', 14); - - y = y + increment; - printLabel('Profit / Loss', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.profit, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Trades', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.roundtrips, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Hits', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.hits, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Fails', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.fails, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Hit Ratio', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('ROI', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Periods', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.periods, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Days', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(currentRecord.days, X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Anualized Rate of Return', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS - thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - - y = bifurcationLevel - - y = y + increment; - y = y + increment; - printLabel('Final Results', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1', 14); - - y = y + increment; - printLabel('Profit / Loss', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.profit, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Trades', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.roundtrips, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Hits', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.hits, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Fails', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.fails, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Hit Ratio', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((lastRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('ROI', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((lastRecord.ROI * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Periods', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.periods, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Days', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel(lastRecord.days, X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - y = y + increment; - printLabel('Anualized Rate of Return', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '0.60'); - y = y + increment; - printLabel((lastRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS + thisObject.container.frame.width / 4, frameTitleHeight + frameBodyHeight * y, '1.00', 14); - - - - function printLabel(labelToPrint, x, y, opacity, fontSize) { - - let labelPoint; - if (fontSize === undefined) { fontSize = 10 }; - - browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY; - - let label = '' + labelToPrint; - if (isNaN(label) === false) { - label = Number(label).toLocaleString(); - if ((label === "-0" || label === "0") && (labelToPrint !== 0) && (labelToPrint !== "0.00")) { - label = Number(labelToPrint).toFixed(6); - } - } - let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO; - - labelPoint = { - x: x - xOffset, - y: y - }; - - labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); - labelPoint = thisObject.fitFunction(labelPoint) - - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; - browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - - } - - browserCanvasContext.closePath(); - browserCanvasContext.fill(); - - /* Parameters */ - let params - let paramsArray = [] - let positionTaken = false - - if (currentRecord.positionSize > 0) { - positionTaken = true - } - - params = {} - params.VALUE = currentRecord.balanceA; - params.INIT_VALUE = currentRecord.initialBalanceA - params.MIN_VALUE = currentRecord.minimunBalanceA - params.MAX_VALUE = currentRecord.maximunBalanceA - params.ASSET_LABEL = 'Asset A' - params.ASSET_NAME = DEFAULT_MARKET.assetB - params.LEFT_OFFSET = 100 - params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset - params.DECIMALS = 4 - - paramsArray.push(params) - - params = {} - params.VALUE = currentRecord.balanceB; - params.MIN_VALUE = currentRecord.minimunBalanceB - params.INIT_VALUE = currentRecord.initialBalanceB - params.MAX_VALUE = currentRecord.maximunBalanceB - params.ASSET_LABEL = 'Asset B' - params.ASSET_NAME = DEFAULT_MARKET.assetA - params.LEFT_OFFSET = 220 - params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset - params.DECIMALS = 2 - - paramsArray.push(params) - - canvas.cockpitSpace.assetBalances.setParamsArray(paramsArray) - } -} - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Project.njsproj b/Project.njsproj index 40731b136..1b64cc95b 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -20,8 +20,6 @@ Code - - Code diff --git a/Project.njsproj.user b/Project.njsproj.user new file mode 100644 index 000000000..db8622989 --- /dev/null +++ b/Project.njsproj.user @@ -0,0 +1,6 @@ + + + + Debug|Any CPU + + \ No newline at end of file diff --git a/TradingSimulation.js b/TradingSimulation.js index f9b3b5787..44cddb7bb 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -353,42 +353,39 @@ record.begin = dailyFile[i][0]; record.end = dailyFile[i][1]; - record.type = dailyFile[i][2]; - record.rate = dailyFile[i][3]; - record.amount = dailyFile[i][4]; - record.balanceA = dailyFile[i][5]; - record.balanceB = dailyFile[i][6]; - record.profit = dailyFile[i][7]; - record.lastTradeProfitLoss = dailyFile[i][8]; - record.stopLoss = dailyFile[i][9]; - record.roundtrips = dailyFile[i][10]; - record.hits = dailyFile[i][11]; - record.fails = dailyFile[i][12]; - record.hitRatio = dailyFile[i][13]; - record.ROI = dailyFile[i][14]; - record.periods = dailyFile[i][15]; - record.days = dailyFile[i][16]; - record.anualizedRateOfReturn = dailyFile[i][17]; - record.sellRate = dailyFile[i][18]; - record.lastTradeROI = dailyFile[i][19]; - record.strategy = dailyFile[i][20]; - record.strategyPhase = dailyFile[i][21]; - record.takeProfit = dailyFile[i][22]; - record.stopLossPhase = dailyFile[i][23]; - record.takeProfitPhase = dailyFile[i][24]; - record.positionSize = dailyFile[i][26]; // 25 is the message for the executor - record.initialBalanceA = dailyFile[i][27]; - record.minimunBalanceA = dailyFile[i][28]; - record.maximunBalanceA = dailyFile[i][29]; - record.initialBalanceB = dailyFile[i][30]; - record.minimunBalanceB = dailyFile[i][31]; - record.maximunBalanceB = dailyFile[i][32]; - record.baseAsset = dailyFile[i][33]; - record.quotedAsset = dailyFile[i][34]; - record.marketBaseAsset = dailyFile[i][35]; - record.marketQuotedAsset = dailyFile[i][36]; - record.positionPeriods = dailyFile[i][37]; - record.positionDays = dailyFile[i][38]; + record.amount = dailyFile[i][2]; + record.balanceA = dailyFile[i][3]; + record.balanceB = dailyFile[i][4]; + record.accumulatedProfitLoss = dailyFile[i][5]; + record.lastTradeProfitLoss = dailyFile[i][6]; + record.stopLoss = dailyFile[i][7]; + record.tradesCount = dailyFile[i][8]; + record.hits = dailyFile[i][9]; + record.fails = dailyFile[i][10]; + record.hitRatio = dailyFile[i][11]; + record.ROI = dailyFile[i][12]; + record.periods = dailyFile[i][13]; + record.days = dailyFile[i][14]; + record.anualizedRateOfReturn = dailyFile[i][15]; + record.sellRate = dailyFile[i][16]; + record.lastTradeROI = dailyFile[i][17]; + record.strategy = dailyFile[i][18]; + record.takeProfit = dailyFile[i][19]; + record.stopLossPhase = dailyFile[i][20]; + record.takeProfitPhase = dailyFile[i][21]; + record.positionSize = dailyFile[i][22]; // 25 is the message for the executor + record.initialBalanceA = dailyFile[i][23]; + record.minimunBalanceA = dailyFile[i][24]; + record.maximunBalanceA = dailyFile[i][25]; + record.initialBalanceB = dailyFile[i][26]; + record.minimunBalanceB = dailyFile[i][27]; + record.maximunBalanceB = dailyFile[i][28]; + record.baseAsset = dailyFile[i][29]; + record.quotedAsset = dailyFile[i][30]; + record.marketBaseAsset = dailyFile[i][31]; + record.marketQuotedAsset = dailyFile[i][32]; + record.positionPeriods = dailyFile[i][33]; + record.positionDays = dailyFile[i][34]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -447,42 +444,39 @@ record.begin = marketFile[i][0]; record.end = marketFile[i][1]; - record.type = marketFile[i][2]; - record.rate = marketFile[i][3]; - record.amount = marketFile[i][4]; - record.balanceA = marketFile[i][5]; - record.balanceB = marketFile[i][6]; - record.profit = marketFile[i][7]; - record.lastTradeProfitLoss = marketFile[i][8]; - record.stopLoss = marketFile[i][9]; - record.roundtrips = marketFile[i][10]; - record.hits = marketFile[i][11]; - record.fails = marketFile[i][12]; - record.hitRatio = marketFile[i][13]; - record.ROI = marketFile[i][14]; - record.periods = marketFile[i][15]; - record.days = marketFile[i][16]; - record.anualizedRateOfReturn = marketFile[i][17]; - record.sellRate = marketFile[i][18]; - record.lastTradeROI = marketFile[i][19]; - record.strategy = marketFile[i][20]; - record.strategyPhase = marketFile[i][21]; - record.takeProfit = marketFile[i][22]; - record.stopLossPhase = marketFile[i][23]; - record.takeProfitPhase = marketFile[i][24]; - record.positionSize = marketFile[i][26]; // 25 is the message for the executor - record.initialBalanceA = marketFile[i][27]; - record.minimunBalanceA = marketFile[i][28]; - record.maximunBalanceA = marketFile[i][29]; - record.initialBalanceB = marketFile[i][30]; - record.minimunBalanceB = marketFile[i][31]; - record.maximunBalanceB = marketFile[i][32]; - record.baseAsset = marketFile[i][33]; - record.quotedAsset = marketFile[i][34]; - record.marketBaseAsset = marketFile[i][35]; - record.marketQuotedAsset = marketFile[i][36]; - record.positionPeriods = marketFile[i][37]; - record.positionDays = marketFile[i][38]; + record.amount = marketFile[i][2]; + record.balanceA = marketFile[i][3]; + record.balanceB = marketFile[i][4]; + record.accumulatedProfitLoss = marketFile[i][5]; + record.lastTradeProfitLoss = marketFile[i][6]; + record.stopLoss = marketFile[i][7]; + record.tradesCount = marketFile[i][8]; + record.hits = marketFile[i][9]; + record.fails = marketFile[i][10]; + record.hitRatio = marketFile[i][11]; + record.ROI = marketFile[i][12]; + record.periods = marketFile[i][13]; + record.days = marketFile[i][14]; + record.anualizedRateOfReturn = marketFile[i][15]; + record.sellRate = marketFile[i][16]; + record.lastTradeROI = marketFile[i][17]; + record.strategy = marketFile[i][18]; + record.takeProfit = marketFile[i][19]; + record.stopLossPhase = marketFile[i][20]; + record.takeProfitPhase = marketFile[i][21]; + record.positionSize = marketFile[i][22]; + record.initialBalanceA = marketFile[i][23]; + record.minimunBalanceA = marketFile[i][24]; + record.maximunBalanceA = marketFile[i][25]; + record.initialBalanceB = marketFile[i][26]; + record.minimunBalanceB = marketFile[i][27]; + record.maximunBalanceB = marketFile[i][28]; + record.baseAsset = marketFile[i][29]; + record.quotedAsset = marketFile[i][30]; + record.marketBaseAsset = marketFile[i][31]; + record.marketQuotedAsset = marketFile[i][32]; + record.positionPeriods = marketFile[i][33]; + record.positionDays = marketFile[i][34]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && @@ -728,7 +722,7 @@ imageSize = 20; let imageToDraw; - /* Depending on what is on top, it is also the text and image of the take profit / stop loss */ + /* Depending on what is on top, it is also the text and image of the take accumulatedProfitLoss / stop loss */ let yOffset = 0 if (record.takeProfit > record.stopLoss) { yOffset = imageSize * 2 } diff --git a/TradingSimulationPartialResultsPanel.js b/TradingSimulationPartialResultsPanel.js index bd07abf7d..3a1f4f8e2 100644 --- a/TradingSimulationPartialResultsPanel.js +++ b/TradingSimulationPartialResultsPanel.js @@ -131,12 +131,12 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.profit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(currentRecord.accumulatedProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.roundtrips, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(currentRecord.tradesCount, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); From 750c6084ccd071c3360e1bdf2fe3007c5292c5ee Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 19 May 2020 20:15:29 +0200 Subject: [PATCH 151/157] refactoring done --- TradingSimulation.js | 130 ++++++++++++------------- TradingSimulationAssetBalancesPanel.js | 8 +- 2 files changed, 68 insertions(+), 70 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 44cddb7bb..8f86d0886 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -353,39 +353,38 @@ record.begin = dailyFile[i][0]; record.end = dailyFile[i][1]; - record.amount = dailyFile[i][2]; - record.balanceA = dailyFile[i][3]; - record.balanceB = dailyFile[i][4]; - record.accumulatedProfitLoss = dailyFile[i][5]; - record.lastTradeProfitLoss = dailyFile[i][6]; - record.stopLoss = dailyFile[i][7]; - record.tradesCount = dailyFile[i][8]; - record.hits = dailyFile[i][9]; - record.fails = dailyFile[i][10]; - record.hitRatio = dailyFile[i][11]; - record.ROI = dailyFile[i][12]; - record.periods = dailyFile[i][13]; - record.days = dailyFile[i][14]; - record.anualizedRateOfReturn = dailyFile[i][15]; - record.sellRate = dailyFile[i][16]; - record.lastTradeROI = dailyFile[i][17]; - record.strategy = dailyFile[i][18]; - record.takeProfit = dailyFile[i][19]; - record.stopLossPhase = dailyFile[i][20]; - record.takeProfitPhase = dailyFile[i][21]; - record.positionSize = dailyFile[i][22]; // 25 is the message for the executor - record.initialBalanceA = dailyFile[i][23]; - record.minimunBalanceA = dailyFile[i][24]; - record.maximunBalanceA = dailyFile[i][25]; - record.initialBalanceB = dailyFile[i][26]; - record.minimunBalanceB = dailyFile[i][27]; - record.maximunBalanceB = dailyFile[i][28]; - record.baseAsset = dailyFile[i][29]; - record.quotedAsset = dailyFile[i][30]; - record.marketBaseAsset = dailyFile[i][31]; - record.marketQuotedAsset = dailyFile[i][32]; - record.positionPeriods = dailyFile[i][33]; - record.positionDays = dailyFile[i][34]; + record.balanceBaseAsset = dailyFile[i][2]; + record.balanceQuotedAsset = dailyFile[i][3]; + record.accumulatedProfitLoss = dailyFile[i][4]; + record.lastTradeProfitLoss = dailyFile[i][5]; + record.stopLoss = dailyFile[i][6]; + record.tradesCount = dailyFile[i][7]; + record.hits = dailyFile[i][8]; + record.fails = dailyFile[i][9]; + record.hitRatio = dailyFile[i][10]; + record.ROI = dailyFile[i][11]; + record.periods = dailyFile[i][12]; + record.days = dailyFile[i][13]; + record.anualizedRateOfReturn = dailyFile[i][14]; + record.sellRate = dailyFile[i][15]; + record.lastTradeROI = dailyFile[i][16]; + record.strategy = dailyFile[i][17]; + record.takeProfit = dailyFile[i][18]; + record.stopLossPhase = dailyFile[i][19]; + record.takeProfitPhase = dailyFile[i][20]; + record.positionSize = dailyFile[i][21]; // 25 is the message for the executor + record.initialBalanceA = dailyFile[i][22]; + record.minimunBalanceA = dailyFile[i][23]; + record.maximunBalanceA = dailyFile[i][24]; + record.initialBalanceB = dailyFile[i][25]; + record.minimunBalanceB = dailyFile[i][26]; + record.maximunBalanceB = dailyFile[i][27]; + record.baseAsset = dailyFile[i][28]; + record.quotedAsset = dailyFile[i][29]; + record.marketBaseAsset = dailyFile[i][30]; + record.marketQuotedAsset = dailyFile[i][31]; + record.positionPeriods = dailyFile[i][32]; + record.positionDays = dailyFile[i][33]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -444,39 +443,38 @@ record.begin = marketFile[i][0]; record.end = marketFile[i][1]; - record.amount = marketFile[i][2]; - record.balanceA = marketFile[i][3]; - record.balanceB = marketFile[i][4]; - record.accumulatedProfitLoss = marketFile[i][5]; - record.lastTradeProfitLoss = marketFile[i][6]; - record.stopLoss = marketFile[i][7]; - record.tradesCount = marketFile[i][8]; - record.hits = marketFile[i][9]; - record.fails = marketFile[i][10]; - record.hitRatio = marketFile[i][11]; - record.ROI = marketFile[i][12]; - record.periods = marketFile[i][13]; - record.days = marketFile[i][14]; - record.anualizedRateOfReturn = marketFile[i][15]; - record.sellRate = marketFile[i][16]; - record.lastTradeROI = marketFile[i][17]; - record.strategy = marketFile[i][18]; - record.takeProfit = marketFile[i][19]; - record.stopLossPhase = marketFile[i][20]; - record.takeProfitPhase = marketFile[i][21]; - record.positionSize = marketFile[i][22]; - record.initialBalanceA = marketFile[i][23]; - record.minimunBalanceA = marketFile[i][24]; - record.maximunBalanceA = marketFile[i][25]; - record.initialBalanceB = marketFile[i][26]; - record.minimunBalanceB = marketFile[i][27]; - record.maximunBalanceB = marketFile[i][28]; - record.baseAsset = marketFile[i][29]; - record.quotedAsset = marketFile[i][30]; - record.marketBaseAsset = marketFile[i][31]; - record.marketQuotedAsset = marketFile[i][32]; - record.positionPeriods = marketFile[i][33]; - record.positionDays = marketFile[i][34]; + record.balanceBaseAsset = marketFile[i][2]; + record.balanceQuotedAsset = marketFile[i][3]; + record.accumulatedProfitLoss = marketFile[i][4]; + record.lastTradeProfitLoss = marketFile[i][5]; + record.stopLoss = marketFile[i][6]; + record.tradesCount = marketFile[i][7]; + record.hits = marketFile[i][8]; + record.fails = marketFile[i][9]; + record.hitRatio = marketFile[i][10]; + record.ROI = marketFile[i][11]; + record.periods = marketFile[i][12]; + record.days = marketFile[i][13]; + record.anualizedRateOfReturn = marketFile[i][14]; + record.sellRate = marketFile[i][15]; + record.lastTradeROI = marketFile[i][16]; + record.strategy = marketFile[i][17]; + record.takeProfit = marketFile[i][18]; + record.stopLossPhase = marketFile[i][19]; + record.takeProfitPhase = marketFile[i][20]; + record.positionSize = marketFile[i][21]; + record.initialBalanceA = marketFile[i][22]; + record.minimunBalanceA = marketFile[i][23]; + record.maximunBalanceA = marketFile[i][24]; + record.initialBalanceB = marketFile[i][25]; + record.minimunBalanceB = marketFile[i][26]; + record.maximunBalanceB = marketFile[i][27]; + record.baseAsset = marketFile[i][28]; + record.quotedAsset = marketFile[i][29]; + record.marketBaseAsset = marketFile[i][30]; + record.marketQuotedAsset = marketFile[i][31]; + record.positionPeriods = marketFile[i][32]; + record.positionDays = marketFile[i][33]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index 7272577da..d9e69a743 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -156,7 +156,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul if (currentRecord.baseAsset === currentRecord.marketBaseAsset) { params = {} - params.VALUE = currentRecord.balanceA; + params.VALUE = currentRecord.balanceBaseAsset; params.INIT_VALUE = currentRecord.initialBalanceA params.MIN_VALUE = currentRecord.minimunBalanceA params.MAX_VALUE = currentRecord.maximunBalanceA @@ -170,7 +170,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul paramsArray.push(params) params = {} - params.VALUE = currentRecord.balanceB; + params.VALUE = currentRecord.balanceQuotedAsset; params.MIN_VALUE = currentRecord.minimunBalanceB params.INIT_VALUE = currentRecord.initialBalanceB params.MAX_VALUE = currentRecord.maximunBalanceB @@ -184,7 +184,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul paramsArray.push(params) } else { params = {} - params.VALUE = currentRecord.balanceB; + params.VALUE = currentRecord.balanceQuotedAsset; params.INIT_VALUE = currentRecord.initialBalanceB params.MIN_VALUE = currentRecord.minimunBalanceB params.MAX_VALUE = currentRecord.maximunBalanceB @@ -198,7 +198,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul paramsArray.push(params) params = {} - params.VALUE = currentRecord.balanceA; + params.VALUE = currentRecord.balanceBaseAsset; params.MIN_VALUE = currentRecord.minimunBalanceA params.INIT_VALUE = currentRecord.initialBalanceA params.MAX_VALUE = currentRecord.maximunBalanceA From 593b0f21919f0dbe8a3419f23930d967170e1731 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 21 May 2020 08:45:40 +0200 Subject: [PATCH 152/157] record --- Conditions.js | 74 ++++++++++++------------ SimulationExecution.js | 14 ++--- SimulationExecutionPanel.js | 26 ++++----- Strategies.js | 14 ++--- Trades.js | 14 ++--- TradingSimulation.js | 12 ++-- TradingSimulationAssetBalancesPanel.js | 60 +++++++++---------- TradingSimulationCurrentPositionPanel.js | 24 ++++---- TradingSimulationPartialResultsPanel.js | 26 ++++----- 9 files changed, 132 insertions(+), 132 deletions(-) diff --git a/Conditions.js b/Conditions.js index 8115c6e9e..0ef615f9d 100644 --- a/Conditions.js +++ b/Conditions.js @@ -25,7 +25,7 @@ // Secondary functions and properties. - currentRecord: undefined + record: undefined }; /* this is part of the module template */ @@ -390,8 +390,8 @@ if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Condition Changed", thisObject.currentRecord); + thisObject.record = record; + thisObject.container.eventHandler.raiseEvent("Current Condition Changed", thisObject.record); } } @@ -461,8 +461,8 @@ if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Condition Changed", thisObject.currentRecord); + thisObject.record = record; + thisObject.container.eventHandler.raiseEvent("Current Condition Changed", thisObject.record); } } @@ -492,7 +492,7 @@ if (userPositionDate >= conditionRecord.begin && userPositionDate <= conditionRecord.end) { - let currentRecord = { + let record = { conditionsNames: headers, strategyIndex: conditionRecord.strategyIndex, stopLossPhase: conditionRecord.stopLossPhase, @@ -502,7 +502,7 @@ formulaValues: conditionRecord.formulaValues }; - sendRecordInfoToDesignerSpace(currentRecord) + sendRecordInfoToDesignerSpace(record) } } @@ -512,15 +512,15 @@ } } - function sendRecordInfoToDesignerSpace(currentRecord) { + function sendRecordInfoToDesignerSpace(record) { - if (currentRecord === undefined) { return; } - if (currentRecord.conditionsNames === undefined) { return; } + if (record === undefined) { return; } + if (record.conditionsNames === undefined) { return; } if (canvas.designSpace.workspace === undefined) { return; } /* We will get now the designer trading system */ let designerTradingSystem - let fileTradingSystem = currentRecord.conditionsNames; + let fileTradingSystem = record.conditionsNames; for (let i = 0; i < canvas.designSpace.workspace.workspaceNode.rootNodes.length; i++) { let rootNode = canvas.designSpace.workspace.workspaceNode.rootNodes[i] @@ -565,7 +565,7 @@ let strategy = fileTradingSystem.strategies[j]; designerTradingSystem.strategies[j].payload.uiObject.setErrorMessage(strategy.error) - if (currentRecord.strategyIndex === j) { + if (record.strategyIndex === j) { designerTradingSystem.strategies[j].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].payload.uiObject.isExecuting = false @@ -650,7 +650,7 @@ for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { - if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase === p) { + if (record.strategyIndex === j && record.stopLossPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -662,15 +662,15 @@ if (phase.formula !== undefined) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) - if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase === p) { - designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + if (record.formulaErrors[formulaErrorsIndex] !== "") { + if (record.strategyIndex === j && record.stopLossPhase === p) { + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(record.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase === p) { - designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + if (record.strategyIndex === j && record.stopLossPhase === p) { + designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(record.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } @@ -735,7 +735,7 @@ for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { - if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase === p) { + if (record.strategyIndex === j && record.takeProfitPhase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -747,15 +747,15 @@ if (phase.formula !== undefined) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) - if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase === p) { - designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + if (record.formulaErrors[formulaErrorsIndex] !== "") { + if (record.strategyIndex === j && record.takeProfitPhase === p) { + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(record.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase === p) { - designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + if (record.strategyIndex === j && record.takeProfitPhase === p) { + designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(record.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } @@ -833,7 +833,7 @@ for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { - if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase - 1 === p) { + if (record.strategyIndex === j && record.stopLossPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -845,14 +845,14 @@ if (phase.formula !== undefined) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) - if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase - 1 === p) { - designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + if (record.formulaErrors[formulaErrorsIndex] !== "") { + if (record.strategyIndex === j && record.stopLossPhase - 1 === p) { + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(record.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyIndex === j && currentRecord.stopLossPhase - 1 === p) { - designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + if (record.strategyIndex === j && record.stopLossPhase - 1 === p) { + designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(record.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } @@ -917,7 +917,7 @@ for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { - if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase - 1 === p) { + if (record.strategyIndex === j && record.takeProfitPhase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -929,15 +929,15 @@ if (phase.formula !== undefined) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) - if (currentRecord.formulaErrors[formulaErrorsIndex] !== "") { - if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase - 1 === p) { - designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(currentRecord.formulaErrors[formulaErrorsIndex]) + if (record.formulaErrors[formulaErrorsIndex] !== "") { + if (record.strategyIndex === j && record.takeProfitPhase - 1 === p) { + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(record.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (currentRecord.strategyIndex === j && currentRecord.takeProfitPhase - 1 === p) { - designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(currentRecord.formulaValues[formulaValuesIndex]) + if (record.strategyIndex === j && record.takeProfitPhase - 1 === p) { + designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(record.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ } @@ -1029,7 +1029,7 @@ } } - if (currentRecord.conditionsValues[conditionIndex] === 1) { + if (record.conditionsValues[conditionIndex] === 1) { condition.payload.uiObject.highlight() } else { highlightSituation = false diff --git a/SimulationExecution.js b/SimulationExecution.js index 9db58a633..cecae899f 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -342,7 +342,7 @@ function plotChart() { try { - let currentRecord + let record let point = { x: 0, @@ -358,7 +358,7 @@ for (let i = 0; i < history.length; i++) { record = history[i]; - currentRecord = record + record = record let timestamp = record.date // Math.trunc(record.date / timeFrame) * timeFrame + timeFrame / 2; @@ -427,7 +427,7 @@ point2.y = point2.y - diff; point3.y = point3.y - diff; - currentRecord.timeFrame = diff + record.timeFrame = diff point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); @@ -502,7 +502,7 @@ point2.y = point2.y + diff; point3.y = point3.y + diff; - currentRecord.timeFrame = diff + record.timeFrame = diff point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); @@ -575,7 +575,7 @@ point2.y = point2.y - diff; point3.y = point3.y - diff; - currentRecord.timeFrame = diff + record.timeFrame = diff point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); @@ -649,7 +649,7 @@ point2.y = point2.y + diff; point3.y = point3.y + diff; - currentRecord.timeFrame = diff + record.timeFrame = diff point2 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point2); point3 = canvas.chartingSpace.viewport.fitIntoVisibleArea(point3); @@ -683,7 +683,7 @@ /* Send the current record to the panel */ if (userPositionDate >= record.date - 30000 && userPositionDate < record.date + 30000) { - thisObject.container.eventHandler.raiseEvent("Current Record Changed", currentRecord); + thisObject.container.eventHandler.raiseEvent("Current Record Changed", record); } /* Circles */ diff --git a/SimulationExecutionPanel.js b/SimulationExecutionPanel.js index 48410e698..ad1e51b7b 100644 --- a/SimulationExecutionPanel.js +++ b/SimulationExecutionPanel.js @@ -19,7 +19,7 @@ function newTradingEnginesPlottersTradingSimulationSimulationExecutionSimulation container.frame.containerName = "Trading Execution"; - let currentRecord; + let record; let upDownButton return thisObject; @@ -30,7 +30,7 @@ function newTradingEnginesPlottersTradingSimulationSimulationExecutionSimulation thisObject.fitFunction = undefined thisObject.isVisible = undefined - currentRecord = undefined + record = undefined upDownButton.finalize() upDownButton = undefined } @@ -75,7 +75,7 @@ function newTradingEnginesPlottersTradingSimulationSimulationExecutionSimulation function onRecordChange(lastCurrentCandle) { - currentRecord = lastCurrentCandle; + record = lastCurrentCandle; } @@ -93,7 +93,7 @@ function newTradingEnginesPlottersTradingSimulationSimulationExecutionSimulation function plot() { - if (currentRecord === undefined) { return; } + if (record === undefined) { return; } const frameBodyHeight = thisObject.container.frame.getBodyHeight(); const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; @@ -101,7 +101,7 @@ function newTradingEnginesPlottersTradingSimulationSimulationExecutionSimulation const X_AXIS = thisObject.container.frame.width / 2; const Y_AXIS = frameTitleHeight + frameBodyHeight / 2; - record = currentRecord + record = record point = { x: X_AXIS, @@ -395,28 +395,28 @@ function newTradingEnginesPlottersTradingSimulationSimulationExecutionSimulation browserCanvasContext.beginPath(); let y; - let recordDate = new Date(currentRecord.datetime) + let recordDate = new Date(record.datetime) printLabel('Market Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.05 / 2, '1'); - printLabel(currentRecord.marketRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.10 / 2, '0.50'); + printLabel(record.marketRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.10 / 2, '0.50'); printLabel('Sell Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.15 / 2, '1'); - printLabel(currentRecord.lastSellRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.20 / 2, '0.50'); + printLabel(record.lastSellRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.20 / 2, '0.50'); printLabel('Sell Executed Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.25 / 2, '1'); - printLabel(currentRecord.sellExecRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.30 / 2, '0.50'); + printLabel(record.sellExecRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.30 / 2, '0.50'); printLabel('Buy Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.35 / 2, '1'); - printLabel(currentRecord.lastBuyRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.40 / 2, '0.40'); + printLabel(record.lastBuyRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.40 / 2, '0.40'); printLabel('Buy Executed Rate', X_AXIS, frameTitleHeight + frameBodyHeight * 0.45 / 2, '1'); - printLabel(currentRecord.buyExecRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.50 / 2, '0.50'); + printLabel(record.buyExecRate, X_AXIS, frameTitleHeight + frameBodyHeight * 0.50 / 2, '0.50'); printLabel('ROI Asset A', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.25 / 2), '1'); - printLabel((currentRecord.combinedProfitsB).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.30 / 2), '0.50'); + printLabel((record.combinedProfitsB).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.30 / 2), '0.50'); printLabel('ROI Asset B', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.15 / 2), '1'); - printLabel((currentRecord.combinedProfitsA).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.20 / 2), '0.50'); + printLabel((record.combinedProfitsA).toFixed(2) + '%', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.20 / 2), '0.50'); printLabel('Datetime', X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.05 / 2), '1'); printLabel(recordDate.toUTCString(), X_AXIS, frameTitleHeight + frameBodyHeight * (1 - 0.1 / 2), '0.50'); diff --git a/Strategies.js b/Strategies.js index 2e82c2267..c793f07ec 100644 --- a/Strategies.js +++ b/Strategies.js @@ -27,7 +27,7 @@ // Secondary functions and properties. - currentRecord: undefined + record: undefined }; /* this is part of the module template */ @@ -395,8 +395,8 @@ if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Strategy Changed", thisObject.currentRecord); + thisObject.record = record; + thisObject.container.eventHandler.raiseEvent("Current Strategy Changed", thisObject.record); } } @@ -468,8 +468,8 @@ (record.begin >= coordinateSystem.min.x && record.end <= coordinateSystem.max.x) ) { - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Strategy Changed", thisObject.currentRecord); + thisObject.record = record; + thisObject.container.eventHandler.raiseEvent("Current Strategy Changed", thisObject.record); } } @@ -609,9 +609,9 @@ if (userPositionDate >= record.begin && userPositionDate <= record.end) { - let currentRecord = { + let record = { }; - thisObject.container.eventHandler.raiseEvent("Current Strategy Record Changed", currentRecord); + thisObject.container.eventHandler.raiseEvent("Current Strategy Record Changed", record); } function drawStick(point1, point2) { diff --git a/Trades.js b/Trades.js index 9da7b37b6..dffb5e03b 100644 --- a/Trades.js +++ b/Trades.js @@ -27,7 +27,7 @@ // Secondary functions and properties. - currentRecord: undefined + record: undefined }; /* this is part of the module template */ @@ -381,8 +381,8 @@ if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Trade Changed", thisObject.currentRecord); + thisObject.record = record; + thisObject.container.eventHandler.raiseEvent("Current Trade Changed", thisObject.record); } } @@ -447,8 +447,8 @@ if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Trade Changed", thisObject.currentRecord); + thisObject.record = record; + thisObject.container.eventHandler.raiseEvent("Current Trade Changed", thisObject.record); } } @@ -478,9 +478,9 @@ if (userPositionDate >= record.begin && userPositionDate <= record.end) { - let currentRecord = { + let record = { }; - thisObject.container.eventHandler.raiseEvent("Current Trade Record Changed", currentRecord); + thisObject.container.eventHandler.raiseEvent("Current Trade Record Changed", record); } let recordPoint1 = { diff --git a/TradingSimulation.js b/TradingSimulation.js index 8f86d0886..da7c86a33 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -26,7 +26,7 @@ // Secondary functions and properties. - currentRecord: undefined + record: undefined }; /* this is part of the module template */ @@ -395,8 +395,8 @@ if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", thisObject.currentRecord); + thisObject.record = record; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", thisObject.record); } } @@ -485,8 +485,8 @@ if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { - thisObject.currentRecord = record; - thisObject.container.eventHandler.raiseEvent("Current Record Changed", thisObject.currentRecord); + thisObject.record = record; + thisObject.container.eventHandler.raiseEvent("Current Record Changed", thisObject.record); } } @@ -525,7 +525,7 @@ if (userPositionDate >= record.begin && userPositionDate <= record.end) { let eventRecords = { - currentRecord: record + record: record }; thisObject.container.eventHandler.raiseEvent("Current Record Changed", eventRecords); } diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index d9e69a743..90dd81025 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -19,7 +19,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul container.frame.containerName = "Simulation Asset Balances Panel"; - let currentRecord; + let record; let lastRecord; let upDownButton @@ -56,7 +56,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul thisObject.onRecordChange = undefined thisObject.isVisible = undefined - currentRecord = undefined + record = undefined lastRecord = undefined upDownButton = undefined @@ -89,7 +89,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul function onRecordChange(records) { - currentRecord = records.currentRecord; + record = records.record; lastRecord = records.lastRecord } @@ -117,7 +117,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul function plotCurrentRecordInfo() { - if (currentRecord === undefined) { return; } + if (record === undefined) { return; } const frameBodyHeight = thisObject.container.frame.getBodyHeight(); const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; @@ -139,7 +139,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul let paramsArray = [] let positionTaken = false - if (currentRecord.positionSize > 0) { + if (record.positionSize > 0) { positionTaken = true } @@ -154,59 +154,59 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul return } - if (currentRecord.baseAsset === currentRecord.marketBaseAsset) { + if (record.baseAsset === record.marketBaseAsset) { params = {} - params.VALUE = currentRecord.balanceBaseAsset; - params.INIT_VALUE = currentRecord.initialBalanceA - params.MIN_VALUE = currentRecord.minimunBalanceA - params.MAX_VALUE = currentRecord.maximunBalanceA + params.VALUE = record.balanceBaseAsset; + params.INIT_VALUE = record.initialBalanceA + params.MIN_VALUE = record.minimunBalanceA + params.MAX_VALUE = record.maximunBalanceA params.ASSET_LABEL = 'Base' - params.ASSET_NAME = currentRecord.baseAsset + params.ASSET_NAME = record.baseAsset params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset + params.BASE_ASSET = record.baseAsset params.DECIMALS = 4 paramsArray.push(params) params = {} - params.VALUE = currentRecord.balanceQuotedAsset; - params.MIN_VALUE = currentRecord.minimunBalanceB - params.INIT_VALUE = currentRecord.initialBalanceB - params.MAX_VALUE = currentRecord.maximunBalanceB + params.VALUE = record.balanceQuotedAsset; + params.MIN_VALUE = record.minimunBalanceB + params.INIT_VALUE = record.initialBalanceB + params.MAX_VALUE = record.maximunBalanceB params.ASSET_LABEL = 'Quoted' - params.ASSET_NAME = currentRecord.quotedAsset + params.ASSET_NAME = record.quotedAsset params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset + params.BASE_ASSET = record.baseAsset params.DECIMALS = 2 paramsArray.push(params) } else { params = {} - params.VALUE = currentRecord.balanceQuotedAsset; - params.INIT_VALUE = currentRecord.initialBalanceB - params.MIN_VALUE = currentRecord.minimunBalanceB - params.MAX_VALUE = currentRecord.maximunBalanceB + params.VALUE = record.balanceQuotedAsset; + params.INIT_VALUE = record.initialBalanceB + params.MIN_VALUE = record.minimunBalanceB + params.MAX_VALUE = record.maximunBalanceB params.ASSET_LABEL = 'Base' - params.ASSET_NAME = currentRecord.baseAsset + params.ASSET_NAME = record.baseAsset params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset + params.BASE_ASSET = record.baseAsset params.DECIMALS = 4 paramsArray.push(params) params = {} - params.VALUE = currentRecord.balanceBaseAsset; - params.MIN_VALUE = currentRecord.minimunBalanceA - params.INIT_VALUE = currentRecord.initialBalanceA - params.MAX_VALUE = currentRecord.maximunBalanceA + params.VALUE = record.balanceBaseAsset; + params.MIN_VALUE = record.minimunBalanceA + params.INIT_VALUE = record.initialBalanceA + params.MAX_VALUE = record.maximunBalanceA params.ASSET_LABEL = 'Quoted' - params.ASSET_NAME = currentRecord.quotedAsset + params.ASSET_NAME = record.quotedAsset params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = currentRecord.baseAsset + params.BASE_ASSET = record.baseAsset params.DECIMALS = 2 paramsArray.push(params) diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js index 6fc1ab6f5..1856c69d9 100644 --- a/TradingSimulationCurrentPositionPanel.js +++ b/TradingSimulationCurrentPositionPanel.js @@ -21,7 +21,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul container.frame.containerName = "Simulation Current Position Panel"; - let currentRecord; + let record; let lastRecord; let upDownButton @@ -54,7 +54,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul thisObject.onRecordChange = undefined thisObject.isVisible = undefined - currentRecord = undefined + record = undefined lastRecord = undefined upDownButton = undefined } @@ -84,7 +84,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul function onRecordChange(records) { - currentRecord = records.currentRecord; + record = records.record; lastRecord = records.lastRecord } @@ -112,7 +112,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul function plotCurrentRecordInfo() { - if (currentRecord === undefined) { return; } + if (record === undefined) { return; } const frameBodyHeight = thisObject.container.frame.getBodyHeight(); const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; @@ -133,32 +133,32 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; y = y + increment; @@ -167,12 +167,12 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); } } diff --git a/TradingSimulationPartialResultsPanel.js b/TradingSimulationPartialResultsPanel.js index 3a1f4f8e2..a6f50a3c5 100644 --- a/TradingSimulationPartialResultsPanel.js +++ b/TradingSimulationPartialResultsPanel.js @@ -19,7 +19,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul container.frame.containerName = "Simulation Partial Results Panel"; - let currentRecord; + let record; let lastRecord; let upDownButton @@ -52,7 +52,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul thisObject.onRecordChange = undefined thisObject.isVisible = undefined - currentRecord = undefined + record = undefined lastRecord = undefined upDownButton = undefined } @@ -82,7 +82,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul function onRecordChange(records) { - currentRecord = records.currentRecord; + record = records.record; lastRecord = records.lastRecord } @@ -110,7 +110,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul function plotCurrentRecordInfo() { - if (currentRecord === undefined) { return; } + if (record === undefined) { return; } const frameBodyHeight = thisObject.container.frame.getBodyHeight(); const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight; @@ -131,47 +131,47 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.accumulatedProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.accumulatedProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.tradesCount, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.tradesCount, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(currentRecord.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((currentRecord.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); } } From 0d2b27b322a8ab124f0b8075631956573f29b314 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 21 May 2020 08:55:56 +0200 Subject: [PATCH 153/157] Refactoring 50 percent --- Trades.js | 12 ++-- TradingSimulation.js | 80 ++++++++++++------------ TradingSimulationAssetBalancesPanel.js | 8 +-- TradingSimulationCurrentPositionPanel.js | 8 +-- TradingSimulationPartialResultsPanel.js | 18 +++--- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Trades.js b/Trades.js index dffb5e03b..c446e64fd 100644 --- a/Trades.js +++ b/Trades.js @@ -366,7 +366,7 @@ record.begin = dailyFile[i][0]; record.end = dailyFile[i][1]; record.status = dailyFile[i][2]; - record.lastTradeROI = dailyFile[i][3]; + record.record.variable_last_position_ROI = dailyFile[i][3]; record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; record.exitType = dailyFile[i][6]; @@ -432,7 +432,7 @@ record.begin = marketFile[i][0]; record.end = marketFile[i][1]; record.status = marketFile[i][2]; - record.lastTradeROI = marketFile[i][3]; + record.record.variable_last_position_ROI = marketFile[i][3]; record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; record.exitType = marketFile[i][6]; @@ -541,10 +541,10 @@ line1 = 'Open Position'; } - if (record.lastTradeROI < 0) { - line2 = 'ROI:' + (record.lastTradeROI).toFixed(2) + ' %'; + if (record.record.variable_last_position_ROI < 0) { + line2 = 'ROI:' + (record.record.variable_last_position_ROI).toFixed(2) + ' %'; } else { - line2 = 'ROI:' + (record.lastTradeROI).toFixed(2) + ' %'; + line2 = 'ROI:' + (record.record.variable_last_position_ROI).toFixed(2) + ' %'; } /* Draw the triangle that represents the trade. */ @@ -559,7 +559,7 @@ let opacity = '0.25'; - if (record.lastTradeROI > 0) { + if (record.record.variable_last_position_ROI > 0) { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')'; } else { diff --git a/TradingSimulation.js b/TradingSimulation.js index da7c86a33..656e7d593 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -353,21 +353,21 @@ record.begin = dailyFile[i][0]; record.end = dailyFile[i][1]; - record.balanceBaseAsset = dailyFile[i][2]; - record.balanceQuotedAsset = dailyFile[i][3]; - record.accumulatedProfitLoss = dailyFile[i][4]; - record.lastTradeProfitLoss = dailyFile[i][5]; - record.stopLoss = dailyFile[i][6]; - record.tradesCount = dailyFile[i][7]; - record.hits = dailyFile[i][8]; - record.fails = dailyFile[i][9]; - record.hitRatio = dailyFile[i][10]; - record.ROI = dailyFile[i][11]; - record.periods = dailyFile[i][12]; - record.days = dailyFile[i][13]; - record.anualizedRateOfReturn = dailyFile[i][14]; - record.sellRate = dailyFile[i][15]; - record.lastTradeROI = dailyFile[i][16]; + record.variable_current_balance_baseAsset = dailyFile[i][2]; + record.variable_current_balance_quotedAsset = dailyFile[i][3]; + record.variable_episode_stat_profitLoss = dailyFile[i][4]; + record.variable_last_position_profitLoss = dailyFile[i][5]; + record.variable_current_position_stopLoss_value = dailyFile[i][6]; + record.variable_episode_count_positions = dailyFile[i][7]; + record.variable_episode_count_hits = dailyFile[i][8]; + record.variable_episode_count_fails = dailyFile[i][9]; + record.variable_episode_stat_hitRatio = dailyFile[i][10]; + record.variable_episode_stat_ROI = dailyFile[i][11]; + record.variable_episode_count_periods = dailyFile[i][12]; + record.variable_episode_stat_days = dailyFile[i][13]; + record.variable_episode_stat_anualizedRateOfReturn = dailyFile[i][14]; + record.record.variable_current_position_rate = dailyFile[i][15]; + record.record.variable_last_position_ROI = dailyFile[i][16]; record.strategy = dailyFile[i][17]; record.takeProfit = dailyFile[i][18]; record.stopLossPhase = dailyFile[i][19]; @@ -443,21 +443,21 @@ record.begin = marketFile[i][0]; record.end = marketFile[i][1]; - record.balanceBaseAsset = marketFile[i][2]; - record.balanceQuotedAsset = marketFile[i][3]; - record.accumulatedProfitLoss = marketFile[i][4]; - record.lastTradeProfitLoss = marketFile[i][5]; - record.stopLoss = marketFile[i][6]; - record.tradesCount = marketFile[i][7]; - record.hits = marketFile[i][8]; - record.fails = marketFile[i][9]; - record.hitRatio = marketFile[i][10]; - record.ROI = marketFile[i][11]; - record.periods = marketFile[i][12]; - record.days = marketFile[i][13]; - record.anualizedRateOfReturn = marketFile[i][14]; - record.sellRate = marketFile[i][15]; - record.lastTradeROI = marketFile[i][16]; + record.variable_current_balance_baseAsset = marketFile[i][2]; + record.variable_current_balance_quotedAsset = marketFile[i][3]; + record.variable_episode_stat_profitLoss = marketFile[i][4]; + record.variable_last_position_profitLoss = marketFile[i][5]; + record.variable_current_position_stopLoss_value = marketFile[i][6]; + record.variable_episode_count_positions = marketFile[i][7]; + record.variable_episode_count_hits = marketFile[i][8]; + record.variable_episode_count_fails = marketFile[i][9]; + record.variable_episode_stat_hitRatio = marketFile[i][10]; + record.variable_episode_stat_ROI = marketFile[i][11]; + record.variable_episode_count_periods = marketFile[i][12]; + record.variable_episode_stat_days = marketFile[i][13]; + record.variable_episode_stat_anualizedRateOfReturn = marketFile[i][14]; + record.record.variable_current_position_rate = marketFile[i][15]; + record.record.variable_last_position_ROI = marketFile[i][16]; record.strategy = marketFile[i][17]; record.takeProfit = marketFile[i][18]; record.stopLossPhase = marketFile[i][19]; @@ -513,8 +513,8 @@ record = records[i]; /* Contributing to Auto-Scale*/ - if (record.stopLoss !== 0) { - coordinateSystem.reportYValue(record.stopLoss) + if (record.variable_current_position_stopLoss_value !== 0) { + coordinateSystem.reportYValue(record.variable_current_position_stopLoss_value) } if (record.takeProfit !== 0) { coordinateSystem.reportYValue(record.takeProfit) @@ -565,15 +565,15 @@ let recordPoint5 = { x: record.begin, - y: record.stopLoss + y: record.variable_current_position_stopLoss_value }; let recordPoint6 = { x: record.end, - y: record.stopLoss + y: record.variable_current_position_stopLoss_value }; - if (record.stopLoss === 0) { // Put these points out of range if stopLoss is zero. + if (record.variable_current_position_stopLoss_value === 0) { // Put these points out of range if stopLoss is zero. recordPoint5.x = 0; recordPoint6.x = 0; @@ -581,15 +581,15 @@ let recordPoint7 = { x: record.begin, - y: record.sellRate + y: record.record.variable_current_position_rate }; let recordPoint8 = { x: record.end, - y: record.sellRate + y: record.record.variable_current_position_rate }; - if (record.sellRate === 0) { // Put these points out of range if sellRate is zero. + if (record.record.variable_current_position_rate === 0) { // Put these points out of range if sellRate is zero. recordPoint7.x = 0; recordPoint8.x = 0; @@ -662,7 +662,7 @@ y: -30 } let imageSize = (recordPoint2.x - recordPoint1.x) / 2; - let recordLabel = record.periods.toLocaleString() + let recordLabel = record.variable_episode_count_periods.toLocaleString() if (imageSize < 8) { if (recordLabel[recordLabel.length - 1] !== '0' || imageSize < 4) recordLabel = '' @@ -723,7 +723,7 @@ /* Depending on what is on top, it is also the text and image of the take accumulatedProfitLoss / stop loss */ let yOffset = 0 - if (record.takeProfit > record.stopLoss) { yOffset = imageSize * 2 } + if (record.takeProfit > record.variable_current_position_stopLoss_value) { yOffset = imageSize * 2 } /* Next we are drawing the stopLoss floor / ceilling */ diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index 90dd81025..609f8df78 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -156,7 +156,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul if (record.baseAsset === record.marketBaseAsset) { params = {} - params.VALUE = record.balanceBaseAsset; + params.VALUE = record.variable_current_balance_baseAsset; params.INIT_VALUE = record.initialBalanceA params.MIN_VALUE = record.minimunBalanceA params.MAX_VALUE = record.maximunBalanceA @@ -170,7 +170,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul paramsArray.push(params) params = {} - params.VALUE = record.balanceQuotedAsset; + params.VALUE = record.variable_current_balance_quotedAsset; params.MIN_VALUE = record.minimunBalanceB params.INIT_VALUE = record.initialBalanceB params.MAX_VALUE = record.maximunBalanceB @@ -184,7 +184,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul paramsArray.push(params) } else { params = {} - params.VALUE = record.balanceQuotedAsset; + params.VALUE = record.variable_current_balance_quotedAsset; params.INIT_VALUE = record.initialBalanceB params.MIN_VALUE = record.minimunBalanceB params.MAX_VALUE = record.maximunBalanceB @@ -198,7 +198,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul paramsArray.push(params) params = {} - params.VALUE = record.balanceBaseAsset; + params.VALUE = record.variable_current_balance_baseAsset; params.MIN_VALUE = record.minimunBalanceA params.INIT_VALUE = record.initialBalanceA params.MAX_VALUE = record.maximunBalanceA diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js index 1856c69d9..24a6e90b6 100644 --- a/TradingSimulationCurrentPositionPanel.js +++ b/TradingSimulationCurrentPositionPanel.js @@ -138,12 +138,12 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.sellRate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.record.variable_current_position_rate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.stopLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_current_position_stopLoss_value, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); @@ -167,12 +167,12 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((record.lastTradeProfitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.variable_last_position_profitLoss), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((record.lastTradeROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.record.variable_last_position_ROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); } } diff --git a/TradingSimulationPartialResultsPanel.js b/TradingSimulationPartialResultsPanel.js index a6f50a3c5..d48d85a5c 100644 --- a/TradingSimulationPartialResultsPanel.js +++ b/TradingSimulationPartialResultsPanel.js @@ -131,47 +131,47 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.accumulatedProfitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_episode_stat_profitLoss, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Trades', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.tradesCount, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_episode_count_positions, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Hits', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_episode_count_hits, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Fails', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_episode_count_fails, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Hit Ratio', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((record.hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.variable_episode_stat_hitRatio * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((record.ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.variable_episode_stat_ROI * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_episode_count_periods, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_episode_stat_days, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Anualized Rate of Return', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((record.anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.variable_episode_stat_anualizedRateOfReturn * 100).toFixed(2) + ' %', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); } } From c250615574c91f18aee57a24495c54695fdfa867 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 21 May 2020 10:00:27 +0200 Subject: [PATCH 154/157] Refactoring Simulation record done --- Conditions.js | 32 ++++---- Trades.js | 12 +-- TradingSimulation.js | 99 ++++++++++++------------ TradingSimulationAssetBalancesPanel.js | 44 +++++------ TradingSimulationCurrentPositionPanel.js | 12 +-- 5 files changed, 99 insertions(+), 100 deletions(-) diff --git a/Conditions.js b/Conditions.js index 0ef615f9d..4471f523a 100644 --- a/Conditions.js +++ b/Conditions.js @@ -375,8 +375,8 @@ record.begin = dailyFile[1][i][0]; record.end = dailyFile[1][i][1]; record.strategyIndex = dailyFile[1][i][2]; - record.stopLossPhase = dailyFile[1][i][3]; - record.takeProfitPhase = dailyFile[1][i][4]; + record.variable_current_position_stopLoss_phase = dailyFile[1][i][3]; + record.variable_current_position_takeProfit_phase = dailyFile[1][i][4]; record.conditions = dailyFile[1][i][5]; record.formulaErrors = dailyFile[1][i][6]; record.formulaValues = dailyFile[1][i][7]; @@ -446,8 +446,8 @@ record.begin = marketFile[1][i][0]; record.end = marketFile[1][i][1]; record.strategyIndex = marketFile[1][i][2]; - record.stopLossPhase = marketFile[1][i][3]; - record.takeProfitPhase = marketFile[1][i][4]; + record.variable_current_position_stopLoss_phase = marketFile[1][i][3]; + record.variable_current_position_takeProfit_phase = marketFile[1][i][4]; record.conditions = marketFile[1][i][5]; record.formulaErrors = marketFile[1][i][6]; record.formulaValues = marketFile[1][i][7]; @@ -650,7 +650,7 @@ for (let p = 0; p < initialDefinition.stopLoss.phases.length; p++) { - if (record.strategyIndex === j && record.stopLossPhase === p) { + if (record.strategyIndex === j && record.variable_current_position_stopLoss_phase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -663,13 +663,13 @@ designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.stopLoss.phases[p].formula.error) if (record.formulaErrors[formulaErrorsIndex] !== "") { - if (record.strategyIndex === j && record.stopLossPhase === p) { + if (record.strategyIndex === j && record.variable_current_position_stopLoss_phase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(record.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (record.strategyIndex === j && record.stopLossPhase === p) { + if (record.strategyIndex === j && record.variable_current_position_stopLoss_phase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.stopLoss.phases[p].formula.payload.uiObject.setValue(record.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -735,7 +735,7 @@ for (let p = 0; p < initialDefinition.takeProfit.phases.length; p++) { - if (record.strategyIndex === j && record.takeProfitPhase === p) { + if (record.strategyIndex === j && record.variable_current_position_takeProfit_phase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -748,13 +748,13 @@ designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(openStage.initialDefinition.takeProfit.phases[p].formula.error) if (record.formulaErrors[formulaErrorsIndex] !== "") { - if (record.strategyIndex === j && record.takeProfitPhase === p) { + if (record.strategyIndex === j && record.variable_current_position_takeProfit_phase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(record.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (record.strategyIndex === j && record.takeProfitPhase === p) { + if (record.strategyIndex === j && record.variable_current_position_takeProfit_phase === p) { designerTradingSystem.strategies[j].openStage.initialDefinition.takeProfit.phases[p].formula.payload.uiObject.setValue(record.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -833,7 +833,7 @@ for (let p = 0; p < manageStage.stopLoss.phases.length; p++) { - if (record.strategyIndex === j && record.stopLossPhase - 1 === p) { + if (record.strategyIndex === j && record.variable_current_position_stopLoss_phase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].payload.uiObject.isExecuting = false @@ -846,12 +846,12 @@ designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.stopLoss.phases[p].formula.error) if (record.formulaErrors[formulaErrorsIndex] !== "") { - if (record.strategyIndex === j && record.stopLossPhase - 1 === p) { + if (record.strategyIndex === j && record.variable_current_position_stopLoss_phase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setErrorMessage(record.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (record.strategyIndex === j && record.stopLossPhase - 1 === p) { + if (record.strategyIndex === j && record.variable_current_position_stopLoss_phase - 1 === p) { designerTradingSystem.strategies[j].manageStage.stopLoss.phases[p].formula.payload.uiObject.setValue(record.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ @@ -917,7 +917,7 @@ for (let p = 0; p < manageStage.takeProfit.phases.length; p++) { - if (record.strategyIndex === j && record.takeProfitPhase - 1 === p) { + if (record.strategyIndex === j && record.variable_current_position_takeProfit_phase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = true } else { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].payload.uiObject.isExecuting = false @@ -930,13 +930,13 @@ designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(manageStage.takeProfit.phases[p].formula.error) if (record.formulaErrors[formulaErrorsIndex] !== "") { - if (record.strategyIndex === j && record.takeProfitPhase - 1 === p) { + if (record.strategyIndex === j && record.variable_current_position_takeProfit_phase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setErrorMessage(record.formulaErrors[formulaErrorsIndex]) } } formulaErrorsIndex++ - if (record.strategyIndex === j && record.takeProfitPhase - 1 === p) { + if (record.strategyIndex === j && record.variable_current_position_takeProfit_phase - 1 === p) { designerTradingSystem.strategies[j].manageStage.takeProfit.phases[p].formula.payload.uiObject.setValue(record.formulaValues[formulaValuesIndex]) } formulaValuesIndex++ diff --git a/Trades.js b/Trades.js index c446e64fd..b7f21036e 100644 --- a/Trades.js +++ b/Trades.js @@ -366,7 +366,7 @@ record.begin = dailyFile[i][0]; record.end = dailyFile[i][1]; record.status = dailyFile[i][2]; - record.record.variable_last_position_ROI = dailyFile[i][3]; + record.variable_last_position_ROI = dailyFile[i][3]; record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; record.exitType = dailyFile[i][6]; @@ -432,7 +432,7 @@ record.begin = marketFile[i][0]; record.end = marketFile[i][1]; record.status = marketFile[i][2]; - record.record.variable_last_position_ROI = marketFile[i][3]; + record.variable_last_position_ROI = marketFile[i][3]; record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; record.exitType = marketFile[i][6]; @@ -541,10 +541,10 @@ line1 = 'Open Position'; } - if (record.record.variable_last_position_ROI < 0) { - line2 = 'ROI:' + (record.record.variable_last_position_ROI).toFixed(2) + ' %'; + if (record.variable_last_position_ROI < 0) { + line2 = 'ROI:' + (record.variable_last_position_ROI).toFixed(2) + ' %'; } else { - line2 = 'ROI:' + (record.record.variable_last_position_ROI).toFixed(2) + ' %'; + line2 = 'ROI:' + (record.variable_last_position_ROI).toFixed(2) + ' %'; } /* Draw the triangle that represents the trade. */ @@ -559,7 +559,7 @@ let opacity = '0.25'; - if (record.record.variable_last_position_ROI > 0) { + if (record.variable_last_position_ROI > 0) { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')'; browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')'; } else { diff --git a/TradingSimulation.js b/TradingSimulation.js index 656e7d593..bc72d9c0d 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -366,25 +366,25 @@ record.variable_episode_count_periods = dailyFile[i][12]; record.variable_episode_stat_days = dailyFile[i][13]; record.variable_episode_stat_anualizedRateOfReturn = dailyFile[i][14]; - record.record.variable_current_position_rate = dailyFile[i][15]; - record.record.variable_last_position_ROI = dailyFile[i][16]; + record.variable_current_position_rate = dailyFile[i][15]; + record.variable_last_position_ROI = dailyFile[i][16]; record.strategy = dailyFile[i][17]; - record.takeProfit = dailyFile[i][18]; - record.stopLossPhase = dailyFile[i][19]; - record.takeProfitPhase = dailyFile[i][20]; - record.positionSize = dailyFile[i][21]; // 25 is the message for the executor - record.initialBalanceA = dailyFile[i][22]; - record.minimunBalanceA = dailyFile[i][23]; - record.maximunBalanceA = dailyFile[i][24]; - record.initialBalanceB = dailyFile[i][25]; - record.minimunBalanceB = dailyFile[i][26]; - record.maximunBalanceB = dailyFile[i][27]; - record.baseAsset = dailyFile[i][28]; - record.quotedAsset = dailyFile[i][29]; - record.marketBaseAsset = dailyFile[i][30]; - record.marketQuotedAsset = dailyFile[i][31]; - record.positionPeriods = dailyFile[i][32]; - record.positionDays = dailyFile[i][33]; + record.variable_current_position_takeProfit_value = dailyFile[i][18]; + record.variable_current_position_stopLoss_phase = dailyFile[i][19]; + record.variable_current_position_takeProfit_phase = dailyFile[i][20]; + record.variable_current_position_size = dailyFile[i][21]; // 25 is the message for the executor + record.variable_episode_parameters_initial_balance_baseAsset = dailyFile[i][22]; + record.variable_episode_parameters_minimum_balance_baseAsset = dailyFile[i][23]; + record.variable_episode_parameters_maximum_balance_baseAsset = dailyFile[i][24]; + record.variable_episode_parameters_initial_balance_quotedAsset = dailyFile[i][25]; + record.variable_episode_parameters_minimum_balance_quotedAsset = dailyFile[i][26]; + record.variable_episode_parameters_maximum_balance_quotedAsset = dailyFile[i][27]; + record.variable_episode_parameters_baseAsset = dailyFile[i][28]; + record.variable_episode_parameters_quotedAsset = dailyFile[i][29]; + record.variable_episode_parameters_marketBaseAsset = dailyFile[i][30]; + record.variable_episode_parameters_marketQuotedAsset = dailyFile[i][31]; + record.variable_current_position_count_periods = dailyFile[i][32]; + record.variable_current_position_stat_days = dailyFile[i][33]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -456,25 +456,24 @@ record.variable_episode_count_periods = marketFile[i][12]; record.variable_episode_stat_days = marketFile[i][13]; record.variable_episode_stat_anualizedRateOfReturn = marketFile[i][14]; - record.record.variable_current_position_rate = marketFile[i][15]; - record.record.variable_last_position_ROI = marketFile[i][16]; - record.strategy = marketFile[i][17]; - record.takeProfit = marketFile[i][18]; - record.stopLossPhase = marketFile[i][19]; - record.takeProfitPhase = marketFile[i][20]; - record.positionSize = marketFile[i][21]; - record.initialBalanceA = marketFile[i][22]; - record.minimunBalanceA = marketFile[i][23]; - record.maximunBalanceA = marketFile[i][24]; - record.initialBalanceB = marketFile[i][25]; - record.minimunBalanceB = marketFile[i][26]; - record.maximunBalanceB = marketFile[i][27]; - record.baseAsset = marketFile[i][28]; - record.quotedAsset = marketFile[i][29]; - record.marketBaseAsset = marketFile[i][30]; - record.marketQuotedAsset = marketFile[i][31]; - record.positionPeriods = marketFile[i][32]; - record.positionDays = marketFile[i][33]; + record.variable_current_position_rate = marketFile[i][15]; + record.variable_last_position_ROI = marketFile[i][16]; + record.variable_current_position_takeProfit_value = marketFile[i][17]; + record.variable_current_position_stopLoss_phase = marketFile[i][18]; + record.variable_current_position_takeProfit_phase = marketFile[i][19]; + record.variable_current_position_size = marketFile[i][20]; + record.variable_episode_parameters_initial_balance_baseAsset = marketFile[i][21]; + record.variable_episode_parameters_minimum_balance_baseAsset = marketFile[i][22]; + record.variable_episode_parameters_maximum_balance_baseAsset = marketFile[i][23]; + record.variable_episode_parameters_initial_balance_quotedAsset = marketFile[i][24]; + record.variable_episode_parameters_minimum_balance_quotedAsset = marketFile[i][25]; + record.variable_episode_parameters_maximum_balance_quotedAsset = marketFile[i][26]; + record.variable_episode_parameters_baseAsset = marketFile[i][27]; + record.variable_episode_parameters_quotedAsset = marketFile[i][28]; + record.variable_episode_parameters_marketBaseAsset = marketFile[i][29]; + record.variable_episode_parameters_marketQuotedAsset = marketFile[i][30]; + record.variable_current_position_count_periods = marketFile[i][31]; + record.variable_current_position_stat_days = marketFile[i][32]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && @@ -516,8 +515,8 @@ if (record.variable_current_position_stopLoss_value !== 0) { coordinateSystem.reportYValue(record.variable_current_position_stopLoss_value) } - if (record.takeProfit !== 0) { - coordinateSystem.reportYValue(record.takeProfit) + if (record.variable_current_position_takeProfit_value !== 0) { + coordinateSystem.reportYValue(record.variable_current_position_takeProfit_value) } /* Send the current record to the panel */ @@ -534,12 +533,12 @@ let takeProfitPhase = -1; if (i > 0) { - if (record.stopLossPhase !== records[i - 1].stopLossPhase) { - stopLossPhase = record.stopLossPhase; + if (record.variable_current_position_stopLoss_phase !== records[i - 1].stopLossPhase) { + stopLossPhase = record.variable_current_position_stopLoss_phase; } - if (record.takeProfitPhase !== records[i - 1].takeProfitPhase) { - takeProfitPhase = record.takeProfitPhase; + if (record.variable_current_position_takeProfit_phase !== records[i - 1].takeProfitPhase) { + takeProfitPhase = record.variable_current_position_takeProfit_phase; } } @@ -581,15 +580,15 @@ let recordPoint7 = { x: record.begin, - y: record.record.variable_current_position_rate + y: record.variable_current_position_rate }; let recordPoint8 = { x: record.end, - y: record.record.variable_current_position_rate + y: record.variable_current_position_rate }; - if (record.record.variable_current_position_rate === 0) { // Put these points out of range if sellRate is zero. + if (record.variable_current_position_rate === 0) { // Put these points out of range if sellRate is zero. recordPoint7.x = 0; recordPoint8.x = 0; @@ -597,15 +596,15 @@ let recordPoint9 = { x: record.begin, - y: record.takeProfit + y: record.variable_current_position_takeProfit_value }; let recordPoint10 = { x: record.end, - y: record.takeProfit + y: record.variable_current_position_takeProfit_value }; - if (record.takeProfit === 0) { // Put these points out of range if takeProfit is zero. + if (record.variable_current_position_takeProfit_value === 0) { // Put these points out of range if takeProfit is zero. recordPoint9.x = 0; recordPoint10.x = 0; @@ -723,7 +722,7 @@ /* Depending on what is on top, it is also the text and image of the take accumulatedProfitLoss / stop loss */ let yOffset = 0 - if (record.takeProfit > record.variable_current_position_stopLoss_value) { yOffset = imageSize * 2 } + if (record.variable_current_position_takeProfit_value > record.variable_current_position_stopLoss_value) { yOffset = imageSize * 2 } /* Next we are drawing the stopLoss floor / ceilling */ diff --git a/TradingSimulationAssetBalancesPanel.js b/TradingSimulationAssetBalancesPanel.js index 609f8df78..6ff7fc997 100644 --- a/TradingSimulationAssetBalancesPanel.js +++ b/TradingSimulationAssetBalancesPanel.js @@ -139,7 +139,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul let paramsArray = [] let positionTaken = false - if (record.positionSize > 0) { + if (record.variable_current_position_size > 0) { positionTaken = true } @@ -154,59 +154,59 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul return } - if (record.baseAsset === record.marketBaseAsset) { + if (record.variable_episode_parameters_baseAsset === record.variable_episode_parameters_marketBaseAsset) { params = {} params.VALUE = record.variable_current_balance_baseAsset; - params.INIT_VALUE = record.initialBalanceA - params.MIN_VALUE = record.minimunBalanceA - params.MAX_VALUE = record.maximunBalanceA + params.INIT_VALUE = record.variable_episode_parameters_initial_balance_baseAsset + params.MIN_VALUE = record.variable_episode_parameters_minimum_balance_baseAsset + params.MAX_VALUE = record.variable_episode_parameters_maximum_balance_baseAsset params.ASSET_LABEL = 'Base' - params.ASSET_NAME = record.baseAsset + params.ASSET_NAME = record.variable_episode_parameters_baseAsset params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = record.baseAsset + params.BASE_ASSET = record.variable_episode_parameters_baseAsset params.DECIMALS = 4 paramsArray.push(params) params = {} params.VALUE = record.variable_current_balance_quotedAsset; - params.MIN_VALUE = record.minimunBalanceB - params.INIT_VALUE = record.initialBalanceB - params.MAX_VALUE = record.maximunBalanceB + params.MIN_VALUE = record.variable_episode_parameters_minimum_balance_quotedAsset + params.INIT_VALUE = record.variable_episode_parameters_initial_balance_quotedAsset + params.MAX_VALUE = record.variable_episode_parameters_maximum_balance_quotedAsset params.ASSET_LABEL = 'Quoted' - params.ASSET_NAME = record.quotedAsset + params.ASSET_NAME = record.variable_episode_parameters_quotedAsset params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = record.baseAsset + params.BASE_ASSET = record.variable_episode_parameters_baseAsset params.DECIMALS = 2 paramsArray.push(params) } else { params = {} params.VALUE = record.variable_current_balance_quotedAsset; - params.INIT_VALUE = record.initialBalanceB - params.MIN_VALUE = record.minimunBalanceB - params.MAX_VALUE = record.maximunBalanceB + params.INIT_VALUE = record.variable_episode_parameters_initial_balance_quotedAsset + params.MIN_VALUE = record.variable_episode_parameters_minimum_balance_quotedAsset + params.MAX_VALUE = record.variable_episode_parameters_maximum_balance_quotedAsset params.ASSET_LABEL = 'Base' - params.ASSET_NAME = record.baseAsset + params.ASSET_NAME = record.variable_episode_parameters_baseAsset params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = record.baseAsset + params.BASE_ASSET = record.variable_episode_parameters_baseAsset params.DECIMALS = 4 paramsArray.push(params) params = {} params.VALUE = record.variable_current_balance_baseAsset; - params.MIN_VALUE = record.minimunBalanceA - params.INIT_VALUE = record.initialBalanceA - params.MAX_VALUE = record.maximunBalanceA + params.MIN_VALUE = record.variable_episode_parameters_minimum_balance_baseAsset + params.INIT_VALUE = record.variable_episode_parameters_initial_balance_baseAsset + params.MAX_VALUE = record.variable_episode_parameters_maximum_balance_baseAsset params.ASSET_LABEL = 'Quoted' - params.ASSET_NAME = record.quotedAsset + params.ASSET_NAME = record.variable_episode_parameters_quotedAsset params.LEFT_OFFSET = X_AXIS params.POSITION_TAKEN = positionTaken - params.BASE_ASSET = record.baseAsset + params.BASE_ASSET = record.variable_episode_parameters_baseAsset params.DECIMALS = 2 paramsArray.push(params) diff --git a/TradingSimulationCurrentPositionPanel.js b/TradingSimulationCurrentPositionPanel.js index 24a6e90b6..d3f7c9fbc 100644 --- a/TradingSimulationCurrentPositionPanel.js +++ b/TradingSimulationCurrentPositionPanel.js @@ -133,12 +133,12 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Size', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.positionSize, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_current_position_size, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Rate', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.record.variable_current_position_rate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_current_position_rate, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Stop', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); @@ -148,17 +148,17 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('Take Profit', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel(record.takeProfit, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(record.variable_current_position_takeProfit_value, X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((record.positionPeriods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.variable_current_position_count_periods), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Days', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((record.positionDays).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.variable_current_position_stat_days).toFixed(2), X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; y = y + increment; @@ -172,7 +172,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; printLabel('ROI', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; - printLabel((record.record.variable_last_position_ROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel((record.variable_last_position_ROI).toFixed(2) + ' % ', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); } } From b14b69b53e922eba2ab31989ce5f9dfe0cbf3503 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 21 May 2020 10:42:02 +0200 Subject: [PATCH 155/157] Episode --- Project.njsproj | 2 +- Strategies.js | 8 ++++---- Trades.js | 6 +++--- ...ialResultsPanel.js => TradingSimulationEpisodePanel.js | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) rename TradingSimulationPartialResultsPanel.js => TradingSimulationEpisodePanel.js (96%) diff --git a/Project.njsproj b/Project.njsproj index 1b64cc95b..e7eadcb92 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -37,7 +37,7 @@ Code - + diff --git a/Strategies.js b/Strategies.js index c793f07ec..34b0c28ea 100644 --- a/Strategies.js +++ b/Strategies.js @@ -383,7 +383,7 @@ record.number = dailyFile[i][3]; record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; - record.triggerOnSituation = dailyFile[i][6]; + record.situationName = dailyFile[i][6]; record.name = dailyFile[i][7]; if ( @@ -456,7 +456,7 @@ record.number = marketFile[i][3]; record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; - record.triggerOnSituation = marketFile[i][6]; + record.situationName = marketFile[i][6]; record.name = marketFile[i][7]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -588,8 +588,8 @@ if (record.name !== "New Strategy") { printLabel(record.name, recordPoint1.x + 5, positionY - 15, '1', 12); } - if (record.triggerOnSituation !== "New Situation") { - printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); + if (record.situationName !== "New Situation") { + printLabel(record.situationName, recordPoint1.x + 5, positionY, '1', 12); } } diff --git a/Trades.js b/Trades.js index b7f21036e..cad27fe7c 100644 --- a/Trades.js +++ b/Trades.js @@ -370,7 +370,7 @@ record.beginRate = dailyFile[i][4]; record.endRate = dailyFile[i][5]; record.exitType = dailyFile[i][6]; - record.takePositionSituation = dailyFile[i][7]; + record.situationName = dailyFile[i][7]; if ( (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) && @@ -436,7 +436,7 @@ record.beginRate = marketFile[i][4]; record.endRate = marketFile[i][5]; record.exitType = marketFile[i][6]; - record.takePositionSituation = marketFile[i][7]; + record.situationName = marketFile[i][7]; if ( (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) && @@ -518,7 +518,7 @@ recordPoint2 = thisObject.fitFunction(recordPoint2); recordPoint3 = thisObject.fitFunction(recordPoint3); - let line0 = record.takePositionSituation + let line0 = record.situationName let line1 = ''; let line2 = ''; diff --git a/TradingSimulationPartialResultsPanel.js b/TradingSimulationEpisodePanel.js similarity index 96% rename from TradingSimulationPartialResultsPanel.js rename to TradingSimulationEpisodePanel.js index d48d85a5c..e1530d7cf 100644 --- a/TradingSimulationPartialResultsPanel.js +++ b/TradingSimulationEpisodePanel.js @@ -1,5 +1,5 @@  -function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimulationPartialResultsPanel() { +function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimulationEpisodePanel() { let thisObject = { fitFunction: undefined, @@ -17,7 +17,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul container.initialize(); thisObject.container = container; - container.frame.containerName = "Simulation Partial Results Panel"; + container.frame.containerName = "Simulation Episode Panel"; let record; let lastRecord; @@ -126,7 +126,7 @@ function newTradingEnginesPlottersTradingSimulationTradingSimulationTradingSimul y = y + increment; y = y + increment; - printLabel('Partial Results', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel('Episode', X_AXIS, frameTitleHeight + frameBodyHeight * y, '1.00', 14, undefined, true, thisObject.container, thisObject.fitFunction); y = y + increment; printLabel('Profit / Loss', X_AXIS, frameTitleHeight + frameBodyHeight * y, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); From 96fd7e2a1d2ffda61087f138b40711f850756025 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 21 May 2020 13:50:57 +0200 Subject: [PATCH 156/157] all good --- Conditions.js | 4 ++-- TradingSimulation.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Conditions.js b/Conditions.js index 4471f523a..1d932cf6e 100644 --- a/Conditions.js +++ b/Conditions.js @@ -495,8 +495,8 @@ let record = { conditionsNames: headers, strategyIndex: conditionRecord.strategyIndex, - stopLossPhase: conditionRecord.stopLossPhase, - takeProfitPhase: conditionRecord.takeProfitPhase, + variable_current_position_stopLoss_phase: conditionRecord.variable_current_position_stopLoss_phase, + variable_current_position_takeProfit_phase: conditionRecord.variable_current_position_takeProfit_phase, conditionsValues: conditionRecord.conditions, formulaErrors: conditionRecord.formulaErrors, formulaValues: conditionRecord.formulaValues diff --git a/TradingSimulation.js b/TradingSimulation.js index bc72d9c0d..629e9c8c1 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -533,11 +533,11 @@ let takeProfitPhase = -1; if (i > 0) { - if (record.variable_current_position_stopLoss_phase !== records[i - 1].stopLossPhase) { + if (record.variable_current_position_stopLoss_phase !== records[i - 1].variable_current_position_stopLoss_phase) { stopLossPhase = record.variable_current_position_stopLoss_phase; } - if (record.variable_current_position_takeProfit_phase !== records[i - 1].takeProfitPhase) { + if (record.variable_current_position_takeProfit_phase !== records[i - 1].variable_current_position_takeProfit_phase) { takeProfitPhase = record.variable_current_position_takeProfit_phase; } } From ae17e25d5bcde90ab136a9b516335c385e17a30c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 23 May 2020 16:38:38 +0200 Subject: [PATCH 157/157] desambiguation --- TradingSimulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 629e9c8c1..52b8d4704 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -149,7 +149,7 @@ /* Loading a few icons */ - imageStopLossPhase = canvas.designSpace.iconByUiObjectType.get('Stop'); + imageStopLossPhase = canvas.designSpace.iconByUiObjectType.get('Managed Stop Loss'); imageTakeProfitPhase = canvas.designSpace.iconByUiObjectType.get('Phase'); imageRecord = canvas.designSpace.iconByUiObjectType.get('Trading System');