Stop Loss as % of trade after 30 periods

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #201557 quote
    downunderneath
    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
    robertogozzi
    Moderator
    Master

    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.

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 robertogozzi
3 years, 4 months ago.

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