Kind of game: a car drives along the lane from left to right

Auftrag beendet

Ausführungszeit 1 Tag
Bewertung des Entwicklers
Good job !
Bewertung des Kunden
Very, very pleased! Super fast, correct, cooperative, coming with his own, better solutions ...

Spezifikation

The idea

The idea of what I want has nothing to do with trading!!! Imagine more of a game ;)

Of course, I want the complete source code, only MQL5.


Final result

I want a graphical car object as a single MQL5-class that ‘drives’ from the first bar on the left to the last bar on the right of the given artificial quotes manageable by the 6 buttons: Hold, Continue, Faster, Slower, Restart, Stop (see below).

Steering right or left (up or down on the chart) is neither needed nor part of the my order, the car drives always from left to right and restarts again at the left edge.

The ‚program‘ should be a MQL5-Script with at least these input variables:
input double dMultSpeed = 1.0; // try & check for a reasonable diplayed Speed value
input int iFaster = 10; // percent to speed up the car
input int iSlower = 10; // percent to slow down the car
input int iLocation = 40; // between high and low of the 1st bar:low+(high-low)*0.01*iLocation
input datetime tBarFirst = D’2024.01.08 00:00:00’; // to have an easy access
input datetime tBarLast = D’2024.01.08 23:59:00’; // to have an easy access
input int iFixStepFwd = 5; // in the constr.: this.dStepLenSec = (datetime) iFixStepFwd;



I want a class of a graphical ‚car‘ object like this (the white cross does not have to be drawn or visible and the sizes, distances and relations of the image here don’t have to be necessarily the same):



The individual properties of this ‘car’ has to be organized in a private struct with at least these property values (not complete), you may name them differently:

    @page { size: 21cm 29.7cm; margin: 2cm } p { line-height: 115%; margin-bottom: 0.25cm; background: transparent } a:visited { color: #800000; text-decoration: underline } a:link { color: #000080; text-decoration: underline }
    • tLength // datetime
    • dWidth // quote / price
    • iColor // color of the chassis and the tyres
    • … // the values of the tyres (size, place,..),
    • dVolume // (int)(tLength*60) * dWidth
    • dStartPoint // a price between hi & lo, (see below)
    • iMsec // int value of milliseconds for Sleep
    • tSpeed // dMultSpeed/iMsec – if speed 0 (Hold) => iMsec=INT_MAX
    • ...
These values of the car must be set at creation in the constructor method.

The wheels/tyres:

  • can have these relationships:
  • tyre width = 15% (adjustable) of the car width and
  • tyre length/diameter = 15% (adjustable) of car length
  • position a: 50% (adjustable) tyre width off the front/back and
  • b: 20% (adjustable) of the tyre width appart from the chassis of the car.


Methods of the car class:

  • The constructor draws and places the car on the ‘lane’ at first bar and a given point (price) between high and low of the first bar: low+(high-low)*0.01*iLocation.

    The ‘back’ of the ‘car’ has to be placed at the first bar’s open time.

  • driveCar() is a method in the car class that moves the center point (the cross of the diagonals) of the car forward by an endless loop unless the script is stopped by the button Stop (s. b.) then the de-constructor is called. The visible speed on the chart is the ‘chart-time-distanceseconds divided by real time. This is realised by Sleep(iMsec): the center of the car moves forward always a fix amount of chart-seconds dStepLenSec followed by Sleep(iMsec). The higher iMsec the slower the visible ‘speed’ of the ‘car’ on the chart – ok?

    Of course the shape of the car (chassis and tyres) stays the same! So after moving the center the cars has to be re-drawn at the new place starting from the new point where the car’s center is now.

  • decelCar(const int perCent) is a method that increases iMsec for Sleep(iMsec) by iMsec *= 0.01*perCent so that the visible speed of the car slows down. Don’t use iSlower directly in this method!

  • accelCar(const int perCent) is a method that decreases iMsec for Sleep(iMsec) by iMsec *= 1.01*perCent so that the visible speed of the car accelerates. Don’t use iFaster directly in this method!


Moving the car from left to right:

  1. The ‘car’ ‘drives’ from the first bar to the middle between the left and right edge of the chart, then

  2. if the ‘car’ is in the middle of the visible chart and drives on the chart is moved ‘under’ the ‘car’ to the left which can be seen by the moving tick volume of the bars. So the visible speed of the car results in the visible speed of the ‘lane’.

  3. if the last bar appears on the chart and so the chart cannot be shifted to the left anymore the car starts to move to the right edge of the visible chart.

  4. Now, if the front side of the car has reached the last bar, you might say bumped against the right edge (time value of the front of the ‘car’ >= its open_time + PeriodSeconds()) the ‘car’ & chart jumps’ to the first bar and the game starts again until either the stop button is pressed or the script is removed from the chart which means practically the same.


The lane:

This ‘car’ shall ‘drive’ (move) along the ‘lane’ build by the bodies of artificial quotes (between high and low) of the artificial Symbol Lane 00 Straight (attached as csv file)) on the chart between the first and the last bar of the artificial quotes (in the attached csv file: between 2024.01.08 00:00 and 2024.01.08 23:59).


