help with break-even code as a second position and second exit

Viewing 15 posts - 16 through 30 (of 39 total)
  • Author
    Posts
  • #152041 quote
    Patrick K Templar
    Participant
    Average

    I’ve cleaned up the code and remove the exit indicator to see if the contracts continue but the code will continue to sell the second contract and that’s the one I want to allow it to run too continue basically i’ve added a picture and on the picture there’s a blue Arrow which shows a sell that is correct but there’s also a red arrow which also shows a sell I want to stop that one from happening

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = AroonUp[19]
    indicator2 = AroonDown[19]
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 AND Not OnMarket THEN
    // Stops and targets : Enter your protection stops and profit targets here
    St = ROUND((AverageTrueRange[14](CLOSE))*2)
    Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)
    BUY 2 PERPOINT AT MARKET
    ENDIF
    
    // target
    
    IF Close >= (TradePrice + Tp) THEN
    SELL 1 PERPOINT AT MARKET
    ENDIF
    
    // Stops
    
    SET STOP LOSS  St
    sys-236.png sys-236.png
    #152047 quote
    robertogozzi
    Moderator
    Master

    That’s because each time line 18 is executed, if conditions are still met, SELL will be executed again closing the second position.

    To keep it running (until you add a condition to close it), replace line 18 with this one:

    IF Close >= (TradePrice + Tp) AND abs(CountOfPosition) = 2 THEN

    so it will execute SELL only the first time.

    Patrick K Templar thanked this post
    #152051 quote
    Patrick K Templar
    Participant
    Average

    That is absolutely brilliant thank you

    #152060 quote
    Patrick K Templar
    Participant
    Average

    I am so sorry to ask for more help with the same indicator,

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter short positions
    indicator1 = CALL DDMIHL1
    c3 = (indicator1 CROSSES UNDER 0)
    
    IF c3 AND Not OnMarket THEN
    // Stops and targets : Enter your protection stops and profit targets here
    St = ROUND((AverageTrueRange[14](CLOSE))*2)
    Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)
    SELLSHORT 2 PERPOINT AT MARKET
    ENDIF
    
    IF Close >= (TradePrice + Tp) AND abs(CountOfPosition) = 2 THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator3 = DI[10](close)
    indicator4 = WeightedAverage[11](DI[10](close))
    c4 = (indicator3 CROSSES OVER indicator4)
    
    IF c4 AND abs(CountOfPosition) = 1 THEN
    BUY AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP LOSS  St

     

    I can’t get the short side of a position to work not too sure what it is if you don’t mind thank you very much

    #152061 quote
    Patrick K Templar
    Participant
    Average

    I’ve played around with it I found the sell shorts and exit shorts were wrong but I believe the line 16 is not right for shorts i’ve adjusted that as well

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = CALL DDMIHL1
    c1 = (indicator1 CROSSES UNDER 0)
    
    IF c1 AND Not OnMarket THEN
    // Stops and targets : Enter your protection stops and profit targets here
    St = ROUND((AverageTrueRange[14](CLOSE))*2)
    Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)
    SELLSHORT 2 PERPOINT AT MARKET
    ENDIF
     
    
    IF Close <= (TradePrice - Tp) AND abs(CountOfPosition) = 2 THEN
    EXITSHORT 1 PERPOINT AT MARKET
    ENDIF
     
    // Stops and targets
    SET STOP LOSS  St
    
    // Conditions to exit long positions
    indicator3 = DI[10](close)
    indicator4 = WeightedAverage[11](DI[10](close))
    c2 = (indicator3 CROSSES OVER indicator4)
    
    IF c2 AND abs(CountOfPosition) = 1 THEN
    EXITSHORT AT MARKET
    ENDIF
    sys-236-1.png sys-236-1.png
    #152063 quote
    robertogozzi
    Moderator
    Master

    Yes, correct.

    Patrick K Templar thanked this post
    #152152 quote
    Patrick K Templar
    Participant
    Average

    Hello i’m afraid that system that you have helped me build may have an underlying fault built into it or it might just be a part of the sellshort side of the code,
    What I have is a screenshot the top 1 is the normal logic and the bottom one is the break-even and scale-out and as you can see the bottom one does not shortsell as much as I think it should and when you compare it to the normal logic it looks bad i’m wondering if there’s anything that can be done here, thannk you

    I will post both systems normal logic first then the break-even

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator2, indicator1, ignored = CALL "PRC_QQE indicator"[5, 14, 4.236]
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator4, indicator3, ignored = CALL "PRC_QQE indicator"[5, 14, 4.236]
    c2 = (indicator3 CROSSES UNDER indicator4)
    
    IF c2 THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF
    
    // Stops and targets : Enter your protection stops and profit targets here
    St =  ROUND((AverageTrueRange[14](CLOSE))*2)
    Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)
    
    
    SET STOP LOSS  St
    SET TARGET PROFIT  Tp
    
    // Conditions to enter long positions
    defparam cumulateorders = false
     
    startBreakeven = TP //how much pips/points in gain to activate the breakeven function?
    PointsToKeep = 10 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
     
    // Conditions to enter long positions
    indicator2, indicator1, ignored = CALL "PRC_QQE indicator"[11, 14, 4.236]
    c1 = (indicator1 CROSSES OVER indicator2)
     
    if c1 AND Not OnMarket THEN
    // Stops and targets :
    St = ROUND((AverageTrueRange[14](CLOSE))*2)
    Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)
    BUY 2 PERPOINT AT MARKET
    SET STOP PLOSS St //first stoploss
    endif
     
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
     
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    
    IF LONGONMARKET AND Close >= (TradePrice + Tp) AND abs(CountOfPosition) = 2 THEN
    SELL 1 PERPOINT AT MARKET
    ENDIF
     
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    
    // Conditions to exit long positions
    indicator3, indicator4, ignored = CALL "PRC_QQE indicator"[11, 14, 4.236]
    B1 = (indicator4 CROSSES UNDER indicator3)
    
    IF B1 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    // Conditions to enter short positions
    indicator1, indicator2, ignored = CALL "PRC_QQE indicator"[11, 14, 4.236]
    A1 = (indicator2 CROSSES UNDER indicator1)
     
    if A1 AND Not OnMarket THEN
    // Stops and targets :
    St = ROUND((AverageTrueRange[14](CLOSE))*2)
    Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)
    SELLSHORT 2 PERPOINT AT MARKET
    SET STOP PLOSS St //first stoploss
    endif
     
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
     
    // --- Sell SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF SHORTONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    
    IF SHORTONMARKET AND Close <= (TradePrice - Tp) AND abs(CountOfPosition) = 2 THEN
    EXITSHORT 1 PERPOINT AT MARKET
    ENDIF
     
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    
    // Conditions to exit short positions
    indicator3, indicator4, ignored = CALL "PRC_QQE indicator"[11, 14, 4.236]
    B1 = (indicator4 CROSSES OVER indicator3)
    
    IF B1 THEN
    EXITSHORT AT MARKET
    ENDIF
    fault.png fault.png
    #152157 quote
    robertogozzi
    Moderator
    Master

    There’s always something to be done. If something doesn’t work as expected it’s just a matter of making it work!

    Append these few lines at the end of your code:

    Graph        B1
    Graph        abs(CountOfPosition)
    GraphOnPrice (TradePrice + Tp)    coloured(0,255,0,255) AS "Long  EXIT 1"
    GraphOnPrice (TradePrice - Tp)    coloured(0,0,255,255) AS "Short EXIT 1"

    you will be able to see data plotted using GRAPH in the variable window of ProBackTest and data plotted using GRAPHONPRICE on your chart,candleby candle.

    You will be able to detect any wrong value that may cause issues.

    You can add more variables, if needed.

    Patrick K Templar thanked this post
    #152164 quote
    Patrick K Templar
    Participant
    Average

    Definitely should be some shorts there you can see an August at the beginning of the chart there’s a crossover and it not on market yet no short and in September there’s a long where they shouldn’t be it goes long yet the qqe has not crossed over i’m going to test a different indicator “what if it’s the indicator”

    nts.png nts.png
    #152166 quote
    Patrick K Templar
    Participant
    Average

    Eureka I found it he was the indicator numbers

    tut.png tut.png
    #152363 quote
    Patrick K Templar
    Participant
    Average

    Hello I’ve noticed some anomalies on the chart and I’m not too sure what they are are I’ve uploaded a picture and I put red arrows on it they don’t affect the equity curve nor is there contracts for them i’m wondering if they can affect the trading backtest algorithm or if on market and the blue arrows show a buy but the conditions for the trade was not met the qqe did not crossover, i’m thinking that’s a problem with the code for the QQE or if it repainted.

    // Conditions to enter long positions
    defparam cumulateorders = false
     
    
    startBreakeven = TP //how much pips/points in gain to activate the breakeven function?
    PointsToKeep = 2 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
     
    // Conditions to enter long positions
    indicator2, indicator1, ignored = CALL "PRC_QQE indicator"[11, 20, 4.236]
    A1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = Williams[8](close)
    A2 = (indicator3 >= -20)
     
    IF A1 AND A2 AND Not OnMarket THEN
    // Stops and targets :
    St = ROUND((AverageTrueRange[14](CLOSE))*2)
    Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)
    BUY 2 PERPOINT AT MARKET
    SET STOP PLOSS St //first stoploss
    endif
     
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
     
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    
    IF LONGONMARKET AND Close >= (TradePrice + Tp) AND abs(CountOfPosition) = 2 THEN
    SELL 1 PERPOINT AT MARKET
    ENDIF
     
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    
    // Conditions to exit long positions
    indicator5, indicator4, ignored = CALL "PRC_QQE indicator"[11, 20, 4.236]
    B1 = (indicator4 CROSSES UNDER indicator5)
    
    IF B1 THEN
    SELL AT MARKET
    ENDIF
    
    
    // Conditions to enter short positions
    // Conditions to enter short positions
    indicator7, indicator6, ignored = CALL "PRC_QQE indicator"[11, 20, 4.236]
    C1 = (indicator6 CROSSES UNDER indicator7)
    indicator8 = Williams[8](close)
    C2 = (indicator8 <= -80)
     
    IF C1 AND C2 AND Not OnMarket THEN
    // Stops and targets :
    St = ROUND((AverageTrueRange[14](CLOSE))*2)
    Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)
    SELLSHORT 2 PERPOINT AT MARKET
    SET STOP PLOSS St //first stoploss
    endif
     
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
     
    // --- Sell SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF SHORTONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    
    IF SHORTONMARKET AND Close <= (TradePrice - Tp) AND abs(CountOfPosition) = 2 THEN
    EXITSHORT 1 PERPOINT AT MARKET
    ENDIF
     
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    EXITSHORT AT breakevenLevel STOP
    ENDIF
    
    // Conditions to exit short positions
    indicator10, indicator9, ignored = CALL "PRC_QQE indicator"[11, 20, 4.236]
    D1 = (indicator9 CROSSES OVER indicator10)
    
    IF D1 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    
    Graph        B1
    Graph        abs(CountOfPosition)
    GraphOnPrice (TradePrice + Tp)    coloured(0,255,0,255) AS "Long  EXIT 1"
    GraphOnPrice (TradePrice - Tp)    coloured(0,0,255,255) AS "Short EXIT 1"

    thank you

    JJJ.png JJJ.png
    #152367 quote
    robertogozzi
    Moderator
    Master

    You should duplicate line 5 and move one of them just after line 17 and the other one after line 62.

    Patrick K Templar thanked this post
    #152411 quote
    Patrick K Templar
    Participant
    Average

    Hello thank you

    I did that and had exactly the same results so no real effect by doing that

    #152419 quote
    robertogozzi
    Moderator
    Master

    What is exactly the problòem where the arrows are plotted.

    What date are those candles?

    Since there’s no variable declared in the original indicator I don’t know in which order you arranged them, when you call the indicator, is the first parameter the RSIperiod?

    #152431 quote
    Patrick K Templar
    Participant
    Average

    Yeah sorry I did not know no what was causing that one contract to come into the market and then go out and like I said it was not affecting the equity curve and it wasn’t showing any contracts on the price chart those blue Arrows that I pointed out in the picture, so what I did I started to strip away at the code and take stuff off so I took the break-even off and that did not affect it and I simplified the code just long and it was still there it’s obvious now to me that is the take profit contract for some reason

    I thank you very much for your help so far

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

help with break-even code as a second position and second exit


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 38 replies,
has 3 voices, and was last updated by robertogozzi
5 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/22/2020
Status: Active
Attachments: 11 files
Logo Logo
Loading...