How to count the Buy entry ?

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #213131 quote
    ZeroCafeineZeroCafeine
    Participant
    Senior

    Hi All

    How to count the buy order will be realy executed and stop buying after 3 time :

    Defparam cumulateorders = True
    SMA10 = Average[10](close)
    SMA20 = Average[20](close)
    SMA100 = Average[100](close)
    
    C1 = SMA10 Crosses Over SMA20 AND SMA20 > SMA100
    
    IF C1 THEN
    BUY 1 CONTRACTS AT MARKET
    Count = Count + 1 // Only if the Purchase is executed
    ENDIF
    

    or a line number for Snippet also will be ok
    Best Reguards,
    ZeroCafeine

    MAx-3.png MAx-3.png
    #213137 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    You have to use COUNT in your entry conditions, provided it is cleared when not on market:

    Defparam cumulateorders = True
    IF Not OnMarket THEN
       Count = 0
    ENDIF
    SMA10 = Average[10](close)
    SMA20 = Average[20](close)
    SMA100 = Average[100](close)
     
    C1 = SMA10 Crosses Over SMA20 AND SMA20 > SMA100
     
    IF C1 AND (Count < 3) THEN
       BUY 1 CONTRACTS AT MARKET
       Count = Count + 1 // Only if the Purchase is executed
    ENDIF
    ZeroCafeine thanked this post
    #213142 quote
    ZeroCafeineZeroCafeine
    Participant
    Senior

    tks you so much for your quick answer, So I have to think like, I’m or not in market, when I see your answer it’s seems like easy, but I don’t know to think like that, I hope soon 😉

    #213152 quote
    ZeroCafeineZeroCafeine
    Participant
    Senior

    You have to use COUNT in your entry conditions, provided it is cleared when not on market:

    tks again for your answers, But Once again, I have phrased my question incorrectly :

    – How to count in the case of Limit order ? you can see in the photo, The conditions for the purchase were met except for the price limit
    – we can also met the same situation in the case of my Buy order is filled (so at this time we are OnMarket) But if my order is closed because of a stop loss so we will be in the case of Not OnMarket (So Count = 0) even we execute the Buy only one time

    Capture-decran-2023-04-12-a-00.05.57.png Capture-decran-2023-04-12-a-00.05.57.png
    #213158 quote
    ZeroCafeineZeroCafeine
    Participant
    Senior

    I found this solution, maybe you have an other idea :

    Defparam cumulateorders = True
    if intradaybarindex=0 then // we reset Count every day
     Count = 0
    endif
    
    SMA10 = Average[10](close)
    SMA20 = Average[20](close)
    SMA100 = Average[100](close)
     
    C1 = SMA10 Crosses Over SMA20 AND SMA20 > SMA100
     
    IF C1 AND (Count <= 3) THEN
       BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    IF OnMarket AND Not OnMarket[1] THEN
     Count = Count + 1 // Like thit we are sure to add 1 only if we are on market and the candle just before we are not on market
    ENDIF
    #213160 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    A better solution is to reset COUNT at the beginning of a new trading day:

    IF IntraDayBarIndex = 0 THEN
       Count = 0
    ENDIF

    the issue with pending orders can be addressed with this code, which detects a new entry (to be tallied when there are more positions on market than there were the prior candle:

    Defparam cumulateorders = True
    IF IntraDayBarIndex = 0 AND Not OnMarket THEN
    Count = 0
    ENDIF
    SMA10 = Average[10](close)
    SMA20 = Average[20](close)
    SMA100 = Average[100](close)
    
    myPos = abs(CountOfPosition)
    Count = Count + (myPos > myPos[1])
     
    C1 = SMA10 Crosses Over SMA20 AND SMA20 > SMA100
     
    IF C1 AND (Count < 3) THEN
    BUY 1 CONTRACTS AT low - 10*PipSize LIMIT
    ENDIF
    set target pprofit 100
    set stop   ploss   100
    #213161 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Actually, instead of checking positions, you might use:

    Count = Count + LongTriggered
    #213163 quote
    ZeroCafeineZeroCafeine
    Participant
    Senior

    My subconscious found the solution while I slept last night, but with your solution on top of it, I’m lost …. 😅

    Actually I’m joking 😊, again thank you for your answer I totally understand your solution and I will try to understand it even better,

    About line 15, wouldn’t it be better to use the Close than Low, also maybe the Close +2 pips in limit for exemple

    With a buy at Low – 10 pips, do I risk not getting executed and the market going without me ?

    #213188 quote
    ZeroCafeineZeroCafeine
    Participant
    Senior

    in the continuity of my code I realise that if I am in position and I take another position then my line 16 does not work so I had to add this :

    IF OnMarket AND Not OnMarket[1] OR ABS(CountOfPosition) > ABS(CountOfPosition[1]) THEN
     Count = Count + 1ENDIF

    It seems to work, I’ll come back at the end of the day to do more tests and compare with your solution @robertogozzi which seems much simpler than mine and I think it does the job

    #213190 quote
    ZeroCafeineZeroCafeine
    Participant
    Senior

    That’s how it takes me more than 4 hours on Wednesday to have 15 minutes of concentration to understand what it is, I’m sick of this temporary office 🤣🤣🤣🤣

    Wish me luck

    IMG_20230412_151913.jpg IMG_20230412_151913.jpg
    #213259 quote
    ZeroCafeineZeroCafeine
    Participant
    Senior

    Actually, instead of checking positions, you might use:

     

    Perfect 😊

    robertogozzi thanked this post
Viewing 11 posts - 1 through 11 (of 11 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 count the Buy entry ?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 10 replies,
has 2 voices, and was last updated by ZeroCafeineZeroCafeine
3 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/11/2023
Status: Active
Attachments: 3 files
ProRealCode ProRealCode
Loading...