Cross Over Strategy HELP please

Viewing 8 posts - 16 through 23 (of 23 total)
  • Author
    Posts
  • #61765 quote
    crolakstrading
    Participant
    Senior

    sorry Im keep coming back.. soo after so many attempts i came up with this..

    defparam cumulateorders=false
    
    // Conditions to enter long positions
    i1 = exponentialaverage[9](close)
    i2 = exponentialaverage[40](close)
     
    long  = i1 crosses over  i2
    short = i1 crosses under i2
    
    IF NOT LongOnMarket AND long[5]and summation[4](long) = 0 THEN
    EntryPrice = highest[5](high) + (5* pipsize)
    BUY 1 CONTRACTS AT EntryPrice STOP
    ENDIF
    
    // Conditions to exit long positions
    If LongOnMarket AND short THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    IF NOT LongOnMarket AND short[5]and summation[4](short) = 0 THEN
    EntryPrice = lowest[5](low) - (5 * pipsize)
    SELLSHORT 1 CONTRACTS AT EntryPrice STOP
    ENDIF
    
    // Conditions to exit short positions
    IF ShortOnMarket AND long THEN
    EXITSHORT AT MARKET
    ENDIF

    which give me the entry as the topline or the bottomline as per the indicator.. but only issue is its only trigger on the 5th candle..  5th bar didn’t get triggered, it doesn’t continue as a stop order? is there a way to sort it out.. please help!

    Thanks

    Ro

    #61813 quote
    robertogozzi
    Moderator
    Master

    In lines 10 and 21 you only check the fifth previous bar, if it’s true the pending order is placed, but the next bar the fifth previous bar will become the sixth previous bar and your condition will obviously be false!

    Since a pending order only lasts one bar…. it’ll never be triggered.

    How many bars do you want the pending order to be kept in place, after the fifth one?

    #61819 quote
    crolakstrading
    Participant
    Senior

    oh ok.. lets say once we get the Entryprice and confirmed then we get a pending order for that price for next 10 bars and probably cancel after 10 bars??

    thanks Roberto.

    #61860 quote
    robertogozzi
    Moderator
    Master

    Line 21 should read

    IF NOT ShortOnMarket AND short[5]and summation[4](short) = 0 THEN
    #61861 quote
    robertogozzi
    Moderator
    Master

    I modified your code to accomodate for counting elapsed bars since the crossing occurrs. I did not test it, give me some feedback.

    defparam cumulateorders = false
    ONCE MaxBars            = 10
    ONCE CrossingBar        = 0
    ONCE CrossUp            = 0
    ONCE CrossDn            = 0
     
    // Conditions to enter long positions
    i1    = exponentialaverage[9](close)
    i2    = exponentialaverage[40](close)
     
    long  = i1 crosses over  i2
    short = i1 crosses under i2
    if long[5] then
       CrossingBar = BarIndex                                          //save the bar ID when the crossing occurred the previous 5th bar
       CrossUp     = 1
       CrossDn     = 0
    endif
    if short[5] then
       CrossingBar = BarIndex                                          //save the bar ID when the crossing occurred the previous 5th bar
       CrossUp     = 0
       CrossDn     = 1
    endif
    if OnMarket then
       CrossingBar = 0                                                 //reset it to zero when on market
       CrossUp     = 0
       CrossDn     = 0
    endif
     
    IF NOT LongOnMarket AND CrossUp AND ((BarIndex - CrossingBar) <= MaxBars) THEN
       EntryPrice = highest[5](high) + (5* pipsize)
       BUY 1 CONTRACTS AT EntryPrice STOP
    ENDIF
     
    // Conditions to exit long positions
    If LongOnMarket AND short THEN
       SELL AT MARKET
    ENDIF
     
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND CrossDn AND ((BarIndex - CrossingBar) <= MaxBars) THEN
       EntryPrice = lowest[5](low) - (5 * pipsize)
       SELLSHORT 1 CONTRACTS AT EntryPrice STOP
    ENDIF
     
    // Conditions to exit short positions
    IF ShortOnMarket AND long THEN
       EXITSHORT AT MARKET
    ENDIF
    Nicolas thanked this post
    #61936 quote
    crolakstrading
    Participant
    Senior

    hi Roberto.. thanks..

    This is actually given better result.. but some of the entry prices isnt right.. i think its only take the 5th candles high and  5pips above..

    Entry price should be.. once the cross over happen and wait for 5 bars and enter the highest high within that 5 bars and 5 pips above!! lets say cross over and the highest high is the 3rd candle with that 5 bars and it should be 5 pips above on that 3rd candle… indicator works perfectly fine as it say below.. if its long we get the TOPLINE perfectly!!

    CrossOver = fast crosses over slow
    IF CrossOver THEN
    BullTrend = 1
    BearTrend = 0
    SideWays = 0
    CrossUnder = 0
    //cross = slow[1]
    DRAWARROWUP(barindex,LOW-5*pointsize) COLOURED(0,255,10)
    endif
    
    IF CrossOver[5] THEN
    IF summation[4](CrossOver OR CrossUnder) = 0 THEN
    TopLine = highest[5](high) + (5 * pipsize)
    DRAWTEXT("---#TopLine#---",barindex-3,TopLine,SansSerif,Bold,10)coloured(0,153,0)
    ENDIF
    #61940 quote
    robertogozzi
    Moderator
    Master

    Try this one, I moved lines 30 and 41 inside a prior IF…ENDIF block.

    defparam cumulateorders = false
    ONCE MaxBars            = 10
    ONCE CrossingBar        = 0
    ONCE CrossUp            = 0
    ONCE CrossDn            = 0
     
    // Conditions to enter long positions
    i1    = exponentialaverage[9](close)
    i2    = exponentialaverage[40](close)
     
    long  = i1 crosses over  i2
    short = i1 crosses under i2
    if long[5] then
       CrossingBar = BarIndex                                          //save the bar ID when the crossing occurred the previous 5th bar
       CrossUp     = 1
       CrossDn     = 0
       EntryPrice  = highest[5](high) + (5* pipsize)
    endif
    if short[5] then
       CrossingBar = BarIndex                                          //save the bar ID when the crossing occurred the previous 5th bar
       CrossUp     = 0
       CrossDn     = 1
       EntryPrice  = lowest[5](low) - (5 * pipsize)
    endif
    if OnMarket then
       CrossingBar = 0                                                 //reset it to zero when on market
       CrossUp     = 0
       CrossDn     = 0
    endif
     
    IF NOT LongOnMarket AND CrossUp AND ((BarIndex - CrossingBar) <= MaxBars) THEN
       BUY 1 CONTRACTS AT EntryPrice STOP
    ENDIF
     
    // Conditions to exit long positions
    If LongOnMarket AND short THEN
       SELL AT MARKET
    ENDIF
     
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND CrossDn AND ((BarIndex - CrossingBar) <= MaxBars) THEN
       SELLSHORT 1 CONTRACTS AT EntryPrice STOP
    ENDIF
     
    // Conditions to exit short positions
    IF ShortOnMarket AND long THEN
       EXITSHORT AT MARKET
    ENDIF
    #62450 quote
    crolakstrading
    Participant
    Senior

    Thanks very much Roberto.. i think this is pretty much gives the right entry.. i will test this and let you know!!!!

Viewing 8 posts - 16 through 23 (of 23 total)
  • You must be logged in to reply to this topic.

Cross Over Strategy HELP please


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 22 replies,
has 2 voices, and was last updated by crolakstrading
8 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/31/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...