close strategy after profit/ number of trades

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #192176 quote
    alejandrocorbutalejandrocorbut
    Participant
    New

    how does one set up the strategy to stop trading after 1 profitable trade/ a certain number of trades?

    #192180 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    To stop trading after 1 profitable trade:

    ONCE TradeON = 1
    IF IntraDayBarIndex = 0 THEN
       TradeON = 1
    ENDIF
    IF StrategyProfit > StrategyProfit[1] THEN
       TradeON = 0
    ENDIF
    IF MyConditions AND TradeON THEN
       BUY/SELLLSHORT....
    ENDIF

    To stop after a certain number of trades:

    ONCE MaxTrades = 3
    ONCE Tally     = 0
    IF IntraDayBarIndex = 0 THEN
       Tally = 0
    ENDIF
    IF StrategyProfit <> StrategyProfit[1] THEN
       Tally = Tally + 1
    ENDIF
    IF MyConditions AND Tally < MaxTrades THEN
       BUY/SELLLSHORT....
    ENDIF
    #192186 quote
    alejandrocorbutalejandrocorbut
    Participant
    New

    awesome. thank you

    #193053 quote
    alejandrocorbutalejandrocorbut
    Participant
    New

    how does one combine these 2 pieces of code so that the maximum number of trades is 2 but the system will stop after 1 profitable trade. So that if first trade is profitable, the second wont happen but if first is a loser then 1 more trade will be allowed

    #193088 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go:

    ONCE TradeON   = 1
    ONCE MaxTrades = 3
    ONCE Tally     = 0
    
    IF IntraDayBarIndex = 0 THEN
       TradeON = 1
       Tally   = 0
    ENDIF
    
    IF StrategyProfit > StrategyProfit[1] THEN
       TradeON = 0
    ENDIF
    
    IF StrategyProfit <> StrategyProfit[1] THEN
       Tally = Tally + 1
    ENDIF
    IF MyConditions AND Tally < MaxTrades AND TradeON THEN
       BUY/SELLLSHORT....
    ENDIF
    #194309 quote
    alejandrocorbutalejandrocorbut
    Participant
    New

    roberto

     

    thank you for this! i am learning fast!!

     

    i applied the code to my strategy but it still does more than the maximum of 2 trades per day and it isnt stopping once profitable. have i put it in wrong?

     

    attached is list of orders and code

     

    alex

    trades.jpg trades.jpg code.jpg code.jpg
    #194327 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    It open as many trades as MAXTRADES.  It’s 3 now, but you can change it as needed.

    #194329 quote
    alejandrocorbutalejandrocorbut
    Participant
    New

    …but on 12th , there were 6 trades, so not sure code is working

    #194340 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    This code is working as expected on DAX, 1-min, 5-min, 15-min TFs, etc…

    DEFPARAM CumulateOrders = False
    ONCE TradeON   = 1
    ONCE MaxTrades = 3
    ONCE Tally     = 0
     
    IF IntraDayBarIndex = 0 THEN
       TradeON = 1
       Tally   = 0
    ENDIF
     
    IF StrategyProfit > StrategyProfit[1] THEN
       TradeON = 0
    ENDIF
     
    IF StrategyProfit <> StrategyProfit[1] THEN
       Tally = Tally + 1
    ENDIF
    
    MyConditions = (average[20] CROSSES UNDER average[100]) AND Not OnMarket
    IF MyConditions AND Tally < MaxTrades AND TradeON THEN
       SELLSHORT 1 contract at Market
    ENDIF
    SET TARGET pPROFIT 60
    SET STOP   pLOSS   60
    //
    graph Tally

    I suggest that you either post your code, or use mine, simply replacing MyConditions with yours.

    #194374 quote
    alejandrocorbutalejandrocorbut
    Participant
    New

    amazing!! thank you for your time and patience!

     

    alex

    #194846 quote
    alejandrocorbutalejandrocorbut
    Participant
    New

    hi roberto

     

    1 more question……!

     

    i have 2 strategies that i have made/ am using with a degree of success and they are both good on back testing. I would like another set of eyes to have a look at them and see where i can improve them. Would be happy to pay for that service! is there anyone you could recommend? would you have a look? should i just post them on a forum and see what people say?! alex

    #194847 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    You can either post your code or apply for paid services at https://www.prorealcode.com/trading-programming-services/

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

close strategy after profit/ number of trades


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/25/2022
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...