Stop Loss as % of trade after 30 periods

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

    Hello. I have been running my own basic trading systems on  UK and USA markets,  4 hours, 1 trade open at a time, for a while now but have recognised that I need to add in a stop loss after a certain period of time. I have been researching all the stop loss coding but I am struggling to make a start.

    I want to include additional code that does the following:

    Open 1 trade and ONLY after 30 periods, close it at a loss of 0.5%

    Could someone please assist me – either direct me to a reference or provide some simple code to adapt.

    Thankyou

    Sean

    #201577 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go:

    ONCE WaitingPeriods = 30
    ONCE Tally          = WaitingPeriods 
    IF StrategyProfit <> StrategyProfit[1]
       Tally = 0
    ENDIF
    IF Not OnMarket THEN
       Tally = Tally + 1
    ELSE
       Tally = 0
    ENDIF
    IF MyLongConditions AND Not OnMarket AND (Tally > WaitingPeriods) THEN
       BUY....
       StopLoss = close * 0.005     //0.5%
       SET STOP LOSS StopLoss
    ENDIF
    IF MyShortConditions AND Not OnMarket AND (Tally > WaitingPeriods) THEN
       SELLSHORT....
       StopLoss = close * 0.005     //0.5%
       SET STOP LOSS StopLoss
    ENDIF
    downunderneath thanked this post
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

Stop Loss as % of trade after 30 periods


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

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