identify the % of trades which open and close in the same bar

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #72577 quote
    Pepsmile
    Participant
    Veteran

    Hi all,

    Below a snippet to visualize and quickly identify the % of trades which open and close in the same bar.

    This could help to avoid some kind of “holly grail” strategies and sometimes to ajust exit orders instead of using Target Profit/Stop Loss.
    Pepsmile

    //Count the % of trades closed in the same candle
    // Pepsmile
    // 7 june 2018
    
    DEFPARAM CUMULATEORDERS = false
    // simple buy/short strategy
    MM1 = ExponentialAverage[20](close)
    
    // Long
    IF MM1 crosses over MM1[1] THEN
    BUY 1 LOT AT MARKET
    ENDIF
    
    // Short
    IF MM1 crosses under MM1[1] THEN
    SELLSHORT 1 LOT AT MARKET
    ENDIF
    
    ////// closed SL & TP to find easily right cases
    set stop ploss 5
    set target pprofit 5
    ///////////////////
    // Snippet
    if longonmarket[2]=0 and longonmarket[1]>0 and longonmarket=0 then
    Long1=Long1+1
    elsif shortonmarket[2]=0 and shortonmarket[1]>0 and shortonmarket=0 then
    Short1=Short1+1
    endif
    
    // Graph variables
    // Long1 = count #longs open/close in the same candle
    // Short1 = count #longs open/close in the same candle
    //graph Long1 as "Long1"
    //graph -Short1 as "Short1"
    //
    
    if (onmarket and barindex=tradeindex) or(barindex=tradeindex and barindex=tradeindex(2)) then
    TotalT=TotalT+1
    endif
    // due to the lag of 1 bar calculation for Long1 & Short1, results have to been considered 1 bar after close, best to see final result
    graph 100*(Long1+Short1)/TotalT
    
    Nicolas thanked this post
    #72601 quote
    GraHal
    Participant
    Master

    Above added to Snippet Link Library

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

identify the % of trades which open and close in the same bar


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Pepsmile @pepsmile Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by GraHal
7 years, 9 months ago.

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