Help with code please!? Launch orders only in specified schedules

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19729 quote
    MarkMark
    Participant
    Senior

    Hello,

    Could someone please help me add a bit of code to this strategy.

    I would like to only enter the market between 090000 and 210000, however i do not want it to close my positions at 210000, i am happy for open positions to run over night, i just want entries of new positions to be between said time frame.

    defparam cumulateorders = false
    
    REM Money Management
    Capital = 2500 // initial capital at launch of the strategy
    Risk = 3 // risk in percent
    
    
    REM Calculate contracts
    equity = Capital + StrategyProfit
    maxrisk = round(equity*(Risk/100))
    
    
    REM defining moving averages
    EMA5 = exponentialaverage[5]
    EMA100 = exponentialaverage[100]
    EMA200 = exponentialaverage[200]
    hh = highest[20](high)
    ll = lowest[20](low)
    
    // -- case BUY
    if EMA5 crosses over EMA200 then
    stoploss = (close-ll)/pointsize
    stoplevel = (close-ll)
    If stoploss < 15 then
    stoploss = 15
    Endif
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    BUY PositionSize SHARES AT MARKET
    endif
    
    // -- case SELL
    if EMA5 crosses under EMA200 then
    stoploss = (hh-close)/pointsize
    stoplevel = (hh-close)
    If stoploss < 15 then
    stoploss = 15
    Endif
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    SELLSHORT PositionSize SHARES AT MARKET
    endif
    
    // -- trades exit
    if EMA5 crosses under EMA100 then
    SELL AT MARKET
    endif
    if EMA5 crosses over EMA100 then
    EXITSHORT AT MARKET
    endif
    
    SET STOP LOSS stoplevel
    
    #19752 quote
    ALEALE
    Moderator
    Master

    could you try it?:

    defparam cumulateorders = false
    
    REM Money Management
    Capital = 2500 // initial capital at launch of the strategy
    Risk = 3 // risk in percent
    
    
    REM Calculate contracts
    equity = Capital + StrategyProfit
    maxrisk = round(equity*(Risk/100))
    
    
    REM defining moving averages
    EMA5 = exponentialaverage[5]
    EMA100 = exponentialaverage[100]
    EMA200 = exponentialaverage[200]
    hh = highest[20](high)
    ll = lowest[20](low)
    
    // -- case BUY
    if EMA5 crosses over EMA200 then
    stoploss = (close-ll)/pointsize
    stoplevel = (close-ll)
    If stoploss < 15 then
    stoploss = 15
    Endif
    if (time >=090000 and time < 210000) then
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    BUY PositionSize SHARES AT MARKET
    endif
    endif
    // -- case SELL
    if EMA5 crosses under EMA200 then
    stoploss = (hh-close)/pointsize
    stoplevel = (hh-close)
    If stoploss < 15 then
    stoploss = 15
    Endif
    if (time >=090000 and time < 210000) then
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    SELLSHORT PositionSize SHARES AT MARKET
    endif
    endif
    
    // -- trades exit
    if EMA5 crosses under EMA100 then
    SELL AT MARKET
    endif
    if EMA5 crosses over EMA100 then
    EXITSHORT AT MARKET
    endif
    
    SET STOP LOSS stoplevel
    #19844 quote
    MarkMark
    Participant
    Senior

    Thanks for this, i will have a look

     

    Mark

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Help with code please!? Launch orders only in specified schedules


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mark @mbaker15 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by MarkMark
9 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/03/2017
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...