Fast Moving Average and Price Crossover

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

    Hi, I have a system that uses heiken ashi candles and it will go long when the simple moving average(9) crosses a bullish candle and then closes and goes short when it crosses a bearish candle. I need any help making it as I’m having trouble doing so. It’s a pretty basic system and I’ve tried stuff like what you can see below but that doesn’t work. Please help.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = close
    indicator2 = Average[9](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 THEN
    BUY 500 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = close
    indicator4 = Average[9](close)
    c2 = (indicator3 CROSSES UNDER indicator4)
    
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator5 = close
    indicator6 = Average[9](close)
    c3 = (indicator5 CROSSES UNDER indicator6)
    
    IF c3 THEN
    SELLSHORT 500 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator7 = close
    indicator8 = Average[9](close)
    c4 = (indicator7 CROSSES OVER indicator8)
    
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    #10178 quote
    Nicolas
    Keymaster
    Master

    Hello, I have not tested your strategy code but it seems right. Why do you think this is not working?

    #10179 quote
    jbyrne
    Participant
    Average

    Hi, this code is correct but it doesn’t do my system correctly. The main problem I’ve been having is getting the system to recognize when the moving average has crossed a candle, then to recognize what direction the candle is.

    #10182 quote
    Nicolas
    Keymaster
    Master

    Your code is catching correctly the moment when price are crossing the moving average. If you want to add a condition on the candlestick direction, you can code it like this:

    bullish = close[1]>open[1]
    bearish = close[1]<open[1]
    
    IF c1 and bullish THEN
     BUY 500 PERPOINT AT MARKET
    ENDIF
    
    IF c3 and bearish THEN
     SELLSHORT 500 PERPOINT AT MARKET
    ENDIF
    
    
    #10183 quote
    jbyrne
    Participant
    Average

    Hi, thank you for your help it’s helped me a lot. I have realized that the problem i was having is that I use heiken ashi candles but ProOrder uses regular candlesticks. How can I get my code to buy/sell according to Heiken Ashi candles instead of regular candlesticks? thank you

    #10188 quote
    Nicolas
    Keymaster
    Master

    Here is Heiken Ashi candlestick codes for Open and Close:

    once haclose=close
    once haopen=open
    
    if barindex>1 then
     haclose=(open+close+low+high)/4
     haopen=(haopen[1]+haclose[1])/2 
    endif
    #10189 quote
    jbyrne
    Participant
    Average

    thank you, you have been very helpful, but can you direct me where to put that code in order to make my system work? thank you

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

Fast Moving Average and Price Crossover


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jbyrne @jbyrne Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by jbyrne
9 years, 7 months ago.

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