Breakeven level gets removed

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #137193 quote
    AntonC
    Participant
    Junior

    Hello,

    I was playing around a little with the breakeven-code posted on here (https://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/) when i noticed that that I seem to have something wrong with my code.

    As shown in the inserted printscreen of the backtest, the breakeven code gets activated once 30 points have moved in my favour, but once the price begins to move against me, the breakeven-code gets “removed” and it doesn’t sell on the set level for some reason, what am I doing wrong?

     

    Regards,
    Anton

    breakeven = 30
    keeppoints = 5
    
    if not onmarket then
    breakeven = 0
    endif
    
    IF LONGONMARKET AND close-tradeprice(1)>=Breakeven*pipsize THEN
    breakeven = tradeprice(1)+keeppoints*pipsize
    ENDIF
    
    if breakeven > 0 then
    sell at breakeven stop
    endif
    
    Graph breakeven as "be"
    2020-06-26-1.png 2020-06-26-1.png
    #137195 quote
    Vonasi
    Moderator
    Master

    Try this. Not tested.

    breakeven = 30
    keeppoints = 5
    
    if not onmarket then 
    flag = 0
    endif
    
    IF longonmarket and close - tradeprice >= Breakeven*pipsize THEN
    flag = 1
    endif
    
    if flag then
    sell at (tradeprice + keeppoints) stop
    endif
    
    swedshare and Brad thanked this post
    #137474 quote
    AntonC
    Participant
    Junior

    That seems to be working, thank you!

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

Breakeven level gets removed


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
AntonC @antonc Participant
Summary

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

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