Retain Buy/Sell condition

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #186107 quote
    SVK
    Participant
    Junior

    Hi All,

    again I’m turning to you knowledgable folks for a small help.

    I have attempted to do it myself but I’m getting nowhere unfortunately.
    Threads I have reviewed:

    How to keep a condition active for more than one bar

    Wait for x bars before entry

    x bars in a row code

    I’m looking for a code which will retain the trigger point but will delay it for 1 or 2 bars and will execute trade only if we are still in downtrend or uptrend.

     

    Price crosses under the 200MA – trigger bar (#1)

    Code retains this information but doesn’t execute the order on next bar(#2).

    When second bar(#3) since trigger opens it needs to check if previous bar(#2) closed below bar (#1 trigger bar).

    If bar #2 didn’t close below bar #1 then order is cancelled.

    If bar #2 closed below bar#1 then order is executed on bar#3.

    First photo is the situation I’m trying to avoid.

    Second photo is a succesfull trade execution.

     

    Thank you very much for your help

    Trigger.jpg Trigger.jpg Trigger-2.jpg Trigger-2.jpg
    #186113 quote
    PeterSt
    Participant
    Master

     

    Once PostPone = 0
    Once BuyingConditionsAreSet = 0
    Once  AllMyBuyingConditionsMeet = 0
    
    It Not BuyingConditionsAreSet then
      // Sort out Buying Conditions here. If they are met, end with :
    
      BuyingConditionsAreSet = 1
      AllMyBuyingConditionsMeet = 1
    endif
    
    If AllMyBuyingConditionsMeet then
      PostPone = 2
    Endif
    
    [...]
    
    If AllMyBuyingConditionsMeet then
    
      If not OnMarket and PostPone = 0 then
        Buy xyz Shares At Market
        BuyingConditionsSet = 0         // Reset.
        AllMyBuyingConditionsMeet = 0   // Reset.
      ElsIf Not OnMarket and PostPone > 0 then
        PostPone = PostPone -1  // Now wait for the next call. 2 actually.
      endif
    
    endif
    
    // BuyingConditionsSet and AllMyBuyingConditionsMeet seem redundant (do the same)
    // but "underway" at downcounting PostPone, you may feel that conditions are
    // not right anymore (the 3 of 1-2-3 never occurs), meaning that the conditions
    // have been "set" all right, but you won't Enter. On the other hand, once
    // you have definitely set the conditions, you may not want to look back and
    // just wait 2 bars regardless. So it is a bit how you want all happening.

    SVK, If you require a fully working code, then this is not for me. In that case the above may be helpful for others.
    It is not that exciting. But when to reset and why, could be (very much).

    Regards,
    Peter

    SVK thanked this post
    #186122 quote
    JS
    Participant
    Senior

    Hi @SVK

     

    DefParam CumulateOrders = False
    
    S1 = Close
    S2 = Average[200](Close)
    
    Cond1 = S1[1] Crosses Over S2[1]
    Cond2 = S1 > S1[1]
    Cond3 = S1[1] Crosses Under S2[1]
    Cond4 = S1 < S1[2]
    
    If Cond1 and Cond2 then
    Buy 1 contract at market
    EndIf
    
    If Cond3 and Cond4 then
    SellShort 1 contract at market
    EndIf
    
    SVK thanked this post
    Schermafbeelding-2022-01-20-om-19.40.28.png Schermafbeelding-2022-01-20-om-19.40.28.png
    #186125 quote
    JS
    Participant
    Senior

    Edit line 9 : Cond4 = S1 < S1[1]

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

Retain Buy/Sell condition


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
SVK @svk Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by JS
4 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/20/2022
Status: Active
Attachments: 3 files
Logo Logo
Loading...