Coding Logic

Viewing 3 posts - 1 through 3 (of 3 total)
  • #11681

    Hi all,

    Can anyone explains the logic of the coding? I mean is how is the Code being executed? More details below:

    For example, if I would like to have an Automated system to monitor a particular stock, if it hits what I defined as “strategy”, it buy/sell for me.

    In the Backtesting and Automatic Trading area, under the programming I should put in my codes. But I’m a newbie for this platform. Hence, I need to know how is the code being executed.

    Q: Does it goes top down every line of code in assuming I set the TF to 1min?

    Q: How do I set some constants that I could use in my later part to compare values?

    Q: How do I initialize my variables ONCE only when starting the trade?

    Q: Does the code being run when the 1min starts or end of the 1min? This is important factor to calculate the PIPs and if we should open the position. (I don’t understand here and couldn’t find any documentations on it. Maybe I didn’t find hard enough whole day 🙂

    Sample logic:

    // Code to buy/sell when conditions meet.

    //  Below I declare some constants.

    Constant CAPITAL = 1000

    Constant IGSPREAD = 3

    Constant TPPIP = 30

    // Here define some variables and initialize ONLY once.

    BULL_FLAG = FALSE

    BEAR_FLAG = FALSE

    INRSI_FLAG = FALSE

    // Below is some logic testing to turn my flag on or off.

    if xxx = xxx then

    BULL_FLAG = TRUE

    end if.

    // Below will test the FLAGS and decide buy or wait.

    #11685

    The code is executed at the end of each bar/timeframe. It is at the end of the bar that you have the final data on open/close/high/low. So, unless you use limit orders, regular buy/sell orders are sent at the end of a bar, based on the code running on that bar, but the orders are executed at the open of the next bar. On lower timeframes, the difference between the open of this bar and the close of the previous bar is less of a concern, than it is on a higher timeframe.

    To set/initialize a variable once, you write ‘once’ before them. You can use this to make a constant too. Example: ONCE MySLRatio=3

    I recommend looking at a few examples. It helps seeing how different systems are constructed.

    #11742

    Hi Wing,

    thanks so much for your reply 🙂

    yup trying hard on it now.

    Any good links to have graphical info drawn to the chart examples?

    Too bad you are not in Singapore, else I sure ask you out for coffee!

    cheers!

Viewing 3 posts - 1 through 3 (of 3 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login