Automatically Move To Break even Code

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #141506 quote
    Mathewdel
    Participant
    New

    Hi Guys,

    I after the functionality for automatically moving my trade to breakeven after it reaches a certain amount of pips.

    Is there a simple way to do this? any help would be greatly appreciated.

    Thanks Mathew

    #141509 quote
    robertogozzi
    Moderator
    Master

    Not tested:

    If not OnMarket then
       NewSL = 0
    Endif
    If NewSL = 0 and PositionPerf > 0 Then
       Pips = close * PositionPerf / pipvalue 
       If Pips >= 20 Then
          NewSL = tradeprice
       Endif
    Endif
    If NewSL > 0 Then
       SELL at NewSL STOP 
       EXITshort at NewSL STOP
    Endif

    no matter whether you’re Long or Short.

    #141510 quote
    robertogozzi
    Moderator
    Master

    Sorry, line 5 should read:

    Pips = tradeprice * PositionPerf / pipvalue
    #141511 quote
    Nicolas
    Keymaster
    Master
    #141515 quote
    Mathewdel
    Participant
    New

    Thanks guys, could you also point me in the direction where to enter the code in the platform?

    #141517 quote
    robertogozzi
    Moderator
    Master

    No matter where.

    #141519 quote
    Mathewdel
    Participant
    New

    Thanks but I’m still having some trouble,

    Does this look right,

    // Conditions to enter long positions
    IF NOT LongOnMarket AND YourConditions THEN
    BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    If LongOnMarket AND YourConditions THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND YourConditions THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    IF ShortOnMarket AND YourConditions THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets : Enter your protection stops and profit targets here
    If not OnMarket then
    NewSL = 0
    Endif
    If NewSL = 0 and PositionPerf > 0 Then
    Pips = tradeprice * PositionPerf / pipvalue
    If Pips >= 20 Then
    NewSL = tradeprice
    Endif
    Endif
    If NewSL > 0 Then
    SELL at NewSL STOP
    EXITshort at NewSL STOP
    Endif
    #141522 quote
    robertogozzi
    Moderator
    Master

    For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<  🙂

    Actually my correct code should be written as (after testing it on Dax):

    If not OnMarket then
       NewSL = 0
    Endif
    If NewSL = 0 and PositionPerf > 0 Then
       Pips = tradeprice * PositionPerf
       If Pips >= 20*pipsize Then
          NewSL = tradeprice
       Endif
    Endif
    If NewSL > 0 Then
      SELL at NewSL STOP
      EXITshort at NewSL STOP
    Endif
    Nicolas thanked this post
    #141557 quote
    Mathewdel
    Participant
    New

    Thanks Roberto,

    However, I’m still getting a code invalid response. Is there something I’m missing?

    // Conditions to enter long positions
    IF NOT LongOnMarket AND YourConditions THEN
    BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    If LongOnMarket AND YourConditions THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND YourConditions THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    IF ShortOnMarket AND YourConditions THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets : Enter your protection stops and profit targets here
    If not OnMarket then
    NewSL = 0
    Endif
    If NewSL = 0 and PositionPerf > 0 Then
    Pips = tradeprice * PositionPerf
    If Pips >= 20*pipsize Then
    NewSL = tradeprice
    Endif
    Endif
    If NewSL > 0 Then
    SELL at NewSL STOP
    EXITshort at NewSL STOP
    Endif
    

    I appreciate your time in helping me.

    #141573 quote
    JC_Bywan
    Moderator
    Master

    Topic moved from “ProBuilder support” forum (indicators only) to “ProOrder support” (trading strategies and backtests)

    #141577 quote
    Nicolas
    Keymaster
    Master

    Sorry but what do you mean by “invalid response”?

    #141626 quote
    robertogozzi
    Moderator
    Master

    This code works fine (I tested it on Dax and EurUsd, Daily TF):

    DEFPARAM CumulateOrders = false
    ONCE MA = 100           //100
    ONCE t  = 0             //0 = sma
    ONCE N  = 50 * pipsize  //50
    IF NOT LongOnMarket AND close crosses over average[MA,t] THEN
       BUY 1 CONTRACTS AT MARKET
    ENDIF
    If Not SHortOnMarket AND close crosses under average[MA,t] THEN
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    If not OnMarket then
       NewSL = 0
    Endif
    If NewSL = 0 and PositionPerf > 0 Then
       Pips = (tradeprice * PositionPerf)
       If Pips >= N Then
          NewSL = tradeprice
       Endif
    Endif
    If NewSL > 0 Then
       SELL at NewSL STOP
       EXITshort at NewSL STOP
    Endif
    SET TARGET pPROFIT 700  //700-pip goal
    //
    GraphOnPrice TradePrice        coloured(0,0,255,255) AS "BE TradePrice"
    GraphOnPrice TradePrice + N    coloured(255,0,0,255) AS "Activation"
    GraphOnPrice TradePrice + Pips coloured(0,128,0,255) AS "Temp profit"
    graph positionperf

    Appending GraphOnPrice and Graph at the end of your code greatly enhances debugging.

    thanked this post
    BE-Dax.jpg BE-Dax.jpg BE-EurUsd.jpg BE-EurUsd.jpg
    #141794 quote
    Mathewdel
    Participant
    New

    Great, thanks for your help guys!

    #142141 quote
    deletedaccount051022
    Participant
    New

    This is really helpful – super grateful!

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

Automatically Move To Break even Code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mathewdel @mathewdel Participant
Summary

This topic contains 13 replies,
has 5 voices, and was last updated by deletedaccount051022
5 years, 6 months ago.

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