How to find trade date?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #201465 quote
    jiminykricketjiminykricket
    Participant
    New

    Hi all,

    I feel like this should be an easy one but seeing as I’m normally fairly adept on PRT I think I’m either massively overthinking it or its just impossible (ha!) So here goes;

    I have a trend following system that on any given day produces trade results heavily inline with previous trades of the same day (Z-score of -31!). Great when it’s profiting, awful when its losing. To combat this I want to stop the system trading for the rest of that trading day (only) after an arbitrary number of losing trades (we’ll use 3 but once I have the code I’ll clearly refine this).

    I’m assuming the ideal code would look something like this;

    If (TradeDate[Position[3]]=Today and PositionPerf[3]<0) 
    and (TradeDate[Position[2]]=Today and PositionPerf[2]<0)
    and (TradeDate[Position[1]]=Today and PositionPerf[1]<0) Then
    
    EndIf
    
    

    The issue is of course, that neither a TradeDate function, or Position/Trade number function exists (unless I just can’t find it?). I can of course figure out how to stop it running based on the past three trades being losing trades, however the important part is these trades are only relevant if on the current trading day.

    Any ideas or workarounds?

    TIA!

    #201466 quote
    jiminykricketjiminykricket
    Participant
    New

    OK.. so having just typed that out I’ve thought of a not-that-great workaround..

    Noting this is for US markets and 10min candles, so 39 candles per day, I guess I could do the following;

     

    IF (TradeIndex[3]<40 and PositionPerf[3]<0)
    and (TradeIndex[2]<40 and PositionPerf[2]<0)
    and (TradeIndex[1]<40 and PositionPerf[1]<0) Then
    
    EndIf

    Would that work? Can anyone think of any improvements?

    TIA!

    #201493 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    This code will limit losses (defaults to 3):

    ONCE MaxLosingTrades = 3
    ONCE Tally           = 0
    IF IntraDayBarIndex = 0 THEN
       Tally = 0
    ENDIF
    IF StrategyProfit < StrategyProfit[1] THEN
       Tally = Tally + 1
    ELSIF StrategyProfit > StrategyProfit[1] THEN
       Tally = 0
    ENDIF
    MyLongConditions = close CROSSES OVER Average[20,0](close)
    IF MyLongConditions AND Not OnMarket AND (Tally < MaxLosingTrades) THEN
       BUY 1 Contract at Market
       SET STOP   pLOSS   30
       SET TARGET pPROFIT 200
    ENDIF
    //graph Tally
    //graph (Tally = MaxLosingTrades) coloured(255,0,0,255)

    Comment out line 9 to not require consecutive losses.

Viewing 3 posts - 1 through 3 (of 3 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

How to find trade date?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by robertogozzirobertogozzi
4 years ago.

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