Implementation of complex trading scenarios, for back testing.....

Discussion in 'Automated Trading' started by MrAgi1, May 15, 2021.

  1. MrAgi1

    MrAgi1

    I have a trading idea, but I don't know how to execute it in python. I am not good at programming. I am trying to backtest my trading idea in PyCharm.

    Please can anyone explain how I can write the codes that meet certain conditions written below?
    First, I have to input certain parameters; the currency pair and a particular time. As an example: EURUSD and 9 AM EST.
    Next, I have to define constants; PipBlock=10 (i.e 10 pips), DAYCounter=30 (i.e 30 trading days), PassCounter=0, FailCounter=0. 30 minutes candlestick chart is used. The program always starts at the 9 AM EST candle every trading day and analyzes for the past 30 tradings days.

    It is important to know the meaning of the alphabet used in the trading scenarios below. The H means the high price of the current candle, O means the opening price of the first/initial candle, L means the low price of the current candle.

    NOTE: If is analyzing any candle, It should retain the "Open" value of the initial candle(i.e if the 9 AM Open candle value is 1.1250 when analyzing the 2 PM EST candle, the program replaces the open value of that 2 PM EST candle with 1.1250 for the calculations). However, the High and Low values of any candle would not be replaced by the high/low of the initial candle values.

    Now the logic for the trade has 4 possible scenarios:

    if (H-O>PipBlock and O-L<PipBlock)
    {PassCounter=PasCounter+1;}
    #Then move to the next trading day
    Explanation: The above is scenario 1, and it starts with the 9 AM candle. Then moves to the next 9 AM candle on the next day.

    if (H-O<PipBlock and O-L<PipBlock)
    #Move to the next candle, on the same trading day
    Explanation: The Above is scenario 2, start with the 9 AM candle, then move to the 9:30 AM candle.

    if (H-O<PipBlock and O-L>PipBlock)
    #Move to the next candle, on the same trading day
    Explanation: The Above is scenario 3, start with the 9 AM candle, then move to the 9:30 AM candle.

    if (H-O>PipBlock and O-L>PipBlock)
    #Move to the next candle, on the same trading day
    Explanation: The Above is scenario 4, start with the 9 AM candle, then move to the 9:30 AM candle.

    NOTE:
    If any of scenario 2, 3, or 4 occurs first and secondly scenario 2 keeps occurring the program would keep moving from candle to candle(i.e 9 AM, 9:30 AM, 10 AM, 10:30 AM e.t.c) until the end of the trading day 9 PM EST then FailCounter=FailCounter+1 and the analysis ends for that trading day and moves to another trading day.
    However, if scenario 3 or 4 occurs again at any time given that the first candle was any of scenarios 2, 3, or 4, then end the analysis immediately for that trading day and FailCounter=FailCounter+1, and move to another trading day.
    If scenario 1 occurs at any time given that the first candle was any of scenarios 2, 3, or 4, then end the analysis immediately for that trading day and PassCounter=PassCounter+1, and move to another trading day.

    Since DAYCounter is 30 days, once the program ends the analysis for a trading day, it would check for the same scenarios on another trading day. The program would keep doing this until the last 30 trading days are analyzed.
    Finally after the 30 days analysis, Print the FailCounter and PassCounter values for that particular currency over the last 30 days.

    Credit for contribution. Appreciated.
     
  2. Great to understand the past. Why should this idea have the slightest predictive power for the future?

     
    MrAgi1 likes this.
  3. MrAgi1

    MrAgi1

    I noticed a trend for a particular currency pair, I don't want to name it here. It always trends at a particular time of the day in one particular direction for a short period of time. I see this as a little edge and I am trying to backtest it by going far back as 3 years ago to get more clarity, but I am not really good at programming and it is extremely tedious to backtest manually if not both impossible and error-prone.

    Well, I was vague in my explanation, hope you get the point.
     
  4. easymon1

    easymon1

    MrAgi1 likes this.
  5. fan27

    fan27

    Nice try, but no one is going to code this for you aside from you paying them to do so. You have a few options.

    1. Spend a considerable amount of time learning to code yourself.
    2. Pay someone to code up your ideas.
    3. Ditch the idea of algo trading and learn how to trade/invest without having to do items 1 or 2.
     
    MrAgi1 likes this.
  6. 2rosy

    2rosy

    You never defined the length of the candles or when day ends.
    The program to do this is less than twenty lines
     
    MrAgi1 likes this.
  7. Bad_Badness

    Bad_Badness

    MrAgi1,

    I suggest you take all your "rules" and manually trade them and ONLY them. Probably you will find how much is missing. Pretend you are the code, and try to define all the parts that you do. If you do only what your rules say, eventually you will discover what you posted is a small percent of the system you need.

    But you will have a lot more data, and insight so if you eventually try to automate, you will have a leg up.

    The problem with people who do not DEVELOPE code, is they don't understand all the extra details to make it work properly under exception conditions. For instance at one point in the past, MS word was 70% error handling and recovery code.

    There is a huge canyon between signals code and trade management code

    It is easy to make a wheeled vehicle go fast, controlling it is another whole deal (x2)
     
    comagnum and MrAgi1 like this.
  8. MrAgi1

    MrAgi1

    I said the 30 minutes chart. So each candle last 30 minutes.