Different stoploss first few bars

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #172883 quote
    ausrodausrod
    Participant
    New

    I am wondering how to code a system that allows me to set a stop loss tight in case market goes against me first 1-3 bars after i execute my order, then change it to a larger one after that. I am cureently using the excellent nicolas trailing stop – the MFE version.

     

    Although i didn’t write it obviously this seems to execute sell or sellshort rather than changing the stop ie it doesnt actually set a trailing or other stop.

     

    I have tried with a variable that resets as it cycles but im not sure this is the best way?

    #172886 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go. You need to set SL1 (tigther SL) and SL2 (the greater one) and the number of bars (N):

    SL1 = 20   //initial SL
    SL2 = 50   //larger SL
    N   = 3    //number of bars to keep the tighter SL
    IF MyLongConditions AND NotOnMarket THEN
       BUY 1 CONTRACT AT MARKET
       SET STOP pLOSS SL1
       Count = 1
    ENDIF
    IF OnMarket AND Count > 0 THEN
       Count = Count + 1
       IF Count > N THEN
          SET STOP pLOSS SL2 //Switch to a larger SL after N bars
          Count = 0
       ENDIF
    ENDIF
Viewing 2 posts - 1 through 2 (of 2 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

Different stoploss first few bars


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ausrod @ausrod Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzirobertogozzi
5 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/01/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...