Silly Q exit x points after entry not working

Viewing 11 posts - 16 through 26 (of 26 total)
  • Author
    Posts
  • #8077 quote
    Nicolas
    Keymaster
    Master

    Hi Cosmic,

    Please change the line 37 to 45 with this code instead:

    if longonmarket then
     set stop ploss 40
     set target pprofit 25
    endif
    
    if shortonmarket then
     set stop ploss 30
     set target pprofit 25
    endif

    To test if it’s ok. In your broker orders list, do you see the takeprofit and stoploss values?

    #8078 quote
    Adolfo
    Participant
    Senior

    Sorry Cosmic1, were too late and didn’t test it, my fault… above code is wrong, here you have it, tested:

    DEFPARAM CUMULATEORDERS = FALSE
    DEFPARAM FLATAFTER = 205500
    
    
    // One Trade Per Day
    Once nbTrades = 0
    Once tradesPerDay = 1
    
    If Day<>Day[1] then
    nbTrades = 0
    Else
    If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
    nbTrades = nbTrades + 1
    Endif
    Endif
    
    If nbTrades < tradesPerDay then
    
    //End One Trade Per Day Code
    
    cashhigh = highest[180](high)
    cashlow = lowest[180](low)
    
    ENDIF
    
    IF NOT LONGONMARKET AND Time > 173000 AND Time <= 193000 THEN
    //Enter Longs
    BUY 1 PERPOINT AT cashhigh-5 STOP
    set stop ploss 40
    set target pprofit 25
    ENDIF
    
    //Enter Shorts
    IF NOT SHORTONMARKET AND Time > 173000 AND Time <= 193000 THEN
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    set stop ploss 30
    set target profit 25
    ENDIF
    
    

    Cheers

    #8119 quote
    Cosmic1
    Participant
    Senior

    Thank you, I think we are nearly there but this latest version now breaks the one trade per day code 🙁

    Separate stops and limits work though 🙂

    #8133 quote
    Cosmic1
    Participant
    Senior

    Actually I can’t see if the separate stops and limits are working as trades are being taken too often…

    #8150 quote
    Nicolas
    Keymaster
    Master

    This should fix the one trade per day issue:

    DEFPARAM CUMULATEORDERS = FALSE
    DEFPARAM FLATAFTER = 205500
    
    
    // One Trade Per Day
    Once nbTrades = 0
    Once tradesPerDay = 1
    
    If Day<>Day[1] then
    nbTrades = 0
    Else
    If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
    nbTrades = nbTrades + 1
    Endif
    Endif
    
    If nbTrades < tradesPerDay then
    
    //End One Trade Per Day Code
    
    cashhigh = highest[180](high)
    cashlow = lowest[180](low)
    
    IF NOT LONGONMARKET AND Time > 173000 AND Time <= 193000 THEN
    //Enter Longs
    BUY 1 PERPOINT AT cashhigh-5 STOP
    set stop ploss 40
    set target pprofit 25
    ENDIF
    
    //Enter Shorts
    IF NOT SHORTONMARKET AND Time > 173000 AND Time <= 193000 THEN
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    set stop ploss 30
    set target profit 25
    ENDIF
    ENDIF
    
    #8151 quote
    Cosmic1
    Participant
    Senior

    Hi, It does and I tried moving the IF’s as you did above but it now doesn’t follow the separate stops and limits. Longs and shorts both get stopped at 20points when using this code.

    DEFPARAM CUMULATEORDERS = FALSE
    DEFPARAM FLATAFTER = 205500
    
    
    // One Trade Per Day
    Once nbTrades = 0
    Once tradesPerDay = 1
    
    If Day<>Day[1] then
    nbTrades = 0
    Else
    If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
    nbTrades = nbTrades + 1
    Endif
    Endif
    
    If nbTrades < tradesPerDay then
    
    //End One Trade Per Day Code
    
    cashhigh = highest[180](high)
    cashlow = lowest[180](low)
    
    IF NOT LONGONMARKET AND Time > 173000 AND Time <= 193000 THEN
    //Enter Longs
    BUY 1 PERPOINT AT cashhigh-5 STOP
    set stop ploss 40
    set target pprofit 40
    ENDIF
    
    //Enter Shorts
    IF NOT SHORTONMARKET AND Time > 173000 AND Time <= 193000 THEN
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    set stop ploss 20
    set target pprofit 20
    ENDIF
    ENDIF
    #8152 quote
    Cosmic1
    Participant
    Senior

    I should correct the above to say Longs and shorts both have their stops and limits at 20points when using this code. Thanks for all your help 🙂

    #8154 quote
    Adolfo
    Participant
    Senior

    Could be this ?

    IF Time > 173000 AND Time <= 193000 THEN
    
    //Enter Longs
    IF NOT LONGONMARKET THEN
    BUY 1 PERPOINT AT cashhigh-5 STOP
    set stop ploss 40
    set target pprofit 40
    ENDIF
    
    //Enter Shorts
    IF NOT SHORTONMARKET 
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    set stop ploss 20
    set target pprofit 20
    ENDIF
    ENDIF
    #8155 quote
    Cosmic1
    Participant
    Senior

    Nope still makes no difference 🙁

    #8158 quote
    Adolfo
    Participant
    Senior

    Ok, how about this?

    IF Time > 173000 AND Time <= 193000 THEN
    //Enter Longs
    IF NOT LONGONMARKET THEN
    BUY 1 PERPOINT AT cashhigh-5 STOP
    stoplong = cashhigh-45*pipsize 
    profitlong = cashhigh+55*pipsize
    ENDIF
    //Enter Shorts
    IF NOT SHORTONMARKET 
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    stopshort = cashlow-15*pipsize 
    profitshort = cashlow+25*pipsize
    ENDIF
    ENDIF
    
    IF NOT ONMARKET THEN 
    stoplong = 0 
    stopshort = 0 
    profitlong = 0 
    profitshort = 0 
    ENDIF
    IF LONGONMARKET THEN
    sell at stoplong stop 
    sell at profitlong limit
    ENDIF
    
    IF SHORTONMARKET THEN
    exitshort at stopshort stop
    exitshort at profitshort limit
    ENDIF
    
    
    #8161 quote
    Cosmic1
    Participant
    Senior

    Thanks again but not working, no stops or limits work at all… All other code works. All trades close at the FLATAFTER time…

    DEFPARAM CUMULATEORDERS = FALSE
    DEFPARAM FLATAFTER = 205500
    
    
    //One Trade Per Day
    Once nbTrades = 0
    Once tradesPerDay = 1
    
    If Day<>Day[1] then
    nbTrades = 0
    Else
    If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
    nbTrades = nbTrades + 1
    Endif
    Endif
    
    If nbTrades < tradesPerDay then
    
    //End One Trade Per Day Code
    
    IF Time = 173000 then
    
    cashhigh = highest[180](high)
    cashlow = lowest[180](low)
    
    ENDIF
    
    IF Time > 173000 AND Time <= 193000 THEN
    
    //Enter Longs
    IF NOT LONGONMARKET THEN
    BUY 1 PERPOINT AT cashhigh-5 STOP
    stoplong = cashhigh-40*pipsize
    profitlong = cashhigh+40*pipsize
    ENDIF
    
    //Enter Shorts
    IF NOT SHORTONMARKET THEN
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    stopshort = cashlow-20*pipsize
    profitshort = cashlow+20*pipsize
    ENDIF
    ENDIF
    
    IF LONGONMARKET THEN
    sell at stoplong stop
    sell at profitlong limit
    ENDIF
    
    IF SHORTONMARKET THEN
    sell at stopshort stop
    sell at profitshort limit
    ENDIF
    
    IF NOT ONMARKET THEN
    stoplong = 0
    stopshort = 0
    profitlong = 0
    profitshort = 0
    ENDIF
    ENDIF
Viewing 11 posts - 16 through 26 (of 26 total)
  • You must be logged in to reply to this topic.

Silly Q exit x points after entry not working


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Cosmic1 @cosmic1 Participant
Summary

This topic contains 25 replies,
has 3 voices, and was last updated by Cosmic1
9 years, 8 months ago.

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