code for EMA, MACD and Stochastic strategy

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #82411 quote
    rae
    Participant
    New

    Hi, I would like to generate a code for the EMA [34,89,144] crossings, MACD and Sto.

    Conditions for long:

    1. EMA34 crosses over EMA89
    2. MACD > 0
    3. Sto > 30
    4. Buy at EMA34 or half of previous candle

     

    Exit when:

    1. EMA34 crosses under EMA144
    2. sell at current price = EMA34
    #82414 quote
    robertogozzi
    Moderator
    Master

    Try this (tested only for syntax errors):

    DEFPARAM CumulateOrders = FALSE
    ONCE BuyCond  = 0
    ONCE SellCond = 0
    IF OnMarket THEN
       BuyCond  = 0
    ENDIF
    IF Not OnMarket THEN
       SellCond = 0
    ENDIF
    Ema144 = exponentialaverage[144](close)
    Ema89  = exponentialaverage[89](close)
    Ema34  = exponentialaverage[34](close)
    MyMacd = Macd[12,26,9](close)
    StocK  = Stochastic[8,4](close)
    c1     = Ema34 CROSSES OVER Ema89
    c2     = MyMacd > 0
    c3     = StocK > 30
    IF BuyCond = 0 THEN
       BuyCond = c1 AND c2 AND c3
       MyPrice= Ema34                         //buy at Ema34  or
       //MyPrice = low[1] + (range[1] / 2)    //buy at half of previous candle
    ENDIF
    // Keep entering a pending orders bar after bar till Onmarket
    IF BuyCond THEN
       IF close > MyPrice THEN
          BUY 1 CONTRACT AT MyPrice LIMIT     //buy at a better price
       ELSE
          BUY 1 CONTRACT AT MyPrice STOP      //buy at a worse price
       ENDIF
    ENDIF
    IF SellCond = 0 THEN
       SellCond  = Ema34 CROSSES UNDER Ema144
       SellPrice = Ema34
    ENDIF
    // Keep entering a pending orders bar after bar till Exit
    IF SellCond THEN
       IF close > SellPrice THEN
          SELL 1 CONTRACT AT SellPrice STOP   //exit at a worse price
       ELSE
          SELL 1 CONTRACT AT SellPrice LIMIT  //exit at a better price
       ENDIF
    ENDIF
    rae thanked this post
    #82417 quote
    rae
    Participant
    New

    thank you!! i will give it a try!

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

code for EMA, MACD and Stochastic strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
rae @rae Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by rae
7 years, 4 months ago.

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