Multi timeframe scalp code question

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #85933 quote
    paulon
    Participant
    Average

    Hi. I want to create a simple program for automatic trading that creates small scalping trades using 15 minute and 5 minute charts (5 minute is the default).

    I am experimenting with different conditions to open the trade but as an example lets say this is a long trade and the opening condition is that MACDline (12,26,9) crosses over 50 on the 5 minute chart. And the RSI(14) must be below 50 on the 15 minute chart

    On the 15 minute chart I have created 2 bands using the ATR. The upper band is the close + the ATR(14) and the lower band is the close – the ATR(14).

    When the trade is opened on the close of the 5 minute bar I want the profit target to be the upper ATR band on the 15 minute chart at the time the trade is opened, and the stop loss to be the lower ATR band on the 15 minute chart at the time the trade is opened.

    Can you help me to code this please?

    #85934 quote
    Vonasi
    Moderator
    Master

    Your question is ProOrder related and not a platform support issue so I have moved your post. Posting in the correct forum will have the best chance of getting a solution and will save us moderators a lot of time moving posts around all day!

    Please try to post in the correct forum with future posts. 🙂

    #85943 quote
    robertogozzi
    Moderator
    Master

    You mean MACDline (12,26,9) crosses over 0 ?

    #85982 quote
    paulon
    Participant
    Average

    Sorry yes you are right!

    #86036 quote
    robertogozzi
    Moderator
    Master

    This the code:

    TIMEFRAME(15 minutes, updateonclose)
    MyRsi    = Rsi[14](close)
    MyAtr    = AverageTrueRange[14](close)
    UpperATR = close + MyAtr
    LowerATR = close - MyAtr
    
    TIMEFRAME(default)                     //5 minutes
    MyMacd   = MACDline[12,26,9](close)
    
    MyConditions = (MyMacd CROSSES OVER 0) AND (MyRsi < 50)
    IF MyConditions AND Not OnMarket THEN
       BUY 1 CONTRACT AT MARKET
       Tp = ABS(UpperATR - close)
       Sl = ABS(close - LowerATR)
       SET TARGET PROFIT Tp
       SET STOP   LOSS   Sl
    ENDIF

    When computing SL and TP I used ABS(()  to make sure it’s not a negative number, because UPDATEONCLOSE at line 1 makes TF15 values older than TF5 so a sudden surge on the default TF might cause, even temporarily, a closing price higher/lower than it was when TF15 closed.

    If you remove UPDATEONCLOSE then you can also remove ABS() but values on TF15 will be the current ones when the TF5 closes, not when TF15 closed last time.

    If you want to try you can even launch the strategy from a 3-minute or 1-minute TF, since 15 is a multiple of 5, 3 and 1 (not 2).

    Nicolas and paulon thanked this post
    #86076 quote
    GraHal
    Participant
    Master

    Even I can understand this one! 🙂  Thank you Paulon and Roberto.

    Results attached for 1 Hour and 3 mins default otherwise unchanged from Roberto code above.

    Paul-Roberto.jpg Paul-Roberto.jpg
    #86144 quote
    GraHal
    Participant
    Master

    Version 1.4 with Shorts.

    If you improve then please post on here so we can all share.

    //https://www.prorealcode.com/topic/multi-timeframe-scalp-code-question/
    DEFPARAM CUMULATEORDERS = False
    Trade = Time > 060000 and Time < 205500
    
    TIMEFRAME(1 Hour)
    MyRsi    = Rsi[8](close)
    MyAtr    = AverageTrueRange[2](close)
    UpperATR = close + MyAtr
    LowerATR = close - MyAtr
     
    TIMEFRAME(default)                     //3 minutes
    MyMacd   = MACDline[12,26,9](close)
     
    MyConditionL = (MyMacd CROSSES OVER 0) AND (MyRsi < 50) and Trade //50
    IF MyConditionL and not onmarket THEN
    BUY 1 CONTRACT AT MARKET
    TpL = (UpperATR - close)
    SlL = (close - LowerATR)
    SET TARGET PPROFIT TpL
    SET STOP   PLOSS   SlL
    ENDIF
    
    MyConditionS = (MyMacd CROSSES UNDER 0) AND (MyRsi > 50) and Trade //50
    IF MyConditionS and not onmarket THEN
    SellShort 1 CONTRACT AT MARKET
    SLS = (UpperATR - close)
    TPS = (close - LowerATR)
    SET TARGET PPROFIT TpS
    SET STOP   PLOSS   SlS
    ENDIF
    //GRAPH UpperATR - close
    //GRAPH close - LowerATR
    //GRAPH TPL
    //GRAPH TPS
    //
    
    Paul-Roberto-2.jpg Paul-Roberto-2.jpg Paul-Roberto-3.jpg Paul-Roberto-3.jpg
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Multi timeframe scalp code question


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
paulon @paulon Participant
Summary

This topic contains 6 replies,
has 4 voices, and was last updated by GraHal
7 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/28/2018
Status: Active
Attachments: 3 files
Logo Logo
Loading...