Closing non-profitable trades based on x-candles

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #50455 quote
    jebus89jebus89
    Participant
    Master

    Hi all!

    Im wondering if someone could help me with a, probably, small problem.

    in one of my strategies i see that alot of the loosing trades never make any profit at all (meaning after trade is activated the market just keeps going down (long trades only)

    Is there a way to code in the following: “If no profit has been made (if the trade does not go into profit-making) within X candles, stop trade” ?

     

    edit: or maybe even better: “If trade has not generated X amounts of pips within X amounts of candles, close trade”

    This could potentially save me from some of the stop losses! 🙂

     

    Big thanks!

     

    Edit: I think ive seen it on this forum before but now i cant find it. Is it possible to code the following: “If MFE >= 25 (or X) pips then stop trade if it falls below 0 pips in profit.” ?

    In other words: if a trade goes to 50$ profit active trade, i dont want to see -50$ closed trade 🙂 If it goes to 50$ then to 0$ i want to close it there.

    #50458 quote
    DespairDespair
    Blocked
    Master

    What you describe sounds like a trailing SL to me. If there is x amount of profit, set the SL to breakeven. There are several trailing SL codes in the forum, also using MFE.

    #50465 quote
    jebus89jebus89
    Participant
    Master

    Hi Despair, thanks for the reply.

    So yea, it is indeed trailing stop, i just dont know how to code them.

    Idea #1: “If trade has not generated X amounts of pips, within X amounts of candles, close trade”

    Idea #2: “If there is x amount of profit, set the SL to breakeven.”

    I know i’ve seen a post regarding idea #2, but i cant recall which post or what words i can use to search for it. I believe it was mixed in someones code for some strategy, no idea which one.

    #50469 quote
    DespairDespair
    Blocked
    Master

    Nicolas posted a whole article on trailing SL. There you will find code you can use.

    #50487 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    As for breakeven (Idea #2), there’s Nicolas‘s code here that is ready to be included in your code:https://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/

    As for Idea #1 you may try this one (I haven’t tested it):

    ONCE MyPips = 5     //5  pips at least after...
    ONCE MyBars = 20    //20 bars have elapsed
    IF OnMarket THEN
       MyProfit = (close - tradeprice) * pipsize
       IF (MyProfit < MyPips) AND (BarIndex - TradeIndex) >= MyBars THEN
          SELL      AT MARKET  //close long trades as well as...
          EXITSHORT AT MARKET  //... short ones
       ENDIF
    ENDIF

    Roberto

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Closing non-profitable trades based on x-candles


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jebus89 @jebus89 Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by robertogozzirobertogozzi
8 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/25/2017
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...