Trade during time slots

Viewing 6 posts - 1 through 6 (of 6 total)
  • #7816

    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?

     

    #7817

    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

    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

    On which timeframe do you test it?

    #7825

    GBPUSD and 15min.

    #7947

    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)

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