Conversion of a trend following strategy from the MultiCharts trading software

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #234718 quote
    Gaby
    Participant
    Average

    Hello, I am wondering if you can help on this translation from PowerLanguage (Multicharts) to Prorealcode. Please note; in the original code  the variable  OpenS(1), (HighS(1), LowS(1) and CloseS(1) are the OHLC of yesteday’s exchange session (18.00 open – 17.00 close, ET time), equal to my local time 23.00 open – 22.00 close GMT time. I am not clear how to translate this in Prorealcode, keeping the default settings, if possible, on the chart.

    Thanks for your support.

    =============================

    Inputs: MyContracts(1), MyStop(1470);
    Variable: SessionStartTimeA(1800), sessionEndTimeA(1700);
    variable: FastSMA(0), SlowSMA(0), DailySetupLong(false), DailySetupShort(false), GradientCheck(false);
    variable: Spread(0.02), MyStartTime(1900), MyEndTime(1600), MyStartPause(2000), MyEndPause(2000), MaxEntriesPerDay(2), MaxDaysInTrade(4);
    variable: myTimeframe(60), myFastLength(12), mySlowLength(24), myGradientLength(2), myDailyFactor(0.5), myGradientFactor(1.6);
    //VARIABLES CALCULATION
    FastSMA = Average(close, myFastLength);
    SlowSMA = Average(close, mySlowLength);
    if currentbar > 1440/myTimeframe then begin //To not divide by 0 on the first bars
    DailySetupLong = absvalue(CloseS(1)-OpenS(1))/(HighS(1)-LowS(1)) <= myDailyFactor and CloseS(1) > OpenS(1);
    DailySetupShort = absvalue(CloseS(1)-OpenS(1))/(HighS(1)-LowS(1)) <= myDailyFactor and CloseS(1) < OpenS(1);
    GradientCheck = absvalue(FastSMA – FastSMA[myGradientLength]) >= myGradientFactor*absvalue(SlowSMA – SlowSMA[myGradientLength]);
    end;
    //ENTRIES
    if tw(MyStartTime,MyEndTime) and (Time<MyStartPause or Time>MyEndPause) and entriestoday(date)<MaxEntriesPerDay then begin
    if marketposition = 0 and DailySetupLong and GradientCheck and FastSMA crosses above SlowSMA then begin
      value1 = close+spread;
    buy(“LE”) mycontracts contracts next bar at value1 limit;
    end;
    if marketposition = 0 and DailySetupShort and GradientCheck and FastSMA crosses below SlowSMA then begin
    value2 = close-spread;
    sellshort(“SE”) mycontracts contracts next bar at value2 limit;
    end;
    end;
    //EXITS
    if (date – entrydate) >= MaxDaysinTrade then setexitonclose;
    if dayofweek(date) = 5 then setexitonclose;
    if FastSMA crosses below SlowSMA then sell(“LX”) next bar at market;
    if FastSMA crosses above SlowSMA then buytocover(“SX”) next bar at market;
    setstopcontract;
    if mystop>0 then setstoploss(MyStop);
    #234731 quote
    Iván González
    Moderator
    Master

    Hi! here you have the code:

    //
    
    startTime=153000
    endTime=220000
    pauseStart=190000
    pauseEnd=203000
    
    maxDaysInTrade=4
    maxEntriesPerDay=2
    spread=0.02
    
    //
    
    fastLength=12
    slowLength=24
    gradientLength=2
    dailyFactor=0.5
    gradientFactor=1.6
    
    //
    
    fastSMA=average[fastLength](close)
    slowSMA=average[slowLength](close)
    
    DailySetupLong=abs(Dclose(1)-Dopen(1))/(Dhigh(1)-Dlow(1))<= dailyFactor and Dclose(1)>Dopen(1)
    
    DailySetupShort=abs(Dclose(1)-Dopen(1))/(Dhigh(1)-Dlow(1))<= dailyFactor and Dclose(1)<Dopen(1)
    
    gradientCheck=abs(fastSMA-fastSMA[gradientLength])>=gradientFactor*abs(slowSMA-slowSMA[gradientLength])
    
    //
    once entriesToday=0
    once daysInMarket=0
    once value1=close
    once value2=close
    
    if intradaybarindex=0 then
    entriesToday=0
    LastTradeidx=tradeindex
    if onmarket then
    daysInMarket=daysInMarket+1
    else
    daysInMarket=0
    endif
    endif
    
    if (time>=startTime and time<endTime) and (time<pauseStart or time>pauseEnd) and entriesToday<maxEntriesPerDay then
    
    if tradeindex<>LastTradeidx then
    entriesToday=entriesToday+1
    LastTradeidx=tradeindex
    else
    entriesToday=entriesToday
    LastTradeidx=LastTradeidx
    endif
    
    if dailySetupLong and gradientCheck and fastSMA crosses over slowSMA then
    value1=close+spread
    buy 1 contract at value1 limit
    endif
    
    if dailySetupShort and gradientCheck and fastSMA crosses under slowSMA then
    value2=close-spread
    sellshort 1 contract at value2 limit
    endif
    endif
    
    if onmarket then
    if longonmarket and fastSMA crosses under slowSMA then
    sell at market
    elsif shortonmarket and fastSMA crosses over slowSMA then
    exitshort at market
    elsif daysInMarket >= maxDaysInTrade then
    sell at market
    exitshort at market
    endif
    endif
    
    graphonprice fastSMA coloured("red")
    graphonprice slowSMA coloured("blue")
    
    Gaby thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Conversion of a trend following strategy from the MultiCharts trading software


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Gaby @gaby Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
1 year, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/02/2024
Status: Active
Attachments: No files
Logo Logo
Loading...