The speed:

The visible speed on the chart is the ‘time-length’ divided by real-time which has to be realised by Sleep( iMsec): the center of the car moves forward always a fix amount of seconds (in ChartTime) followed by Sleep( iMsec). The higher iMsec the slower the car and vice versa – ok? The shape of the car stays always the same of course.


The buttons:

There should be 6 buttons to manipulate the car at the top right corner, two on top of each other, three next to each other, upper row: Hold,Faster, Restart, underneath: Continue, Slower, Stop

  1. Hold (temporarily), iMsec = INT_MAX, save actual value of iMsec in prev_value,

  2. Continue, iMsec= prev_value,

  3. Faster, calls accelCar(iF aster),

  4. Slower, calls decelCar(iSlower),

  5. Restart, the car restarts from the beginning

  6. Stop, scripts is ended


My formal preferences for classes, functions, and methods following:

https://www.youtube.com/watch?v=BiMGgaJJmr4

  • No code comments within functions and/or methods except the body is too long then please have a line that explains what is done by the next part of code.

  • At the top of any class should be the list of all methods.

  • Enums and its names should start with an € (see below) so that its (global) variable name could be almost the same like LogMode which denotes right away the enum €LogMode it refers to (see below).

  • Right above the declaration (so outside of the classes/func./meth.) there should be a comment block /* … */
    with
    firstly the descrpition what the class/function/method does, what is its purpose, then what it returns followed by the usage: bool ok = name(...) – easy to read, to understand, and to use by copy&paste&amend.

    Right after the declaration – its first lines - there is:

    #ifdef _DEBUG
            ifFunc Print(_trcAct);
    #endif

    and on global scope:

    #define _ifFunc if( WhatDebug>€DebgNO && WhatDebug % €DebugFunc == 0 )
    # define _trcAct ">> trc.Act >> ",__FILE__,"[",__LINE__,"] ",__FUNCTION__,"() ",_t2All(TimeCurrent())



    Here is an example of what I mean (check s the lot size, has nothing to do with this job!!) :

    /* get the symbol values of the broker and check whether the lots is allowed
        return the valid lot size, or 0. 0
        use: checkLots(lots); checkLots(lots, MyMaxVol); */
    double checkLots(double lts, const double myMaxVol=5.0)
    {
    #ifdef _DEBUG
            _ifFunc Print(_trcAct);
    #endif
            double VolMin = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN),
            VolMax = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX),
            ...
    


  • In Debugmode I want to be able to follow the sequence of functions calls (see above).
    For this I’
    d like have this in the global scope:

     enum € LogMode
    {
            €LogNO = 0, //
            €LogALL = 1, // log everything
            €LogFunc = 3, // _ifFunc log each call of the function to control the "flow"
    };
    int LogMode;
    
    #define _ifAll if( LogMode>€ LogNO ) // log everything
    #define _ifFunc if( LogMode>€LogNO && LogMode % €LogFunc == 0 )



    The idea is that the global variable LogMode is a multiplication of prime numbers
    (2,3,5,7,11,13,17,..) in OnInit(): LogMode = €LogFunc*€Log This *€Log That ;
    so that the €LogMode%€Log This logs the specific lines. E. g. if I want to see
    the sequence of function calls I enter
    ifFunc Print(_trcAct); (see above).

  • The name of the functions/method should follow the convention:
    - it begins with a verb or its abbreviation, such as check or calc,
    - followed by the subject being dealt with like: setTyres(..), decelCar(..), calcSpeed(..), ...

  • Index variables like i,k,m,.. accessing vectors, lists, matrices, etc. don’t need mnemonic names (but please don’t use the capital “i”: I and small “L”: l – they look too much the same).

  • Otherwise please use mnemonic names for the variables but keep it short, clear and crisp: I would prefer calc instead of calculate, accel instead of accelerate, ...

  • The names of the variables begin with a character identifying the type (except the index variables), here some examples:
    int iCount; double dPrice; datetime tTime; ulong uID; long lBigger. I think any other types are not needed.


A snapshot of the car on the lane with the place of the 6 buttons which don’t have to be exactly there
but of course with their descrition I was too lazy to enter Hold, Faster, Restart,..:




And here are the properties of the chart: https://www.mql5.com/ru/forum/1111/page3453#comment_51799408

(Even though the tick volume is not shown at the moment on this chart, the wave structure of the tick volume will show that the lane is moving under the car if the left and right edges are too far away.)

Attached is the file with 1-minutes bars for you to 'construct' the lane in the chart as artificial symbol "Lane 00 Straight" with 5 digits - more is not needed to define.






Dateien:

Bewerbungen

1
Entwickler 1
Bewertung
(320)
Projekte
466
42%
Schlichtung
77
12% / 64%
Frist nicht eingehalten
75
16%
Frei

Projektdetails

Budget
50 - 200 USD
MwSt (20%): 10 - 40 USD
Insgesamt: 60 - 240 USD
Für die Entwickler
45 - 180 USD
Ausführungsfristen
von 2 bis 10 Tag(e)