Trade during time slots

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #7816 quote
    markouk
    Participant
    Average

    New to learning this code and trying to build a strategy that only trades during specific hours. But I cannot seem to get the code quite right, can anyone help me please?

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    Defparam FLATAFTER = 235900
    
    // Conditions to enter long positions
    indicator1 = MACDline[12,26,9](close)
    indicator2 = ExponentialAverage[9](MACDline[12,26,9](close))
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF (Time >= 175900) AND (Time <= 205900) AND c1 THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    IF (Time >= 235900) THEN
    SELL AT MARKET
    ENDIF
    
    // Stops and targets
    #7817 quote
    Nicolas
    Keymaster
    Master

    Your code seems right, except that you can delete the lines 14 to the end because you use FLATAFTER instruction that will close immediately all orders on market.

    If you plan to trade this strategy on a daily basis, that will not work because trade will never be executed (due to time limitations you made), maybe that’s where is your trouble with this code.

    #7820 quote
    markouk
    Participant
    Average

    Nicolas thank you for replying. The problem I am having is getting the trade to exit. In backtesting I can see one Buy, but then it does not exit at 2359hrs and therefore no other trades can take place.

    #7822 quote
    Nicolas
    Keymaster
    Master

    On which timeframe do you test it?

    #7825 quote
    markouk
    Participant
    Average

    GBPUSD and 15min.

    #7947 quote
    markouk
    Participant
    Average

    Nicolas for whatever reason my code started working without much changes by me. The trades now close and my latest version is:

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    Defparam FLATAFTER = 083000

    // Conditions to enter long positions
    indicator1 = MACDline[12,26,9](close)
    indicator2 = ExponentialAverage[9](MACDline[12,26,9](close))
    c1 = (indicator1 CROSSES OVER indicator2)

    IF (Time >= 054500) AND (Time <= 0715000) AND c1 THEN
    BUY 2 PERPOINT AT MARKET
    ENDIF

    // Conditions to enter short positions
    indicator1 = MACDline[12,26,9](close)
    indicator2 = ExponentialAverage[9](MACDline[12,26,9](close))
    c2 = (indicator1 CROSSES UNDER indicator2)

    IF c2 THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF

    // Stops and targets
    SET STOP %LOSS 0.4
    Set target PPROFIT 18

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Trade during time slots


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
markouk @markoukay Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by markouk
9 years, 8 months ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 05/23/2016
Status: Active
Attachments: No files
Logo Logo
Loading...