Stop at X bars

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

    Hi guys,

    I am seeking for a bit of help please:

    What should be written where to have the position stopped (closed) X bars after the entry?

    Coding for me is close to Chinese (with all the respect I have for this great country ;).

    FYI: careful: This strategy does not perform well all the time…

    Thank you for your help.

    DJ

    //-------------------------------------------------------------------------
    // Code principal : MOM DD 9%
    //-------------------------------------------------------------------------
    // Définition des paramètres du code
    DEFPARAM CumulateOrders = False // Cumul des positions désactivé
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    DEFPARAM FLATBEFORE = 090000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 220000
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
    timeEnterBefore = time >= 090000
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
    timeEnterAfter = time < 220000
    
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Conditions pour ouvrir une position acheteuse
    indicator1 = Momentum[12](close)
    c1 = (indicator1 >= indicator1[4])
    indicator2 = BollingerBandWidth[20](close)
    c2 = (indicator2 > indicator2[4])
    indicator3 = Williams[14](close)
    c3 = (indicator3 > indicator3[2])
    
    IF (c1 AND c2 AND c3) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    indicator4 = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DLow(1)
    c4 = (close CROSSES OVER indicator4)
    
    IF c4 THEN
    SELL AT MARKET
    ENDIF
    
    // Stops et objectifs
    SET STOP pLOSS 35

    Edited by moderator to make PRT code format appear, please use the <> button in your new messages toolbar to insert PRT code

    #35618 quote
    Nicolas
    Keymaster
    Master

    It has been answered many times already in the past on forums. You need to use TRADEINDEX and make a comparison with the actual BARINDEX, that’s all you need 🙂

    IF BARINDEX-TRADEINDEX(1)>5 AND LongOnMarket THEN
       SELL AT MARKET 
    ENDIF
    Inertia thanked this post
    #35645 quote
    Inertia
    Participant
    Master

    Thank you Nicolas. Help much appreciated.

    #35685 quote
    Inertia
    Participant
    Master

    Hi Nicolas,

    What would be the keyword that I should look for to have the strategy looking for multiple entries please ? (like for each signal given instead of waiting for being flat again)

    Thank you again Boss !

    DJ

    #35687 quote
    Nicolas
    Keymaster
    Master

    You want to take another order while you are still on market, right? What would be the trigger to decide to add orders?

    Inertia thanked this post
    #35705 quote
    Inertia
    Participant
    Master

    Hi Nicolas, I think I found the trick on one of your previous posts … I have set up Defparam to True… then the strategy is now looking for all possible entries during the specified time frame…

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

Stop at X bars


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Inertia @inertia Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Inertia
8 years, 9 months ago.

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