stop loss 5 pips below or above the previous candle

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

    Hi Roberto,

    Many thanks for your trailing stop code.

    Just need some help – I would like to add in a hard stop loss in addition to these trailing stop codes.

    For example, when i have a long position, i want the stop to be 5 pips below the previous candle and for short positions, 5 pips above the previous candle, can i code it something like this and put it in addition to your codes?

    stoploss = close-(Low[1]-5*pointsize)
    set stop loss stoploss
    
    if longonmarket then
    set stop loss stoploss
    endif
    
    stoploss1 = close-(High[1]-5*pointsize)
    set stop loss stoploss1

    I’m new to PRT – any help would be greatly appreciated.

    Thanks!

    #196997 quote
    robertogozzi
    Moderator
    Master

    Do NOT append your questions to unrelated exixting topic. Create a new one, instead.

    Thank you 🙂

    Your code looks is almost correct, just use ABS() to make sure you get positive values and remove SET STOP LOSS outside IF…ENDIF to make sure you don’t overwrite the previous one when OnMarket:

    stoploss = abs(close-Low[1])-5*pointsize
    if longonmarket then
    set stop loss stoploss
    endif
     
    stoploss1 = abs(close-High[1])+5*pointsize
    if shortonmarket then
    set stop loss stoploss1
    endif

    You can append Nicolss’code to your code, for sure.

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

stop loss 5 pips below or above the previous candle


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
sibeihotan @sibeihotan Participant
Summary

This topic contains 1 reply,
has 1 voice, and was last updated by robertogozzi
3 years, 7 months ago.

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