Limiting number of trades

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

    HI,

    I’m trying to trade between specified time and limit the number of trades (2).

    I ran the test it will only trade once, will not trade up to twice a day everyday.

    Can you please help with my code?

    Thanks in Advance:)

    Here is my code:

    // Trading time: 11pm to 530am
    DEFPARAM FLATBEFORE = 230000
    DEFPARAM FLATAFTER = 052500
    
    ONCE start = 230000
    
    // limiting # of trades
    IF Time = start THEN
    TradeCount = 0
    ENDIF
    
    a = MACD[12,26,9](close)
    b = SmoothedStochastic[14,3](close)
    c = Average[24](close)
    
    // Conditions to enter long positions
    IF NOT LongOnMarket AND time>=start AND TradeCount<3 AND a>7 AND b>20  AND close>c THEN
    BUY 1 LOT AT MARKET
    TradeCount = TradeCount + 1
    ENDIF
    //
    // Conditions to exit long positions
    If LongOnMarket AND close<c THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND time>=start AND TradeCount<3 AND a<-7 AND b<80  AND close<c  THEN
    SELLSHORT 1 LOT AT MARKET
    TradeCount=TradeCount+1
    ENDIF
    
    // Conditions to exit short positions
    IF ShortOnMarket AND close>c THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets : Enter your protection stops and profit targets here
    
    prt-help.png prt-help.png
    #25274 quote
    Nicolas
    Keymaster
    Legend

    I do not see the problem at first read. Did you try to debug the “TradeCount” variables with a GRAPH?

    GRAPH TradeCount

    You’ll find it easy to debug with this line in your code, to see if the trade count is well incrementing.

    #25284 quote
    robertogozzi
    Moderator
    Legend

    I think you should decrement by 1 after/before lines 24 and 35 (TradeCount = TradeCount - 1).

    But I did not test it.

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

Limiting number of trades


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
micKm @mickm Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by robertogozzi
9 years, 7 months ago.

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