X Max trade per day

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #222386 quote
    Inertia
    Participant
    Master

    Hello All !

    Hope you are doing well 😉

    1 – May I kindly ask for a snippet of code that would allow an auto strategy being triggered X MAX num of time per Day ?

    2 – Is there another snippet of code that will let the strategy keeping on being triggered until X Pts per day are achieved?

    Example > I am looking for a gain of 10 pts per day. First trigger, loss of -30 pts. I need 40 pips to achieve my daily goal (forget about the fees).  Best scenario, 4 wins in a row THEN the strategy will stop for the day.

    BIG THANKS

    #222390 quote
    Nicolas
    Keymaster
    Master

    1/ numerous topics for that:

    Max profit and loss each day in a trading strategy

    https://www.prorealcode.com/topic/1-gain-par-jour/#post-74368

    https://www.prorealcode.com/topic/1-position-par-jour/#post-46788

    https://www.prorealcode.com/topic/how-to-operate-just-once-in-a-day/

    https://www.prorealcode.com/topic/quick-question-one-order-per-day/

    https://www.prorealcode.com/topic/limiting-accumulating-orders-fuse/#post-25833

    https://www.prorealcode.com/topic/limite-le-trading-automatique-a-un-ordre-journalier/

    Max number of trades in a period

    Limite du nombre de trade par jour ne fonctionne par correctement

    2/ code for Daily max loss/profit in points/pips:

    MaxProfit = 50 //max daily profit objective in pips
    MaxLoss = 40 //max daily loss in pips
     
    //max profit/loss achieved
    if day<>day[1] then
    strategyprofitpoint=0 //daily reset
    endif
    if(strategyprofit<>strategyprofit[1]) then
    pnl = strategyprofit-strategyprofit[1]
    size = max(startContract,abs(countofposition[1]))
    onepos = pnl/size
    pointprofit = onepos/pointvalue
    strategyprofitpoint = strategyprofitpoint+pointprofit
    endif
    allowtrading=1
    if (strategyprofitpoint>=MaxProfit or strategyprofitpoint<=-MaxLoss) then
    allowtrading=0
    endif
    Inertia thanked this post
    #222402 quote
    Inertia
    Participant
    Master
    //-------------------------------------------------------------------------
    // Main code : NSDQ Clo W Pré OCTOBRE 13
    //-------------------------------------------------------------------------
    // Definition of code parameters
    DEFPARAM CumulateOrders     = False // Cumulating positions deactivated
    DEFPARAM FLATBEFORE         = 070000
    DEFPARAM FLATAFTER          = 213000
    
    maxorders = 2 //max orders per day
     
    //reset the count of orders each day
    if intradaybarindex=0 then
    count = 0
    endif
     
    //counting orders
    if onmarket and lastindex<>tradeindex then
    count=count+1
    lastindex=tradeindex
    endif
    
    trailingstop = 6// Previous 25
    if not onmarket then
    MAXPRICE = 0
    priceexit = 0
    endif
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    SELL AT priceexit STOP
    endif
    
    
    // Conditions to enter long positions
    c1 = (low CROSSES UNDER 15112)
    
    IF NOT LONGONMARKET AND c1 THEN
    buy 1 SHARES AT MARKET
    ENDIF
    
    SET STOP %LOSS 0.2
    SET TARGET %PROFIT 0.07
    

    Hello !

    This strategy keep buying indefinitely … I thought the code would have stopped after the second trade…

    Where is my mistakeplease??

    THANK YOU 😉

    #222456 quote
    robertogozzi
    Moderator
    Master

    You added variable maxorders, but you never used it to enter trades, so it is useless. In addition count wasn’t correctly updated and wasn’t used either.

    I added maxpips to set a daily target, after which trading is disabled:

    DEFPARAM CumulateOrders     = False // Cumulating positions deactivated
    DEFPARAM FLATBEFORE         = 070000
    DEFPARAM FLATAFTER          = 213000
    ONCE maxorders = 2    //max orders per day
    ONCE maxpips   = 10   //max daily gain (in pips)
    ONCE count     = 0
    ONCE pips      = 0
    ONCE myProfit  = 0
    //reset the count of orders each day
    if intradaybarindex=0 then
    count    = 0
    pips     = 0
    myProfit = StrategyProfit
    endif
    
    //counting orders
    //if onmarket and lastindex<>tradeindex then
    //count=count+1
    //lastindex=tradeindex
    //endif
    IF StrategyProfit <> StrategyProfit[1] THEN
    pips = pips + ((StrategyProfit - myProfit) / Pipvalue)
    IF pips >= maxpips THEN
    count = maxorders + 1   //disable trtading after reaching maxpips gain
    ENDIF
    ENDIF
    trailingstop = 6// Previous 25
    if not onmarket then
    MAXPRICE = 0
    priceexit = 0
    endif
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    SELL AT priceexit STOP
    endif
    // Conditions to enter long positions
    c1 = (low CROSSES UNDER 15112)
    
    IF NOT LONGONMARKET AND c1 AND count < maxorders THEN
    buy 1 SHARES AT MARKET
    count=count+1
    ENDIF
    SET STOP %LOSS 0.2
    SET TARGET %PROFIT 0.07
    Inertia thanked this post
    #222459 quote
    Inertia
    Participant
    Master

    THANK YOU very much Roberto !  I keep this one safe.

    Have a nice week-end.

    Damien

    robertogozzi thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

X Max trade per day


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Inertia @inertia Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/13/2023
Status: Active
Attachments: No files
Logo Logo
Loading...