Backtest Trend Following Moving Averages from Nicolas

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

    Hi, I am a beginner and trying to backtest the indicator (https://www.prorealcode.com/prorealtime-indicators/trend-following-moving-averages/) that create from Nicolas. Can someone please help me figure out or explain how it work in detail?

    #174115 quote
    Nicolas
    Keymaster
    Master

    That indicator doesnt return any value, it plots a cloud of MA in different colors, you can’t use the code “as is” to create a strategy directly in ProOrder. It would need some custom coding, but can you tell us what is the strategy you have in mind?

    #174117 quote
    zxcnin
    Participant
    New

    Thanks Nicolas. I figure it out. I was trying to use the green line as buy signal and red as sell signal. My custom below using EMA 100 to follow the trend. It would be grateful if you have further suggestion.

    DEFPARAM CumulateOrders=False
    capital = 100000 + strategyprofit
    n = capital / close
    // --- settings
    prd = 30 //Period to Check Trend
    rateinp = 1 //Trend Channel Rate %  minval = 0.1, step = 0.1
    ulinreg = 1 // 1=true, Use Linear Regression
    linprd = 10 //Linear Regression Period, minval = 2
    matype = 1 //ma type 0=sma, 1-ema, etc.
    // --- end of settings
    
    rate = rateinp / 100
    pricerange = highest[300](close) - lowest[300](close)
    chan = pricerange * rate
    
    p1 = 100
    //trend
    masrc1 = average[p1,matype](close)
    if ulinreg then
    ma1 = LinearRegression[linprd](masrc1)
    else
    ma1 = masrc1
    endif
    
    hh1 = highest[prd](ma1)
    ll1 = lowest[prd](ma1)
    diff1 = abs(hh1-ll1)
    
    if diff1>chan then
    if ma1>ll1+chan then
    trend1=1
    elsif ma1<hh1-chan then
    trend1=-1
    else
    trend1=0
    endif
    else
    trend1=0
    endif
    
    ret1 = trend1*diff1/chan
    
    alpha1 = min(255,(80+abs(ret1*10)))
    if ret1<0 then
    r1=255
    g1=0
    else
    r1=0
    g1=255
    endif
    
    iprev=$prev[p1]
    
    $prev[p1] = ma1
    
    IF g1 = 255 THEN
    BUY n SHARES AT MARKET
    ENDIF
    
    SET STOP %LOSS 10
    
    IF r1 = 255 THEN
    SELL AT MARKET
    ENDIF
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Backtest Trend Following Moving Averages from Nicolas


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
zxcnin @zxcnin Participant
Summary

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

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