Opening bar stop loss

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #172529 quote
    Paulchal
    Participant
    Average

    Hi

    What is the right code for a stop loss that is set after the opening bar.

    long entry condition is met and position is opened. If after that first bar ( whichever time frame is set) the first candle is green then the SL is set at the opening price. If the first candle is red the SL is set at the close price minus x pips.

    The reverse SL conditions for a short position.

    Any ideas on the code would be greatly received.

    #172551 quote
    robertogozzi
    Moderator
    Master

    Eccolo (SL=Stop Loss):

    Bullish = close > open
    Bearish = close < open
    IF LongOnMarket AND Not LongOnMarket[1] THEN   //prima barra dopo entrata a mercato
       IF Bullish THEN
          SL = TradePrice
       ELSIF Bearish THEN
          SL = close - 20*PipSize
       ENDIF
    ELSIF ShortOnMarket AND Not ShortOnMarket[1] THEN   //prima barra dopo entrata a mercato
       IF Bearish THEN
          SL = TradePrice
       ELSIF Bullish THEN
          SL = close + 20*PipSize
       ENDIF
    ENDIF
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Opening bar stop loss


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Paulchal @paulchal Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
4 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/26/2021
Status: Active
Attachments: No files
Logo Logo
Loading...