stop loss -3 candles

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #150867 quote
    mr bluemr blue
    Participant
    Senior

    Hi there!

    Yes I know – the topic stop loss has been covered hundreds of times in this space, but I didn’t found a code snipped matching my needs.

    So I am looking for a simple code snipped which does the following:

    • after entering a long/short position, the stop is placed for a long position (3 candles back low -1 tick) and for short (3 candles back high + 1 tick)
    • as long as the trade is active the stop is updated accordingly (always 3 candles back +/- 1 tick)

     

    I tried to code it by myself, but I failed – shame on me – I know 🙂

     

    So is there anyone who solved this problem already or likes to write it?

     

    Many thanks in advance.

    #150870 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Not tested:

    IF MyLongConditions AND Not OnMarket THEN
       BUY 1 CONTRACT AT MARKET
       NewSL = low[3]-1*pipsize
       SELL  AT NewSL STOP
    ENDIF
    //
    IF MyShortConditions AND Not OnMarket THEN
       SELLSHORT 1 CONTRACT AT MARKET
       NewSL = high[3]+1*pipsize
       EXITSHORT AT NewSL STOP
    ENDIF
    //
    IF OnMarket THEN
       IF PositionPerf > 0 THEN
          IF LongOnMarket THEN
             NewSL = max(newSL,low[3]-1*pipsize)
          ELSE
             NewSL = min(newSL,high[3]+1*pipsize)
          ENDIF
       ENDIF
       IF NewSL > 0 THEN
          SELL             AT NewSL STOP
         EXITSHORT AT NewSL STOP
       ENDIF
    ENDIF
    mr blue, GraHal and icharttop thanked this post
    #150871 quote
    GraHalGraHal
    Participant
    Legend

    Link to above added as Log 261 here …

    Snippet Link Library

    robertogozzi thanked this post
    #150877 quote
    mr bluemr blue
    Participant
    Senior

    works – grazie

Viewing 4 posts - 1 through 4 (of 4 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

stop loss -3 candles


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
mr blue @marco_sala Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by mr bluemr blue
5 years, 11 months ago.

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